|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: Action release version to publish, for example v1.0.0 |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + prerelease: |
| 11 | + description: Mark the GitHub release as a prerelease and skip the major tag update |
| 12 | + required: false |
| 13 | + default: false |
| 14 | + type: boolean |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v6 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Setup PNPM |
| 30 | + uses: pnpm/action-setup@v6 |
| 31 | + with: |
| 32 | + run_install: false |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v6 |
| 36 | + with: |
| 37 | + node-version: 24 |
| 38 | + cache: pnpm |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: pnpm install --frozen-lockfile |
| 42 | + |
| 43 | + - name: Check formatting |
| 44 | + run: pnpm format:check |
| 45 | + |
| 46 | + - name: Lint |
| 47 | + run: pnpm lint |
| 48 | + |
| 49 | + - name: Typecheck |
| 50 | + run: pnpm typecheck |
| 51 | + |
| 52 | + - name: Test |
| 53 | + run: pnpm test |
| 54 | + |
| 55 | + - name: Validate action metadata |
| 56 | + run: pnpm validate:action |
| 57 | + |
| 58 | + - name: Build dist |
| 59 | + run: pnpm build |
| 60 | + |
| 61 | + - name: Verify dist is current |
| 62 | + run: git diff --exit-code -- dist/index.js |
| 63 | + |
| 64 | + - name: Validate release version |
| 65 | + id: release |
| 66 | + env: |
| 67 | + RELEASE_VERSION: ${{ inputs.version }} |
| 68 | + run: | |
| 69 | + set -euo pipefail |
| 70 | +
|
| 71 | + if [[ ! "$RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then |
| 72 | + echo "::error::Release version must look like v1.0.0" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + if git rev-parse -q --verify "refs/tags/$RELEASE_VERSION" >/dev/null; then |
| 77 | + echo "::error::Tag $RELEASE_VERSION already exists" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | +
|
| 81 | + version_without_prefix="${RELEASE_VERSION#v}" |
| 82 | + major_version="v${version_without_prefix%%.*}" |
| 83 | +
|
| 84 | + echo "version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT" |
| 85 | + echo "major=$major_version" >> "$GITHUB_OUTPUT" |
| 86 | + shell: bash |
| 87 | + |
| 88 | + - name: Create immutable version tag |
| 89 | + env: |
| 90 | + RELEASE_VERSION: ${{ steps.release.outputs.version }} |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | + git tag "$RELEASE_VERSION" "$GITHUB_SHA" |
| 94 | + git push origin "refs/tags/$RELEASE_VERSION" |
| 95 | + shell: bash |
| 96 | + |
| 97 | + - name: Update major version tag |
| 98 | + if: ${{ !inputs.prerelease }} |
| 99 | + env: |
| 100 | + MAJOR_VERSION: ${{ steps.release.outputs.major }} |
| 101 | + run: | |
| 102 | + set -euo pipefail |
| 103 | + git tag -f "$MAJOR_VERSION" "$GITHUB_SHA" |
| 104 | + git push --force origin "refs/tags/$MAJOR_VERSION" |
| 105 | + shell: bash |
| 106 | + |
| 107 | + - name: Create GitHub release |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ github.token }} |
| 110 | + PRERELEASE: ${{ inputs.prerelease }} |
| 111 | + RELEASE_VERSION: ${{ steps.release.outputs.version }} |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | +
|
| 115 | + args=(release create "$RELEASE_VERSION" --title "$RELEASE_VERSION" --generate-notes) |
| 116 | +
|
| 117 | + if [[ "$PRERELEASE" == "true" ]]; then |
| 118 | + args+=(--prerelease) |
| 119 | + fi |
| 120 | +
|
| 121 | + gh "${args[@]}" |
| 122 | + shell: bash |
0 commit comments