-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6425 from sapcc/gh-actions
init gh-actions for helm chart test and push to github oci registry
- Loading branch information
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: "Helm lint" | ||
on: | ||
pull_request: | ||
types: [ opened, synchronize, reopened ] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
helm-lint: | ||
runs-on: [ ubuntu-latest ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Helm | ||
uses: azure/setup-helm@v4.2.0 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
check-latest: true | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up chart-testing | ||
uses: helm/chart-testing-action@v2.6.1 | ||
|
||
- name: Run chart-testing (list-changed) | ||
id: list-changed | ||
run: | | ||
changed=$(ct list-changed --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }}) | ||
if [[ -n "$changed" ]]; then | ||
echo "changed=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Run chart-testing (lint) | ||
if: steps.list-changed.outputs.changed == 'true' | ||
run: ct lint --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }} | ||
|
||
- name: Check version bump | ||
id: check-bump | ||
if: steps.list-changed.outputs.changed == 'true' | ||
continue-on-error: true | ||
run: | | ||
for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do | ||
chart_version=$(yq .version "$chart/Chart.yaml") | ||
if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then | ||
echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" | ||
echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT" | ||
echo "needsbump=true" >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
done | ||
- uses: actions/github-script@v6 | ||
if: steps.check-bump.outputs.needsbump == 'true' | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: ':warning: Chart `oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/${{ steps.check-bump.outputs.chart }}:${{ steps.check-bump.outputs.chart_version }}` already exists in registry. Please increment the chart version.' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: Package Helm Chart and publish to GitHub Packages | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
ACTIONS_RUNNER_DEBUG: false | ||
|
||
jobs: | ||
helm-release: | ||
runs-on: [ ubuntu-latest ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Configure Git | ||
run: | | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
- name: Set up Helm | ||
uses: azure/setup-helm@v4.2.0 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
check-latest: true | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Run chart-testing (list-changed) | ||
id: list-changed | ||
run: | | ||
changed=$(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}) | ||
if [[ -n "$changed" ]]; then | ||
echo "changed=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Run chart-testing (lint) | ||
if: steps.list-changed.outputs.changed == 'true' | ||
run: ct lint --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }} | ||
|
||
- name: Check if Helm chart with same version already exists | ||
id: check-chart | ||
if: steps.list-changed.outputs.changed == 'true' | ||
run: | | ||
for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do | ||
chart_version=$(yq .version "$chart/Chart.yaml") | ||
if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then | ||
echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" | ||
echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT" | ||
echo "needsbump=true" >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
done | ||
- name: Chart needs version bump | ||
if: steps.check-chart.outputs.bump == 'true' | ||
env: | ||
CHART_VERSION: ${{ steps.check-chart.outputs.chart_version }} | ||
run: | | ||
echo "Chart ${{ matrix.chartDir }}:${{ env.CHART_VERSION }} already exists in OCI registry. Skipping upload. Please increment the chart version." | ||
exit 1 | ||
- name: Push Charts to GHCR | ||
if: steps.list-changed.outputs.changed == 'true' && steps.check-chart.outputs.bump != 'true' | ||
run: | | ||
for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do | ||
helm dependency update $chart | ||
helm package $chart -d $chart | ||
PKG_NAME=`ls $chart/*.tgz` | ||
helm push ${PKG_NAME} oci://${{ env.REGISTRY }}/${{ github.repository }}/ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters