diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e29bc01..939dcc6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,6 +47,46 @@ jobs: --repo "${REPO}" \ --draft=false + update-floating-tag: + runs-on: 'ubuntu-latest' + needs: + - 'create-release' + steps: + - name: 'Update floating tag' + uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7 + env: + RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}' + REPO: '${{ github.repository }}' + with: + github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}' + script: |- + const tag = process.env.RELEASE_VERSION; + const major = tag.split(".")[0]; + const githubActionsRef = `${process.env.REPO}@${major}` + + // Try to update the ref first. If that fails, it probably does not + // exist yet, and we should create it. + try { + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "tags/" + major, + sha: context.sha, + force: true, + }); + core.info(`Updated ${githubActionsRef} to ${context.sha} (${tag})`); + } catch (err) { + core.warning(`Failed to create tag ${major}: ${err}`); + + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "refs/tags/" + major, + sha: context.sha, + }); + core.info(`Created ${githubActionsRef} at ${context.sha} (${tag})`); + } + cleanup-failed-release: if: |- ${{ always() && needs.create-release.outputs.created == 'true' && contains(fromJSON('["failure", "cancelled", "skipped"]'), needs.publish-release.result) }}