Repository navigation
v0.4.2 #12
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: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| publish: | |
| if: github.repository == 'chenlongapps/opencode-token-usage' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| package-manager-cache: false | |
| - run: npm install --global npm@^11.5.1 | |
| - run: npm ci | |
| - name: Verify release tag | |
| run: node --eval "const pkg = require('./package.json'); const expected = 'v' + pkg.version; if (process.env.GITHUB_REF_NAME !== expected) throw new Error('Release tag ' + process.env.GITHUB_REF_NAME + ' does not match ' + expected)" | |
| - run: npm run typecheck | |
| - run: npm test | |
| - id: registry | |
| name: Check whether this version is already published | |
| shell: bash | |
| run: | | |
| package_name="$(node --print "require('./package.json').name")" | |
| package_version="$(node --print "require('./package.json').version")" | |
| if npm view "$package_name@$package_version" version >/dev/null 2>&1; then | |
| echo "published=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - if: steps.registry.outputs.published != 'true' | |
| run: npm publish |