Skip to content

Commit

Permalink
Feat/refactor workflows (#52)
Browse files Browse the repository at this point in the history
* refactor create_release workflow to make automatic release

* add check_version workflow

* refactor doc´ker build

* refactor helm build

* refactor create_release.yaml

* change version to 1.0.0

* fix path ref

* add missing v

* refactor workflows

* Enhance CI Workflow: Check for Version Bump and appVersion Changes (#44)

* feat: additional approval on Version change

* fix: combine version bump check and approve by label

* fix: adjust label name

* fix: remove tag comparison

* fix: base_ref

* fix: some naming changes

* Fix syntax

Co-authored-by: Jonathan Mayer <[email protected]>

* refactor check-for-release.yaml

* fix dependency

* resolve merge conflicts

* add label removing

* chore: syntax

* change message

* removed not needed if checks

* removal of new release

* fix errors in workflows

* fix appVersion variable mismatch

---------

Co-authored-by: Johannes <[email protected]>
Co-authored-by: Jonathan Mayer <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent 43bd005 commit d19831b
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 55 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/check-for-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Check for new release

on:
pull_request:
types: [opened, synchronize, labeled]

jobs:
check_for_release:
name: Check For Release
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for appVersion changes
run: |
echo "Checking for appVersion changes..."
if git diff origin/${{ github.base_ref }} -- deployments/chart/Chart.yaml | grep -qe "^[+-]appVersion: "; then
app_version_change=$(echo "version changed")
echo "app_version_change=$app_version_change" >> $GITHUB_ENV
else
app_version_change=$(echo "No appVersion changes detected.")
echo "app_version_change=$app_version_change" >> $GITHUB_ENV
fi
- name: Remove new version label
if: ${{ env.app_version_change == 'No appVersion changes detected.' }}
run: |
echo "No appVersion changes detected. Removing new version label"
gh pr edit ${{ github.event.pull_request.number }} --remove-label "new release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fail if changes occured
if: ${{ !contains(github.event.pull_request.labels.*.name, 'new release') }}
run: |
if [ "${{ env.app_version_change }}" == "version changed" ]; then
echo "Version changed, exiting..."
exit 1
else
echo "No appVersion changes detected."
fi
- name: Remove approval label
run: |
gh pr edit ${{ github.event.pull_request.number }} --remove-label "needs approval"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

post_message:
name: Post Message To Warn Of New Release
runs-on: ubuntu-latest
needs: check_for_release
if: ${{ failure() && !contains(github.event.pull_request.labels.*.name, 'needs approval') }}
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract appVersion
id: extract_appversion
run: |
appversion=$(yq e '.appVersion' ./deployments/chart/Chart.yaml)
echo "appversion=$appversion" >> $GITHUB_ENV
- name: Post warning comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: "⚠️ Warning: Merging this PR will result in a new release because the `appVersion` in Chart.yaml has changed to `${{ env.appversion }}`. Please confirm this by adding the `new release` label before merging."

- name: Set a label on the pull request
run: |
gh pr edit ${{ github.event.pull_request.number }} --add-label "needs approval"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83 changes: 83 additions & 0 deletions .github/workflows/check_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Check for new version

on:
push:
branches:
- main
paths:
- deployments/chart/Chart.yaml

jobs:
check_versions:
runs-on: ubuntu-latest
outputs:
version_change: ${{ steps.check_for_version_change.outputs.version_change }}
app_version_change: ${{ steps.check_for_appVersion_change.outputs.app_version_change }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for appVersion change
id: check_for_appVersion_change
run: |
app_version_change=$(git diff main HEAD~1 -- deployments/chart/Chart.yaml | grep -qe "^[+-]appVersion: " && echo "appVersion changed" || echo "appVersion didn't change")
echo "app_version_change=$app_version_change" >> $GITHUB_OUTPUT
- name: Check for version change
id: check_for_version_change
run: |
version_change=$(git diff main HEAD~1 -- deployments/chart/Chart.yaml | grep -qe "^[+-]version: " && echo "version changed" || echo "version didn't change")
echo "version_change=$version_change" >> $GITHUB_OUTPUT
build_new_chart:
runs-on: ubuntu-latest
needs: check_versions
if: ${{ needs.check_versions.outputs.version_change == 'version changed' }}
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract Chart Version
id: chart_version
run: |
version=$(yq e '.version' ./deployments/chart/Chart.yaml)
echo "version=$version" >> $GITHUB_ENV
- name: Dispatch Event to build new helm chart
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: caas-team/GoKubeDownscaler
event-type: build-new-chart
client-payload: '{"version": "${{ env.version }}"}'

release_new_version:
runs-on: ubuntu-latest
needs: check_versions
if: ${{ needs.check_versions.outputs.app_version_change == 'appVersion changed' }}
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract App Version
id: app_version
run: |
app_version=$(yq e '.appVersion' ./deployments/chart/Chart.yaml)
echo "app_version=$app_version" >> $GITHUB_ENV
- name: Dispatch Event to create new release
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: caas-team/GoKubeDownscaler
event-type: release-new-version
client-payload: '{"appVersion": "${{ env.app_version }}"}'
17 changes: 6 additions & 11 deletions .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
name: Create Release
name: Create new release

on:
push:
tags:
- "*"
repository_dispatch:
types: [release-new-version]

jobs:
release:
name: Create Release
create_release:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Create GitHub Release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: ${{ github.ref_name }}
tag: v${{ github.event.client_payload.appVersion }}
name: v${{ github.event.client_payload.appVersion }}
generateReleaseNotes: true
32 changes: 5 additions & 27 deletions .github/workflows/docker_build.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
# Build and push Image
name: Build and push Image

on:
push:
repository_dispatch:
types: [release-new-version]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Check Version Format in Tag
if: startsWith(github.ref, 'refs/tags/v')
uses: nowsprinting/[email protected]
id: check-version
with:
prefix: "v"

- name: Set tag
id: set-tag
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
TAG1="dev"
TAG2="commit-$SHORT_SHA"
if [[ "${{ steps.check-version.outputs.is_valid }}" == 'true' ]]; then
TAG1="latest"
TAG2="${{ steps.check-version.outputs.full_without_prefix }}"
fi
echo "TAG1=$TAG1" >> $GITHUB_ENV
echo "TAG2=$TAG2" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -41,8 +19,8 @@ jobs:
mtr.devops.telekom.de/caas/go-kube-downscaler
ghcr.io/caas-team/gokubedownscaler
tags: |
${{ env.TAG1 }}
${{ env.TAG2 }}
latest
${{ github.event.client_payload.appVersion }}
- name: Install Cosign
uses: sigstore/cosign-installer@main
Expand Down
23 changes: 8 additions & 15 deletions .github/workflows/helm_build.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Build and Push Helm Package
name: Build and push helm chart

on:
push:
tags:
- "*"
repository_dispatch:
types: [build-new-chart]

jobs:
helm:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand All @@ -22,13 +21,13 @@ jobs:
helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
helm registry login ${MTR} -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
MTR: mtr.devops.telekom.de

- name: Helm Lint, Package, and Push
run: |
cd chart
cd deployments/chart
helm lint .
helm package .
helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts
Expand All @@ -37,16 +36,10 @@ jobs:
MTR: mtr.devops.telekom.de
REPO: caas

- name: Extract Chart Version
id: chart_version
run: |
version=$(yq e '.version' ./chart/Chart.yaml)
echo "::set-output name=version::$version"
- name: Dispatch Event to Helm-Charts Repo
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: caas-team/helm-charts
event-type: new-helm-chart-version
client-payload: '{"chart": "go-kube-downscaler", "version": "${{ steps.chart_version.outputs.version }}"}'
client-payload: '{"chart": "go-kube-downscaler", "version": "${{ github.event.client_payload.version }}"}'
4 changes: 2 additions & 2 deletions deployments/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: go-kube-downscaler
description: A Helm chart for deploying the go-kube-downscaler

type: application
version: 0.0.0
appVersion: 0.0.0
version: 1.0.0
appVersion: 1.0.0

0 comments on commit d19831b

Please sign in to comment.