From 1ead15602f21ca7af11fcfd0652d9a6ec8843c45 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 9 Sep 2024 11:14:39 +0200 Subject: [PATCH 01/19] refactor create_release workflow to make automatic release --- .github/workflows/create_release.yaml | 78 +++++++++++++++++++++++---- .github/workflows/docker_build.yaml | 1 - .github/workflows/helm_build.yaml | 52 ------------------ 3 files changed, 69 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/helm_build.yaml diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index 77f543a..c0c8b45 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -1,25 +1,85 @@ -name: Create Release +name: Create a release and push Helm Chart on: push: - tags: - - "*" + branches: + - main + paths: + - deployments/chart/Chart.yaml jobs: - release: - name: Create Release + create_release: runs-on: ubuntu-latest permissions: contents: write + outputs: + latest_tag: ${{ steps.get_latest_tag.outputs.latest_tag }} + version: ${{ steps.chart_version.outputs.version }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract Chart Version + id: chart_version + run: | + version=$(yq e '.version' .deployments/chart/Chart.yaml) + echo "version=$version" >> $GITHUB_OUTPUT + + - name: Get latest Git tag + id: get_latest_tag + run: | + latest_tag=$(git describe --tags --abbrev=0 || echo "No tags found") + echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT - name: Create GitHub Release - id: create_release + if: ${{ steps.get_latest_tag.outputs.latest_tag }} != v${{ steps.chart_version.outputs.version }} + id: create_tag uses: ncipollo/release-action@v1 with: - tag: ${{ github.ref_name }} - name: ${{ github.ref_name }} + tag: v${{ steps.chart_version.outputs.version }} + name: v${{ steps.chart_version.outputs.version }} generateReleaseNotes: true + + push_chart: + runs-on: ubuntu-latest + needs: create_release + if: ${{ needs.create_release.outputs.latest_tag }} != v${{ needs.create_release.outputs.version }} + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Set up Helm + run: | + curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + helm version + + - name: Log in to Helm OCI Registry + run: | + 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}} + MTR: mtr.devops.telekom.de + + - name: Helm Lint, Package, and Push + run: | + cd deployments/chart + helm lint . + helm package . + helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts + helm push $(ls *.tgz | head -1) oci://${MTR}/${REPO}/charts + env: + MTR: mtr.devops.telekom.de + REPO: caas + + - 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": "${{ needs.create_release.outputs.version }}"}' diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 0c59080..881c419 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -1,4 +1,3 @@ -# Build and push Image name: Build and push Image on: diff --git a/.github/workflows/helm_build.yaml b/.github/workflows/helm_build.yaml deleted file mode 100644 index 89aebdf..0000000 --- a/.github/workflows/helm_build.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build and Push Helm Package - -on: - push: - tags: - - "*" - -jobs: - helm: - runs-on: ubuntu-latest - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - - - name: Set up Helm - run: | - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - helm version - - - name: Log in to Helm OCI Registry - run: | - 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}} - MTR: mtr.devops.telekom.de - - - name: Helm Lint, Package, and Push - run: | - cd chart - helm lint . - helm package . - helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts - helm push $(ls *.tgz | head -1) oci://${MTR}/${REPO}/charts - env: - 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 }}"}' From 1a644f793aa5825a8e4d0b49f7d1a903e8f61cd1 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 11:30:58 +0200 Subject: [PATCH 02/19] add check_version workflow --- .github/workflows/check_version.yaml | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/check_version.yaml diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml new file mode 100644 index 0000000..36dc886 --- /dev/null +++ b/.github/workflows/check_version.yaml @@ -0,0 +1,41 @@ +name: Check for new version + +on: + push: + branches: + - main + paths: + - test-chart/Chart.yaml + +jobs: + check_version: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract Chart Version + id: chart_version + run: | + version=$(yq e '.version' ./test-chart/Chart.yaml) + echo "version=$version" >> $GITHUB_ENV + + - name: Get latest Git tag + id: get_latest_tag + run: | + latest_tag=$(git describe --tags --abbrev=0 || echo "No tags found") + echo "latest_tag=$latest_tag" >> $GITHUB_ENV + + - name: Dispatch Event to Helm-Charts Repo + if: ${{ env.version }} != ${{ env.latest_tag}} + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: caas-team/GoKubeDownscaler + event-type: release-new-version + client-payload: '{"version": "${{ env.version }}"}' From aec56c0cc7bf1a4806dab7f7515e6a314d9b5c21 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 11:39:32 +0200 Subject: [PATCH 03/19] =?UTF-8?q?refactor=20doc=C2=B4ker=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker_build.yaml | 32 ++++------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 881c419..8505dde 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -1,37 +1,13 @@ name: Build and push Image on: - push: + repository_dispatch: + types: [release-new-version] jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Check Version Format in Tag - if: startsWith(github.ref, 'refs/tags/v') - uses: nowsprinting/check-version-format-action@v4.0.2 - 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 @@ -40,8 +16,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.version }} - name: Install Cosign uses: sigstore/cosign-installer@main From ce1cb1add638019ab12113918150e2c2ad7f0607 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 11:39:44 +0200 Subject: [PATCH 04/19] refactor helm build --- .github/workflows/helm_build.yaml | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/helm_build.yaml diff --git a/.github/workflows/helm_build.yaml b/.github/workflows/helm_build.yaml new file mode 100644 index 0000000..5242ca2 --- /dev/null +++ b/.github/workflows/helm_build.yaml @@ -0,0 +1,45 @@ +name: Build and Push Helm Package + +on: + repository_dispatch: + types: [release-new-version] + +jobs: + helm: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Set up Helm + run: | + curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + helm version + + - name: Log in to Helm OCI Registry + run: | + 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}} + MTR: mtr.devops.telekom.de + + - name: Helm Lint, Package, and Push + run: | + cd chart + helm lint . + helm package . + helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts + helm push $(ls *.tgz | head -1) oci://${MTR}/${REPO}/charts + env: + MTR: mtr.devops.telekom.de + REPO: caas + + - 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": "${{ github.event.client_payload.version }}"}' From cbc928b554c4380bd2cab3840fd3fb13abd5af50 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 11:40:46 +0200 Subject: [PATCH 05/19] refactor create_release.yaml --- .github/workflows/create_release.yaml | 77 +++------------------------ 1 file changed, 6 insertions(+), 71 deletions(-) diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index c0c8b45..306eae5 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -1,85 +1,20 @@ -name: Create a release and push Helm Chart +name: Create new release on: - push: - branches: - - main - paths: - - deployments/chart/Chart.yaml + repository_dispatch: + types: [release-new-version] jobs: create_release: runs-on: ubuntu-latest permissions: contents: write - outputs: - latest_tag: ${{ steps.get_latest_tag.outputs.latest_tag }} - version: ${{ steps.chart_version.outputs.version }} steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Extract Chart Version - id: chart_version - run: | - version=$(yq e '.version' .deployments/chart/Chart.yaml) - echo "version=$version" >> $GITHUB_OUTPUT - - - name: Get latest Git tag - id: get_latest_tag - run: | - latest_tag=$(git describe --tags --abbrev=0 || echo "No tags found") - echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT - - name: Create GitHub Release - if: ${{ steps.get_latest_tag.outputs.latest_tag }} != v${{ steps.chart_version.outputs.version }} - id: create_tag + id: create_release uses: ncipollo/release-action@v1 with: - tag: v${{ steps.chart_version.outputs.version }} - name: v${{ steps.chart_version.outputs.version }} + tag: v${{ github.event.client_payload.version }} + name: v${{ github.event.client_payload.version }} generateReleaseNotes: true - - push_chart: - runs-on: ubuntu-latest - needs: create_release - if: ${{ needs.create_release.outputs.latest_tag }} != v${{ needs.create_release.outputs.version }} - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - - - name: Set up Helm - run: | - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - helm version - - - name: Log in to Helm OCI Registry - run: | - 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}} - MTR: mtr.devops.telekom.de - - - name: Helm Lint, Package, and Push - run: | - cd deployments/chart - helm lint . - helm package . - helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts - helm push $(ls *.tgz | head -1) oci://${MTR}/${REPO}/charts - env: - MTR: mtr.devops.telekom.de - REPO: caas - - - 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": "${{ needs.create_release.outputs.version }}"}' From bb64d8c19f2f4f6362574fd363383c5b45d34178 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 12:44:01 +0200 Subject: [PATCH 06/19] change version to 1.0.0 --- deployments/chart/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/chart/Chart.yaml b/deployments/chart/Chart.yaml index 5310975..b171092 100644 --- a/deployments/chart/Chart.yaml +++ b/deployments/chart/Chart.yaml @@ -3,5 +3,5 @@ name: go-kube-downscaler description: A Helm chart for deploying the go-kube-downscaler type: application -version: 0.1.0 +version: 1.0.0 appVersion: 1.0.0 From 3afd16a9cfd379ed207374931bc679a8dd025e1f Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 14:08:54 +0200 Subject: [PATCH 07/19] fix path ref --- .github/workflows/check_version.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml index 36dc886..983f16f 100644 --- a/.github/workflows/check_version.yaml +++ b/.github/workflows/check_version.yaml @@ -5,7 +5,7 @@ on: branches: - main paths: - - test-chart/Chart.yaml + - deployments/chart/Chart.yaml jobs: check_version: @@ -22,7 +22,7 @@ jobs: - name: Extract Chart Version id: chart_version run: | - version=$(yq e '.version' ./test-chart/Chart.yaml) + version=$(yq e '.version' ./deployments/chart/Chart.yaml) echo "version=$version" >> $GITHUB_ENV - name: Get latest Git tag From df58447c7c0cf82436c5e6a8be6cdd0d4f0f30d8 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 10 Sep 2024 14:24:30 +0200 Subject: [PATCH 08/19] add missing v --- .github/workflows/check_version.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml index 983f16f..cdc69cb 100644 --- a/.github/workflows/check_version.yaml +++ b/.github/workflows/check_version.yaml @@ -32,7 +32,7 @@ jobs: echo "latest_tag=$latest_tag" >> $GITHUB_ENV - name: Dispatch Event to Helm-Charts Repo - if: ${{ env.version }} != ${{ env.latest_tag}} + if: v${{ env.version }} != ${{ env.latest_tag}} uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.GITHUB_TOKEN }} From a904fb402e12a53dd4f280f4d3bf15d917679830 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 12 Sep 2024 08:55:58 +0200 Subject: [PATCH 09/19] refactor workflows --- .github/workflows/check_version.yaml | 60 +++++++++++++++++++++++---- .github/workflows/create_release.yaml | 4 +- .github/workflows/helm_build.yaml | 12 +++--- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml index cdc69cb..0282db3 100644 --- a/.github/workflows/check_version.yaml +++ b/.github/workflows/check_version.yaml @@ -8,10 +8,11 @@ on: - deployments/chart/Chart.yaml jobs: - check_version: + check_versions: runs-on: ubuntu-latest - permissions: - contents: write + 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 @@ -19,23 +20,64 @@ jobs: 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: Get latest Git tag - id: get_latest_tag + - name: Dispatch Event to Helm-Charts Repo + 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: | - latest_tag=$(git describe --tags --abbrev=0 || echo "No tags found") - echo "latest_tag=$latest_tag" >> $GITHUB_ENV + app_version=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) + echo "app_version=$app_version" >> $GITHUB_ENV - name: Dispatch Event to Helm-Charts Repo - if: v${{ env.version }} != ${{ env.latest_tag}} uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.GITHUB_TOKEN }} repository: caas-team/GoKubeDownscaler event-type: release-new-version - client-payload: '{"version": "${{ env.version }}"}' + client-payload: '{"appVersion": "${{ env.app_version }}"}' diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index 306eae5..ebcc5b8 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -15,6 +15,6 @@ jobs: id: create_release uses: ncipollo/release-action@v1 with: - tag: v${{ github.event.client_payload.version }} - name: v${{ github.event.client_payload.version }} + tag: v${{ github.event.client_payload.appVersion }} + name: v${{ github.event.client_payload.appVersion }} generateReleaseNotes: true diff --git a/.github/workflows/helm_build.yaml b/.github/workflows/helm_build.yaml index 5242ca2..03177a3 100644 --- a/.github/workflows/helm_build.yaml +++ b/.github/workflows/helm_build.yaml @@ -1,11 +1,11 @@ -name: Build and Push Helm Package +name: Build and push helm chart on: repository_dispatch: - types: [release-new-version] + types: [build-new-chart] jobs: - helm: + build_and_push: runs-on: ubuntu-latest steps: - name: Checkout Repo @@ -21,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 From 7ba5df9922870a7c77d50ef26d65583c93ed7544 Mon Sep 17 00:00:00 2001 From: Johannes <38868829+Fovty@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:04:29 +0200 Subject: [PATCH 10/19] 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 --- .github/workflows/check-for-release.yaml | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/check-for-release.yaml diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml new file mode 100644 index 0000000..eb74c73 --- /dev/null +++ b/.github/workflows/check-for-release.yaml @@ -0,0 +1,46 @@ +name: Check for new release + +on: + pull_request: + types: [opened, synchronize, labeled] + +jobs: + check_version_bump: + name: Check For Relase + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract Chart appVersion + id: extract_appversion + run: | + appversion=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) + echo "appversion=$appversion" >> $GITHUB_ENV + + # Check for changes in the appVersion between PR and base branch + - name: Check for appVersion changes + if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') }} + run: | + echo "Checking for appVersion changes..." + if git diff origin/${{ github.base_ref }} -- deployments/chart/Chart.yaml | grep -qe "^[+-]appVersion: "; then + echo "appVersion has changed. Failing the job." + exit 1 + else + echo "No appVersion changes detected." + fi + + # Post warning comment if there is a failure + - name: Post warning comment + if: ${{ failure() }} + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: "⚠️ Warning: This PR will result in a new release because the `appVersion` in Chart.yaml has changed to `${{ env.appversion }}`. Please confirm before merging." From c9395fdc1ca08e94057b0a10f28b68e77aa5e153 Mon Sep 17 00:00:00 2001 From: Jan <157487559+JTaeuber@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:33:11 +0200 Subject: [PATCH 11/19] Fix syntax Co-authored-by: Jonathan Mayer --- .github/workflows/check-for-release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index eb74c73..b497eae 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -5,8 +5,8 @@ on: types: [opened, synchronize, labeled] jobs: - check_version_bump: - name: Check For Relase + check_for_release: + name: Check For Relaese runs-on: ubuntu-latest permissions: contents: write @@ -43,4 +43,4 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.pull_request.number }} - body: "⚠️ Warning: This PR will result in a new release because the `appVersion` in Chart.yaml has changed to `${{ env.appversion }}`. Please confirm before merging." + body: "⚠️ Warning: Merging this PR will result in a new release because the `appVersion` in Chart.yaml has changed to `${{ env.appversion }}`. Please confirm before merging." From 2257b100c1991b6adab3ca1ccdce2aa73ef4fdfc Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 12 Sep 2024 16:03:38 +0200 Subject: [PATCH 12/19] refactor check-for-release.yaml --- .github/workflows/check-for-release.yaml | 47 ++++++++++++++++-------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index b497eae..a3d6fcc 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -6,11 +6,8 @@ on: jobs: check_for_release: - name: Check For Relaese + name: Check For Release runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write steps: - name: Checkout code @@ -18,15 +15,8 @@ jobs: with: fetch-depth: 0 - - name: Extract Chart appVersion - id: extract_appversion - run: | - appversion=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) - echo "appversion=$appversion" >> $GITHUB_ENV - - # Check for changes in the appVersion between PR and base branch - - name: Check for appVersion changes - if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') }} + - name: Check for appVersion change + if: ${{ !contains(github.event.pull_request.labels.*.name, 'new release') }} run: | echo "Checking for appVersion changes..." if git diff origin/${{ github.base_ref }} -- deployments/chart/Chart.yaml | grep -qe "^[+-]appVersion: "; then @@ -36,11 +26,36 @@ jobs: echo "No appVersion changes detected." fi - # Post warning comment if there is a failure + 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 - if: ${{ failure() }} 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 before merging." + 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 replacing the 'needs approval' label with 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 }} From 7a6ca541f61689a3188cf731b28cce1a02f9d8dd Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 12 Sep 2024 16:18:29 +0200 Subject: [PATCH 13/19] fix dependency --- .github/workflows/check-for-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index a3d6fcc..9f17369 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -30,7 +30,7 @@ jobs: 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') }} + if: ${{ failure() && !contains(github.event.pull_request.labels.*.name, 'needs approval') && github.event.action != 'labeled' }} permissions: contents: write pull-requests: write From c6b9b4de13a822080d6e4cd90bc96136a081e848 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 12 Sep 2024 16:29:49 +0200 Subject: [PATCH 14/19] resolve merge conflicts --- deployments/chart/Chart.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/deployments/chart/Chart.yaml b/deployments/chart/Chart.yaml index f21047b..b171092 100644 --- a/deployments/chart/Chart.yaml +++ b/deployments/chart/Chart.yaml @@ -3,10 +3,5 @@ name: go-kube-downscaler description: A Helm chart for deploying the go-kube-downscaler type: application -<<<<<<< feat/RefactorWorkflows version: 1.0.0 appVersion: 1.0.0 -======= -version: 0.0.0 -appVersion: 0.0.0 ->>>>>>> main From 2d80bbb188e5d052917688cec8a3c170643ca51e Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Sep 2024 09:49:55 +0200 Subject: [PATCH 15/19] add label removing --- .github/workflows/check-for-release.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index 9f17369..a2c60bc 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -24,13 +24,23 @@ jobs: exit 1 else echo "No appVersion changes detected." + gh pr edit ${{ github.event.pull_request.number }} --remove-label "needs approval" fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Remove approval label + if: ${{ contains(github.event.pull_request.labels.*.name, 'new release') }} + 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') && github.event.action != 'labeled' }} + if: ${{ failure() && !contains(github.event.pull_request.labels.*.name, 'needs approval') }} permissions: contents: write pull-requests: write From b9f7e5abf9433b5846a1f3a540690c25c6499c3f Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Sep 2024 09:51:09 +0200 Subject: [PATCH 16/19] chore: syntax --- .github/workflows/check-for-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index a2c60bc..8a341b7 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -37,7 +37,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} post_message: - name: Post message to warn of new release + 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') }} From bc23ab04981156aa86996bb5dbb8cca1acdc8dd4 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Sep 2024 09:55:21 +0200 Subject: [PATCH 17/19] change message --- .github/workflows/check-for-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index 8a341b7..b639a3c 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -62,7 +62,7 @@ jobs: 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 replacing the 'needs approval' label with the 'new release' label before merging." + 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: | From 1fc8de9b5786f43ae13b3553ffa7240771c724d4 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Sep 2024 10:24:44 +0200 Subject: [PATCH 18/19] removed not needed if checks --- .github/workflows/check-for-release.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index b639a3c..a9704cc 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -24,13 +24,9 @@ jobs: exit 1 else echo "No appVersion changes detected." - gh pr edit ${{ github.event.pull_request.number }} --remove-label "needs approval" fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Remove approval label - if: ${{ contains(github.event.pull_request.labels.*.name, 'new release') }} run: | gh pr edit ${{ github.event.pull_request.number }} --remove-label "needs approval" env: From cdce99f0731670cecaf2c77159ee084ef7aed05a Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Sep 2024 14:13:21 +0200 Subject: [PATCH 19/19] removal of new release --- .github/workflows/check-for-release.yaml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml index a9704cc..bee3f40 100644 --- a/.github/workflows/check-for-release.yaml +++ b/.github/workflows/check-for-release.yaml @@ -15,12 +15,30 @@ jobs: with: fetch-depth: 0 - - name: Check for appVersion change - if: ${{ !contains(github.event.pull_request.labels.*.name, 'new release') }} + - 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 - echo "appVersion has changed. Failing the job." + 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."