From 6b4563bdf77543165f1d09aaea4cd35f81696375 Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Mon, 6 Jan 2025 08:37:57 -0700 Subject: [PATCH] refactor(workflows): remove unnecessary shell declarations and streamline release tagging process --- .github/workflows/helm-repository-sync.yaml | 6 +- .github/workflows/pre-pull-images.yaml | 3 - .github/workflows/release.yaml | 66 ++++++++++++--------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.github/workflows/helm-repository-sync.yaml b/.github/workflows/helm-repository-sync.yaml index 1dd36dbc2..cfa62b15c 100644 --- a/.github/workflows/helm-repository-sync.yaml +++ b/.github/workflows/helm-repository-sync.yaml @@ -35,13 +35,11 @@ jobs: uses: actions/checkout@v4 with: token: "${{ steps.app-token.outputs.token }}" - fetch-depth: 0 - name: Setup Homebrew uses: Homebrew/actions/setup-homebrew@master - name: Setup Workflow Tools - shell: bash run: brew install fluxcd/tap/flux - if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }} @@ -54,7 +52,6 @@ jobs: - if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }} name: Sync Helm Repository - shell: bash run: | declare -a repos=() for f in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do @@ -71,7 +68,6 @@ jobs: - if: ${{ github.event.inputs.helmRepoNamespace != '' && github.event.inputs.helmRepoName != '' }} name: Sync Helm Repository - shell: bash run: | flux --namespace ${{ github.event.inputs.helmRepoNamespace }} \ - reconcile source helm ${{ github.event.inputs.helmRepoName }} || true \ No newline at end of file + reconcile source helm ${{ github.event.inputs.helmRepoName }} || true diff --git a/.github/workflows/pre-pull-images.yaml b/.github/workflows/pre-pull-images.yaml index b20ece2f4..acbec1561 100644 --- a/.github/workflows/pre-pull-images.yaml +++ b/.github/workflows/pre-pull-images.yaml @@ -54,7 +54,6 @@ jobs: - name: Extract Images id: extract-images - shell: bash run: | images=$(yq --indent=0 --output-format=json \ '[.. | .images? | select(. != null)] | flatten | sort | unique' images.yaml \ @@ -70,7 +69,6 @@ jobs: steps: - name: Compare Images id: compare-images - shell: bash run: | images=$(jq --compact-output --null-input \ --argjson f1 '${{ needs.extract-images.outputs.default }}' \ @@ -94,7 +92,6 @@ jobs: uses: Homebrew/actions/setup-homebrew@master - name: Setup Workflow Tools - shell: bash run: brew install siderolabs/tap/talosctl - name: Pre-pull Image diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ab809acf3..5f95dc7cf 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,34 +19,44 @@ jobs: app-id: "${{ secrets.BOT_APP_ID }}" private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}" - - name: Checkout - uses: actions/checkout@v4 + - name: Get Previous Release Tag and Determine Next Tag + id: determine-next-tag + uses: actions/github-script@v7 with: - token: "${{ steps.app-token.outputs.token }}" + github-token: "${{ steps.app-token.outputs.token }}" + result-encoding: string + script: | + const { data: releases } = await github.rest.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 1, + }); + + let previousTag = "0.0.0"; // Default if no previous release exists + if (releases.length > 0) { + previousTag = releases[0].tag_name; + } + + const [previousMajor, previousMinor, previousPatch] = previousTag.split('.').map(Number); + const currentYear = new Date().getFullYear(); + const currentMonth = new Date().getMonth() + 1; // Months are 0-indexed in JavaScript + + const nextMajorMinor = `${currentYear}.${currentMonth}`; + let nextPatch; + + if (`${previousMajor}.${previousMinor}` === nextMajorMinor) { + console.log("Month release already exists for the year. Incrementing patch number by 1."); + nextPatch = previousPatch + 1; + } else { + console.log("Month release does not exist for the year. Starting with patch number 0."); + nextPatch = 0; + } + + return `${nextMajorMinor}.${nextPatch}`; - name: Create Release - shell: bash - env: - GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}" - run: | - # Retrieve previous release tag - previous_tag="$(gh release list --limit 1 | awk '{ print $1 }')" - previous_major="${previous_tag%%\.*}" - previous_minor="${previous_tag#*.}" - previous_minor="${previous_minor%.*}" - previous_patch="${previous_tag##*.}" - # Determine next release tag - next_major_minor="$(date +'%Y').$(date +'%-m')" - if [[ "${previous_major}.${previous_minor}" == "${next_major_minor}" ]]; then - echo "Month release already exists for year, incrementing patch number by 1" - next_patch="$((previous_patch + 1))" - else - echo "Month release does not exist for year, setting patch number to 0" - next_patch="0" - fi - # Create release - release_tag="${next_major_minor}.${next_patch}" - gh release create "${release_tag}" \ - --repo="${GITHUB_REPOSITORY}" \ - --title="${release_tag}" \ - --generate-notes + uses: ncipollo/release-action@v1 + with: + generateReleaseNotes: true + tag: "${{ steps.determine-next-tag.outputs.result }}" + token: "${{ steps.app-token.outputs.token }}"