name: release # A single workflow file so npm Trusted Publishing can be configured against it. on: push: branches: - main # Stable releases (latest) - next # Prereleases of the next major permissions: {} # A queued run checks out the tip of its branch, so it also releases what a # running one didn't get to concurrency: ${{ github.workflow }}-${{ github.ref_name }} jobs: release: name: release (${{ github.ref_name }}) runs-on: ubuntu-latest env: DIST_TAG: ${{ github.ref_name == 'next' && 'next' || 'latest' }} # npm's trusted publisher config requires this environment environment: npm-publish permissions: contents: write # Push version commits and tags, create GitHub releases id-token: write # npm trusted publishing steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.ref_name }} # Existing tags let changesets tag only the new versions fetch-tags: true # Pushes the version commit and tags with these credentials persist-credentials: true - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 22.x # Fresh install from the registry, so a poisoned cache can't run in a job that can publish package-manager-cache: false - run: pnpm install --frozen-lockfile - env: ACTOR: ${{ github.actor }} run: | git config --global user.name "$ACTOR" git config --global user.email "$ACTOR@users.noreply.github.com" # `changeset version` fails if there are no changesets. After `pre exit`, # they're in `.changeset/pre/` until the stable release. - if: hashFiles('.changeset/*.md') != '' || (env.DIST_TAG == 'latest' && hashFiles('.changeset/pre.json') != '') run: pnpm run version-packages env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Empty if no changesets were merged - id: version run: | git add -A if ! git diff --cached --quiet; then git commit -m "chore: Version packages" pnpm changeset git-tag git push --follow-tags fi echo "tags=$(git tag --points-at HEAD | xargs)" >> "$GITHUB_OUTPUT" # Uploads the new versions to npm, but they only go live once a maintainer # approves them with 2FA (see CONTRIBUTORS.md) - if: steps.version.outputs.tags run: pnpm -r --filter './packages/**' stage publish --provenance --no-git-checks --tag "$DIST_TAG" # Only next-intl gets a GitHub release, the other packages have their # changelogs. A draft, so it's only published once the npm versions are # live. Notes are the changelog entry. - if: steps.version.outputs.tags run: | tag=$(git tag --points-at HEAD "$PACKAGE@*") [ -n "$tag" ] || exit 0 dir=$(dirname "$(grep -l "\"name\": \"$PACKAGE\"" packages/*/package.json)") awk -v heading="## ${tag##*@}" '$0 == heading {found=1; next} /^## / {found=0} found' "$dir/CHANGELOG.md" > notes.md gh release create "$tag" --draft --verify-tag --prerelease="$PRERELEASE" --title "$tag" --notes-file notes.md env: PACKAGE: next-intl PRERELEASE: ${{ env.DIST_TAG != 'latest' }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}