Publish Package to npm #2
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 to npm | |
| on: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ github.event.repository.default_branch }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies and generate package-lock.json | |
| run: | | |
| npm install | |
| npm install --package-lock-only | |
| git add package-lock.json | |
| git commit -m "chore: update package-lock.json" || echo "No changes to commit" | |
| - name: Update package.json with release tag | |
| run: | | |
| TAG="${{ github.event.release.tag_name }}" | |
| echo "Updating package.json version to $TAG" | |
| npm version "$TAG" --no-git-tag-version --allow-same-version | |
| - name: Commit and push version update | |
| run: | | |
| TAG="${{ github.event.release.tag_name }}" | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git add package.json package-lock.json | |
| git commit -m "Update package.json to version $TAG" | |
| git push origin ${{ github.event.repository.default_branch }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |