ci: merge publish-next into release workflow #5
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: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| jobs: | |
| publish-latest: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.3.14" | |
| - run: bun install --frozen-lockfile | |
| - run: bun run build | |
| # The version bump (package.json + CHANGELOG.md) already landed on main | |
| # via a release/x.x.x pull request (see the make-release skill), so this | |
| # job only needs to publish that version if it hasn't been already. | |
| - name: Check if this version is already published | |
| id: check | |
| run: | | |
| pkg_name=$(node -p "require('./package.json').name") | |
| pkg_version=$(node -p "require('./package.json').version") | |
| echo "pkg_name=$pkg_name" >> "$GITHUB_OUTPUT" | |
| echo "pkg_version=$pkg_version" >> "$GITHUB_OUTPUT" | |
| if npm view "$pkg_name@$pkg_version" version --registry https://registry.npmjs.org >/dev/null 2>&1; then | |
| echo "already_published=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "already_published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish to GitHub Packages | |
| if: steps.check.outputs.already_published == 'false' | |
| run: bun publish --registry https://npm.pkg.github.com --tag latest --tolerate-republish | |
| env: | |
| NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # bun publish does not support npm's OIDC "Trusted Publishing" yet | |
| # (oven-sh/bun#22423, #24855), so the npm registry step uses the npm CLI instead. | |
| - uses: actions/setup-node@v4 | |
| if: steps.check.outputs.already_published == 'false' | |
| with: | |
| node-version: "22" | |
| - name: Publish to npm | |
| if: steps.check.outputs.already_published == 'false' | |
| run: | | |
| npm install -g npm@latest | |
| npm publish --registry https://registry.npmjs.org --tag latest --access public | |
| - name: Tag and create GitHub Release | |
| if: steps.check.outputs.already_published == 'false' | |
| run: | | |
| version="${{ steps.check.outputs.pkg_version }}" | |
| git tag "v$version" | |
| git push origin "v$version" | |
| awk '/^## /{n++} n==1' CHANGELOG.md > /tmp/release-notes.md | |
| gh release create "v$version" --title "v$version" --notes-file /tmp/release-notes.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| publish-next: | |
| if: github.ref == 'refs/heads/develop' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.3.14" | |
| - run: bun install --frozen-lockfile | |
| - run: bun run build | |
| - run: bunx changeset version --snapshot "next-$(git rev-parse --short HEAD)" --snapshot-prerelease-template "{tag}" | |
| - run: bun publish --registry https://npm.pkg.github.com --tag next --tolerate-republish | |
| env: | |
| NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # bun publish does not support npm's OIDC "Trusted Publishing" yet | |
| # (oven-sh/bun#22423, #24855), so the npm registry step uses the npm CLI instead. | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| - run: npm install -g npm@latest | |
| - name: Publish to npm | |
| run: | | |
| pkg_name=$(node -p "require('./package.json').name") | |
| pkg_version=$(node -p "require('./package.json').version") | |
| if npm view "$pkg_name@$pkg_version" version --registry https://registry.npmjs.org >/dev/null 2>&1; then | |
| echo "$pkg_name@$pkg_version already published to npm, skipping" | |
| else | |
| npm publish --registry https://registry.npmjs.org --tag next --access public | |
| fi |