0.12.0 #26
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: Node.js Package | |
| on: | |
| release: | |
| types: [created, published] | |
| workflow_dispatch: | |
| jobs: | |
| install: | |
| runs-on: ubuntu-latest | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Restore node_modules cache | |
| id: cache-node | |
| uses: actions/cache@v3 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install dependencies (if cache miss) | |
| if: steps.cache-node.outputs.cache-hit != 'true' | |
| run: npm install | |
| build-and-test: | |
| needs: install | |
| runs-on: ubuntu-latest | |
| env: | |
| NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Restore node_modules cache | |
| id: cache-node | |
| uses: actions/cache@v3 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install dependencies (if cache miss) | |
| if: steps.cache-node.outputs.cache-hit != 'true' | |
| run: npm install | |
| - run: npm run build | |
| - run: npm run test | |
| publish-gpr: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: write | |
| env: | |
| NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Switch to main branch | |
| if: github.event_name == 'release' | |
| run: | | |
| git checkout main | |
| git pull origin main | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://npm.pkg.github.com/ | |
| - name: Restore node_modules cache | |
| id: cache-node | |
| uses: actions/cache@v3 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install dependencies (if cache miss) | |
| if: steps.cache-node.outputs.cache-hit != 'true' | |
| run: npm install | |
| - name: Extract version from release tag | |
| if: github.event_name == 'release' | |
| id: extract-version | |
| run: | | |
| TAG_NAME="${{ github.event.release.tag_name }}" | |
| # Remove 'v' prefix if present (e.g., v1.2.3 -> 1.2.3) | |
| VERSION=${TAG_NAME#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Update package.json version | |
| if: github.event_name == 'release' | |
| run: | | |
| npm version --no-git-tag-version ${{ steps.extract-version.outputs.version }} | |
| - name: Commit version update | |
| if: github.event_name == 'release' | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: 'chore: update version to ${{ steps.extract-version.outputs.version }}' | |
| file_pattern: 'package.json package-lock.json' | |
| branch: main | |
| - run: npm publish --access public |