diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 761123d4e9..78343e17cd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,37 +18,50 @@ 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 - env: - GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}" - run: | - # Retrieve previous release tag - previous_tag="$(gh release list --limit 1 --json tagName --jq '.[0].tagName')" - if [[ -z "${previous_tag}" ]]; then - echo "No previous release found. Starting with the first release of the year and month." - previous_tag="0.0.0" - fi - # Parse previous release tag into components - previous_major=$(cut -d. -f1 <<<"${previous_tag}") - previous_minor=$(cut -d. -f2 <<<"${previous_tag}") - previous_patch=$(cut -d. -f3 <<<"${previous_tag}") - # Determine next release tag components - 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: actions/github-script@v7 + with: + github-token: "${{ steps.app-token.outputs.token }}" + script: | + await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "${{ steps.determine-next-tag.outputs.result }}", + name: "${{ steps.determine-next-tag.outputs.result }}", + generate_release_notes: true, + });