Skip to content

tag-release

tag-release #6

Workflow file for this run

name: tag-release
run-name: tag-release
description: |
Tag a given commit as a release
on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
project:
type: choice
required: true
default: "jco"
options:
- jco
- js-component-bindgen
- preview2-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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
ref: ${{ github.event.inputs.ref || 'main' }}
# Pull project and version
# (automatically triggered run)
- name: Collect metadata
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: meta
with:
script: |
switch (context.eventName) {
case 'pull_request':
if (!context?.payload?.head?.ref.includes("prep-release")) {
console.log(`invalid ref [${context?.payload?.head?.ref}]: does not include 'prep-release'`);
return;
}
if (!context?.payload?.head?.ref || !context.payload.head.merged) {
console.log("invalid/unexpected pull request event type (must be merged, must have ref)");
return;
}
if (!context?.payload?.commits?.len || context?.payload?.commits?.len == 0) {
console.log("missing commits on automatically triggered merge");
return;
}
const commitMsg = context.payload.commits[0].message;
const [_, project, version] = /^release:\s([^\s]+)\sv([^\s]+)$/.match(commitMsg);
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;