1.2.1 #4
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: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - "v*" | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| ci: | |
| name: CI (Node ${{ matrix.node-version }}) | |
| runs-on: windows-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| node-version: | |
| - 20 | |
| - 22 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run checks | |
| run: npm run check | |
| publish: | |
| name: Publish to npm | |
| runs-on: windows-latest | |
| needs: ci | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: https://registry.npmjs.org | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build package | |
| run: npm run build | |
| - name: Verify tag matches package version | |
| run: | | |
| node -e 'const fs=require("node:fs"); | |
| const tag=(process.env.GITHUB_REF_NAME||"").replace(/^v/,""); | |
| const version=JSON.parse(fs.readFileSync("package.json","utf8")).version; | |
| if(tag!==version){ | |
| console.error("Tag version ("+tag+") does not match package.json version ("+version+")."); | |
| process.exit(1); | |
| } | |
| console.log("Tag version matches package.json: "+version);' | |
| - name: Publish package | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |