tag-release #828
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: tag-release | |
| run-name: tag-release | |
| description: | | |
| Tag a given commit as a release | |
| on: | |
| merge_group: | |
| pull_request: | |
| types: | |
| - closed | |
| workflow_dispatch: | |
| inputs: | |
| project: | |
| type: choice | |
| required: true | |
| default: "jco" | |
| options: | |
| - jco | |
| - jco-transpile | |
| - jco-std | |
| - js-component-bindgen | |
| - preview2-shim | |
| - preview3-shim | |
| description: | | |
| Project to tag for release (ex. `0.1.0`) | |
| ref: | |
| type: string | |
| required: true | |
| description: | | |
| Repository ref to tag (e.x. 'branch', 'jco-v0.1.0', '<long SHA>') | |
| version: | |
| type: string | |
| required: true | |
| description: | | |
| Version tag (e.x. `0.1.0`) | |
| permissions: | |
| contents: none | |
| jobs: | |
| tag-release: | |
| runs-on: ubuntu-24.04 | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.ref || 'main' }} | |
| token: ${{ secrets.RELEASE_PAT || github.token }} | |
| # Pull project and version | |
| # (automatically triggered run) | |
| - name: Collect metadata | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| id: meta | |
| with: | |
| script: | | |
| switch (context.eventName) { | |
| case 'pull_request': | |
| const pr = context?.payload?.pull_request; | |
| if (!pr) { | |
| throw new Error("Invalid/missing pull request payload"); | |
| return; | |
| } | |
| console.log(`sha: [${pr.merge_commit_sha}]`); | |
| const headMerged = pr.merged; | |
| const numCommits = pr.commits.len; | |
| const title = pr.title; | |
| if (!headMerged) { | |
| console.log("Invalid/unexpected pull request event type (must be merged)"); | |
| return; | |
| } | |
| if (!title?.startsWith("release:")) { | |
| console.log(`Invalid ref [${title}]: does not include 'prep-release'`); | |
| return; | |
| } | |
| const [_, project, version] = /^release:\s+([^\s]+)\s+v([^\s]+)$/.exec(title); | |
| core.setOutput('proceed', "true"); | |
| core.setOutput('project', project); | |
| core.setOutput('version', version); | |
| return; | |
| case 'workflow_dispatch': | |
| core.setOutput('proceed', "true"); | |
| core.setOutput('project', context.payload.inputs.project); | |
| core.setOutput('version', context.payload.inputs.version); | |
| return; | |
| default: | |
| console.log(`unexpected github event name [${context.eventName}]`); | |
| return; | |
| } | |
| - name: Push tag | |
| if: ${{ steps.meta.outputs.proceed }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]"; | |
| git config user.email "github-actions[bot]@users.noreply.github.com"; | |
| export TAG=${{ steps.meta.outputs.project }}-v${{ steps.meta.outputs.version }}; | |
| git tag $TAG; | |
| git push origin $TAG; |