chore: update publish.yaml to use npm ci #47
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: | |
| push: | |
| branches: main | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update npm | |
| run: npm install -g npm@latest | |
| - name: Get package version | |
| id: version | |
| run: | | |
| echo "version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| echo "version_number=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Check if tag exists | |
| id: tag_check | |
| run: | | |
| if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Extract changelog for version | |
| if: steps.tag_check.outputs.exists == 'false' | |
| run: | | |
| VERSION_NUMBER="${{ steps.version.outputs.version_number }}" | |
| awk -v ver="$VERSION_NUMBER" ' | |
| /^## \[/ { | |
| if (found) exit | |
| if (index($0, ver)) found=1 | |
| next | |
| } | |
| found { print } | |
| ' CHANGELOG.md > release_notes.md | |
| - name: Create tag and release | |
| if: steps.tag_check.outputs.exists == 'false' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag ${{ steps.version.outputs.version }} | |
| git push origin ${{ steps.version.outputs.version }} | |
| gh release create ${{ steps.version.outputs.version }} \ | |
| --title "${{ steps.version.outputs.version }}" \ | |
| --notes-file release_notes.md | |
| - name: Check if already published | |
| id: npm_check | |
| run: | | |
| PUBLISHED=$(npm view @reserve-protocol/react-zapper version 2>/dev/null || echo "0.0.0") | |
| CURRENT="${{ steps.version.outputs.version_number }}" | |
| if [ "$PUBLISHED" = "$CURRENT" ]; then | |
| echo "published=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "published=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Install dependencies | |
| if: steps.npm_check.outputs.published == 'false' | |
| run: npm ci | |
| - name: Build package | |
| if: steps.npm_check.outputs.published == 'false' | |
| run: npm run build | |
| - name: Publish to npm | |
| if: steps.npm_check.outputs.published == 'false' | |
| run: npm publish |