Release #2
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: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Action release version to publish, for example v1.0.0 | |
| required: true | |
| type: string | |
| prerelease: | |
| description: Mark the GitHub release as a prerelease and skip moving action tag updates | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup PNPM | |
| uses: pnpm/action-setup@v6 | |
| with: | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Check formatting | |
| run: pnpm format:check | |
| - name: Lint | |
| run: pnpm lint | |
| - name: Typecheck | |
| run: pnpm typecheck | |
| - name: Test | |
| run: pnpm test | |
| - name: Validate action metadata | |
| run: pnpm validate:action | |
| - name: Build dist | |
| run: pnpm build | |
| - name: Verify dist is current | |
| run: git diff --exit-code -- dist/index.js | |
| - name: Validate release version | |
| id: release | |
| env: | |
| RELEASE_VERSION: ${{ inputs.version }} | |
| run: | | |
| set -euo pipefail | |
| if [[ ! "$RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then | |
| echo "::error::Release version must look like v1.0.0" | |
| exit 1 | |
| fi | |
| if git rev-parse -q --verify "refs/tags/$RELEASE_VERSION" >/dev/null; then | |
| echo "::error::Tag $RELEASE_VERSION already exists" | |
| exit 1 | |
| fi | |
| version_without_prefix="${RELEASE_VERSION#v}" | |
| major="${version_without_prefix%%.*}" | |
| remaining="${version_without_prefix#*.}" | |
| minor="${remaining%%.*}" | |
| major_version="v$major" | |
| minor_version="v$major.$minor" | |
| { | |
| echo "version=$RELEASE_VERSION" | |
| echo "major=$major_version" | |
| echo "minor=$minor_version" | |
| } >> "$GITHUB_OUTPUT" | |
| shell: bash | |
| - name: Create immutable version tag | |
| env: | |
| RELEASE_VERSION: ${{ steps.release.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| git tag "$RELEASE_VERSION" "$GITHUB_SHA" | |
| git push origin "refs/tags/$RELEASE_VERSION" | |
| shell: bash | |
| - name: Update moving action tags | |
| if: ${{ !inputs.prerelease }} | |
| env: | |
| MAJOR_VERSION: ${{ steps.release.outputs.major }} | |
| MINOR_VERSION: ${{ steps.release.outputs.minor }} | |
| run: | | |
| set -euo pipefail | |
| git tag -f "$MINOR_VERSION" "$GITHUB_SHA" | |
| git push --force origin "refs/tags/$MINOR_VERSION" | |
| git tag -f "$MAJOR_VERSION" "$GITHUB_SHA" | |
| git push --force origin "refs/tags/$MAJOR_VERSION" | |
| shell: bash | |
| - name: Create GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PRERELEASE: ${{ inputs.prerelease }} | |
| RELEASE_VERSION: ${{ steps.release.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| args=(release create "$RELEASE_VERSION" --title "$RELEASE_VERSION" --generate-notes) | |
| if [[ "$PRERELEASE" == "true" ]]; then | |
| args+=(--prerelease) | |
| fi | |
| gh "${args[@]}" | |
| shell: bash |