Fix trusted publishing repository metadata #9
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: publish | |
| # No-op change to validate Actions via a PR merge after enabling them for this repository. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - CHANGELOG.md | |
| - .node-version | |
| - package.json | |
| - .github/workflows/publish.yml | |
| - scripts/release/** | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Exact package version that already exists on main | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| id-token: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Enforce main for manual publishes | |
| if: github.event_name == 'workflow_dispatch' && github.ref_name != 'main' | |
| run: | | |
| echo "Manual publishing is only supported from the main branch." | |
| exit 1 | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0 | |
| - name: Setup Node | |
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | |
| with: | |
| node-version-file: .node-version | |
| cache: pnpm | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Prepare release metadata | |
| id: release | |
| env: | |
| ALLOW_MISSING_CHANGELOG: ${{ github.event_name == 'workflow_dispatch' && 'true' || 'false' }} | |
| EXPECTED_VERSION: ${{ github.event.inputs.version }} | |
| RELEASE_NOTES_PATH: release-notes.md | |
| run: node scripts/release/prepare-release.mjs | |
| - name: Skip npm publish | |
| if: steps.release.outputs.should_publish_package != 'true' | |
| run: | | |
| echo "Skipping npm publish." | |
| echo "package.json version: ${{ steps.release.outputs.package_version }}" | |
| echo "latest npm version: ${{ steps.release.outputs.latest_npm_version }}" | |
| echo "reason: ${{ steps.release.outputs.release_reason }}" | |
| - name: Publish package | |
| if: steps.release.outputs.should_publish_package == 'true' | |
| run: npm publish --provenance --access public | |
| - name: Create or update GitHub release | |
| if: steps.release.outputs.should_publish_package == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_NOTES_PATH: ${{ steps.release.outputs.release_notes_path }} | |
| RELEASE_TAG: v${{ steps.release.outputs.package_version }} | |
| RELEASE_TITLE: v${{ steps.release.outputs.package_version }} | |
| run: | | |
| if [ -s "$RELEASE_NOTES_PATH" ]; then | |
| NOTES_FLAG="file" | |
| else | |
| NOTES_FLAG="empty" | |
| fi | |
| if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then | |
| if [ "$NOTES_FLAG" = "file" ]; then | |
| gh release edit "$RELEASE_TAG" --title "$RELEASE_TITLE" --notes-file "$RELEASE_NOTES_PATH" | |
| else | |
| gh release edit "$RELEASE_TAG" --title "$RELEASE_TITLE" --notes "" | |
| fi | |
| else | |
| if [ "$NOTES_FLAG" = "file" ]; then | |
| gh release create "$RELEASE_TAG" --title "$RELEASE_TITLE" --notes-file "$RELEASE_NOTES_PATH" --target "$GITHUB_SHA" | |
| else | |
| gh release create "$RELEASE_TAG" --title "$RELEASE_TITLE" --notes "" --target "$GITHUB_SHA" | |
| fi | |
| fi |