chore: make installed package smaller #4
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: Release | |
| # Releases are cut by pushing a tag, never automatically on a merge: | |
| # | |
| # 1. bump "version" in package.json, update CHANGELOG.md, commit, push | |
| # 2. git tag -a v1.2.3 -m "Release v1.2.3" && git push origin v1.2.3 | |
| # | |
| # The tag is the trigger and the version in package.json is the source of truth; | |
| # the two must agree or this workflow refuses to run. | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| # Manual re-run, for finishing a release that partly failed. | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| issues: write | |
| id-token: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Full history: release notes are generated from the commit range. | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'pnpm' | |
| - run: pnpm install --frozen-lockfile | |
| # A tag that disagrees with package.json would publish a version nobody | |
| # asked for, so fail before anything reaches the registry. | |
| - name: Check the tag matches package.json | |
| id: check | |
| run: | | |
| set -euo pipefail | |
| NAME="$(node -p "require('./package.json').name")" | |
| VERSION="$(node -p "require('./package.json').version")" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" | |
| if [ "$TAG_VERSION" != "$VERSION" ]; then | |
| echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $VERSION." | |
| exit 1 | |
| fi | |
| echo "Tag $GITHUB_REF_NAME matches package.json." | |
| else | |
| echo "Manual run — releasing version $VERSION from package.json." | |
| fi | |
| # Re-running a tag must not fail on a publish that already succeeded. | |
| if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then | |
| echo "published=true" >> "$GITHUB_OUTPUT" | |
| echo "$NAME@$VERSION is already on npm — the publish step will be skipped." | |
| else | |
| echo "published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Configure git identity | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # release-it neither commits nor tags here — the tag already exists and is | |
| # what triggered this run. It publishes and creates the GitHub release. | |
| # | |
| # `prepublishOnly` runs lint, typecheck, tests and build before the tarball | |
| # is uploaded, so a broken tree cannot reach npm. | |
| - name: Release v${{ steps.check.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| FLAGS="--ci --no-increment" | |
| if [ "${{ steps.check.outputs.published }}" = "true" ]; then | |
| FLAGS="$FLAGS --no-npm.publish" | |
| fi | |
| pnpm release-it $FLAGS | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |