Publish to npm via OIDC Trusted Publishing (#21) #13
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 to npm | |
| on: | |
| push: | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+' | |
| - 'v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js 20.x | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: 'npm' | |
| registry-url: 'https://registry.npmjs.org/' | |
| - name: Upgrade npm for Trusted Publishing | |
| run: npm install -g npm@latest | |
| - name: Determine pre-release tag | |
| id: release-tag | |
| run: | | |
| TAG_NAME=${GITHUB_REF#refs/tags/} | |
| echo "Detected tag: $TAG_NAME" | |
| if [[ "$TAG_NAME" == *-alpha.* ]]; then | |
| echo "tag=alpha" >> $GITHUB_ENV | |
| npm version --no-git-tag-version $TAG_NAME | |
| else | |
| echo "tag=latest" >> $GITHUB_ENV | |
| fi | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Compile the code | |
| run: npm run compile | |
| - name: Publish | |
| run: npm publish --provenance --access public --tag ${{ env.tag }} |