Helm Chart Lint and Release #112
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
name: Helm Chart Lint and Release | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
helm-lint: | |
name: Helm lint & testing | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repo hosting code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
- name: Run helm lint | |
run: helm lint cloudprober/. | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
check-latest: true | |
- name: Set up chart-testing | |
uses: helm/chart-testing-action@v2 | |
- name: Run chart-testing (list-changed) | |
id: list-changed | |
run: | | |
changed=$(ct list-changed --chart-dirs . --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-dirs . --target-branch ${{ github.event.repository.default_branch }} \ | |
--check-version-increment=false --validate-maintainers=false | |
- name: Create kind cluster | |
if: steps.list-changed.outputs.changed == 'true' | |
uses: helm/[email protected] | |
- name: Run chart-testing (install) | |
if: steps.list-changed.outputs.changed == 'true' | |
run: ct install --chart-dirs . --target-branch ${{ github.event.repository.default_branch }} | |
paths-filter: | |
name: Filter Chart.yaml | |
outputs: | |
charts_yaml_changing: ${{ steps.filter.outputs.chartYaml }} | |
runs-on: ubuntu-latest | |
needs: [helm-lint] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
chartYaml: | |
- 'cloudprober/Chart.yaml' | |
chart-release: | |
name: Release chart | |
runs-on: ubuntu-latest | |
needs: [paths-filter, helm-lint] | |
if: needs.paths-filter.outputs.charts_yaml_changing == 'true' | |
steps: | |
- name: Check out repo hosting code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
chartYaml: | |
- 'cloudprober/Chart.yaml' | |
- name: Compute chart version | |
run: |- | |
baseVersion=$(sed -n '/version: /s/version: //p' cloudprober/Chart.yaml) | |
echo ">> Base version: $baseVersion" | |
bv=( ${baseVersion//./ } ) | |
appVersion=$(sed -n '/appVersion: /s/appVersion: //p' cloudprober/Chart.yaml) | |
echo ">> App version: $appVersion" | |
cpVersion=${appVersion/v/} | |
cpVersion=$(echo $cpVersion | tr -d "'") | |
echo ">> Cloudprober version: $cpVersion" | |
cv=( ${cpVersion//./ } ) | |
newVersion=$((${bv[0]} + ${cv[0]})).$((${bv[1]} + ${cv[1]})).$((${bv[2]} + ${cv[2]})) | |
echo ">> New version: $newVersion" | |
echo "CHART_VERSION=${newVersion}" >> $GITHUB_ENV | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
- name: Create tag | |
uses: actions/github-script@v5 | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{ env.CHART_VERSION }}', | |
sha: context.sha | |
}) | |
- name: Package chart and build index | |
run: |- | |
git worktree add repo gh-pages | |
cd repo | |
helm package ../cloudprober/. --version=${CHART_VERSION} -d packages | |
helm repo index . --url https://helm.cloudprober.org | |
git add * | |
git status | |
- name: Push release | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') | |
run: |- | |
cd repo | |
git add * | |
git config user.name "Manu Garg" | |
git config user.email "[email protected]" | |
git commit -m "[automated] Update helm charts repo" || exit 0 | |
git push |