From f85fdff334dc0021fb42c30a5cda5584beea3a05 Mon Sep 17 00:00:00 2001 From: Jan <157487559+JTaeuber@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:46:26 +0200 Subject: [PATCH] Revert "Feat/refactor workflows (#42)" (#49) This reverts commit 8f06df4d272eee393596583fac85b18bd06ee5ac. --- .github/workflows/check-for-release.yaml | 85 ------------------------ .github/workflows/check_version.yaml | 83 ----------------------- .github/workflows/create_release.yaml | 17 +++-- .github/workflows/docker_build.yaml | 33 +++++++-- .github/workflows/helm_build.yaml | 23 ++++--- deployments/chart/Chart.yaml | 4 +- 6 files changed, 57 insertions(+), 188 deletions(-) delete mode 100644 .github/workflows/check-for-release.yaml delete mode 100644 .github/workflows/check_version.yaml diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check-for-release.yaml deleted file mode 100644 index bee3f40..0000000 --- a/.github/workflows/check-for-release.yaml +++ /dev/null @@ -1,85 +0,0 @@ -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 }} diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml deleted file mode 100644 index 0282db3..0000000 --- a/.github/workflows/check_version.yaml +++ /dev/null @@ -1,83 +0,0 @@ -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 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: | - app_version=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) - echo "app_version=$app_version" >> $GITHUB_ENV - - - name: Dispatch Event to Helm-Charts Repo - 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 }}"}' diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index ebcc5b8..77f543a 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -1,20 +1,25 @@ -name: Create new release +name: Create Release on: - repository_dispatch: - types: [release-new-version] + push: + tags: + - "*" jobs: - create_release: + release: + name: 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: v${{ github.event.client_payload.appVersion }} - name: v${{ github.event.client_payload.appVersion }} + tag: ${{ github.ref_name }} + name: ${{ github.ref_name }} generateReleaseNotes: true diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 8505dde..0c59080 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -1,13 +1,38 @@ +# Build and push Image name: Build and push Image on: - repository_dispatch: - types: [release-new-version] + push: 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 @@ -16,8 +41,8 @@ jobs: mtr.devops.telekom.de/caas/go-kube-downscaler ghcr.io/caas-team/gokubedownscaler tags: | - latest - ${{ github.event.client_payload.version }} + ${{ env.TAG1 }} + ${{ env.TAG2 }} - name: Install Cosign uses: sigstore/cosign-installer@main diff --git a/.github/workflows/helm_build.yaml b/.github/workflows/helm_build.yaml index 03177a3..89aebdf 100644 --- a/.github/workflows/helm_build.yaml +++ b/.github/workflows/helm_build.yaml @@ -1,11 +1,12 @@ -name: Build and push helm chart +name: Build and Push Helm Package on: - repository_dispatch: - types: [build-new-chart] + push: + tags: + - "*" jobs: - build_and_push: + helm: runs-on: ubuntu-latest steps: - name: Checkout Repo @@ -21,13 +22,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 deployments/chart + cd chart helm lint . helm package . helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts @@ -36,10 +37,16 @@ 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": "${{ github.event.client_payload.version }}"}' + client-payload: '{"chart": "go-kube-downscaler", "version": "${{ steps.chart_version.outputs.version }}"}' diff --git a/deployments/chart/Chart.yaml b/deployments/chart/Chart.yaml index b171092..97381e7 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: 1.0.0 -appVersion: 1.0.0 +version: 0.0.0 +appVersion: 0.0.0