Publish Package #12
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: Publish Package | |
| on: | |
| release: | |
| types: | |
| - published | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| publish: | |
| if: ${{ github.event.release.prerelease == false }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| scope: "@willwade" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Derive release version | |
| id: release_version | |
| env: | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| run: | | |
| VERSION="${RELEASE_TAG#refs/tags/}" | |
| VERSION="${VERSION#v}" | |
| if [[ -z "$VERSION" ]]; then | |
| echo "Unable to determine version from release tag '${RELEASE_TAG}'" >&2 | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Sync package metadata | |
| run: | | |
| npm version "${{ steps.release_version.outputs.version }}" --no-git-tag-version | |
| - name: Get OIDC token | |
| id: oidc | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const token = await core.getIDToken('https://registry.npmjs.org'); | |
| core.setOutput('token', token); | |
| - name: Configure npm with OIDC token | |
| run: | | |
| npm config set //registry.npmjs.org/:_authToken "${{ steps.oidc.outputs.token }}" | |
| npm config set @willwade:registry https://registry.npmjs.org/ | |
| - name: Publish to npm (Trusted Publishing) | |
| run: npm publish --access public --provenance | |
| - name: Show npm debug log on failure | |
| if: failure() | |
| run: cat ~/.npm/_logs/*-debug-0.log | tail -100 |