|
| 1 | +# Manual release: bumps the version, prepends auto-generated release notes to |
| 2 | +# CHANGELOG.md, tags, creates a GitHub release, and publishes to npm. |
| 3 | +# |
| 4 | +# Publishing uses npm trusted publishing (OIDC), so no npm token is stored in |
| 5 | +# the repository. One-time setup and the first manual publish are documented |
| 6 | +# in the repository wiki. |
| 7 | +name: Release |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: "Version to release, e.g. 0.2.0 (tags v0.2.0)" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +concurrency: release |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + id-token: write # npm trusted publishing (OIDC) |
| 22 | + |
| 23 | +jobs: |
| 24 | + release: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + env: |
| 27 | + VERSION: ${{ inputs.version }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v7 |
| 30 | + with: |
| 31 | + # Full history so release notes and the previous tag are found. |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + # package-manager-cache: false is required. setup-node auto-enables npm |
| 35 | + # caching when it detects a lockfile, and that step runs npm config get |
| 36 | + # cache with the runner's bundled npm 10/11, which fails the repository's |
| 37 | + # devEngines check (npm >= 12) before the upgrade step below can run. |
| 38 | + # Simply leaving the cache option unset is not enough because auto-caching |
| 39 | + # is on by default. |
| 40 | + - uses: actions/setup-node@v7 |
| 41 | + with: |
| 42 | + node-version-file: .nvmrc |
| 43 | + registry-url: "https://registry.npmjs.org" |
| 44 | + package-manager-cache: false |
| 45 | + |
| 46 | + # Runs outside the repository because the runner's bundled npm 11 would |
| 47 | + # otherwise fail the repository's devEngines check (npm >= 12) before it |
| 48 | + # can upgrade itself. |
| 49 | + - name: Use npm 12 (required by devEngines and trusted publishing) |
| 50 | + run: npm install -g npm@12 |
| 51 | + working-directory: ${{ runner.temp }} |
| 52 | + |
| 53 | + - name: Validate version |
| 54 | + run: | |
| 55 | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 56 | + echo "::error::'$VERSION' is not plain X.Y.Z semver" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + if git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then |
| 60 | + echo "::error::tag v$VERSION already exists" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + - run: npm ci |
| 65 | + - run: npm run lint |
| 66 | + - run: npm run format:check |
| 67 | + - run: npm run typecheck |
| 68 | + - run: npm run build |
| 69 | + - run: npm test |
| 70 | + |
| 71 | + - name: Bump version |
| 72 | + run: npm version --no-git-tag-version "$VERSION" |
| 73 | + |
| 74 | + - name: Generate release notes and update CHANGELOG.md |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ github.token }} |
| 77 | + run: | |
| 78 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match 'v*' 2>/dev/null || true) |
| 79 | + gh api "repos/${{ github.repository }}/releases/generate-notes" \ |
| 80 | + -f tag_name="v$VERSION" \ |
| 81 | + -f target_commitish="${{ github.sha }}" \ |
| 82 | + ${PREVIOUS_TAG:+-f previous_tag_name="$PREVIOUS_TAG"} \ |
| 83 | + --jq .body > /tmp/release-notes.md |
| 84 | + { |
| 85 | + echo "# Changelog" |
| 86 | + echo |
| 87 | + echo "## v$VERSION ($(date -u +%Y-%m-%d))" |
| 88 | + echo |
| 89 | + cat /tmp/release-notes.md |
| 90 | + echo |
| 91 | + tail -n +3 CHANGELOG.md |
| 92 | + } > /tmp/changelog.md |
| 93 | + mv /tmp/changelog.md CHANGELOG.md |
| 94 | +
|
| 95 | + - name: Commit, tag and push |
| 96 | + run: | |
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 99 | + git add package.json package-lock.json CHANGELOG.md |
| 100 | + git commit -m "chore: release v$VERSION" |
| 101 | + git tag "v$VERSION" |
| 102 | + git push origin "HEAD:$GITHUB_REF_NAME" |
| 103 | + git push origin "v$VERSION" |
| 104 | +
|
| 105 | + - name: Create GitHub release |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ github.token }} |
| 108 | + run: gh release create "v$VERSION" --title "v$VERSION" --notes-file /tmp/release-notes.md |
| 109 | + |
| 110 | + - name: Publish to npm (trusted publishing, provenance attached) |
| 111 | + run: npm publish |
0 commit comments