|
1 | 1 | name: Publish Package to npmjs |
2 | 2 |
|
3 | | -# Trigger this workflow when a release is published |
4 | 3 | on: |
5 | 4 | release: |
6 | 5 | types: [published] |
7 | 6 | workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: 'Existing release tag to publish (for example, v1.2.0)' |
| 10 | + required: true |
| 11 | + type: string |
8 | 12 |
|
9 | 13 | jobs: |
10 | 14 | build: |
11 | | - # Specify the runner environment |
12 | 15 | runs-on: ubuntu-latest |
13 | 16 | permissions: |
14 | 17 | contents: write |
15 | 18 | id-token: write |
| 19 | + env: |
| 20 | + RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }} |
16 | 21 |
|
17 | 22 | steps: |
18 | | - # Step 1: Check out the repository's code |
19 | 23 | - name: Check out repository |
20 | 24 | uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ env.RELEASE_TAG }} |
| 27 | + fetch-depth: 0 |
21 | 28 |
|
22 | | - # Step 2: Set up Node.js environment |
23 | 29 | - name: Set up Node.js |
24 | 30 | uses: actions/setup-node@v4 |
25 | 31 | with: |
26 | | - node-version: '24' # Node 24 includes npm 11+ required for OIDC Trusted Publishing |
| 32 | + node-version: '24' |
| 33 | + |
| 34 | + - name: Verify release tag and version |
| 35 | + run: | |
| 36 | + node <<'NODE' |
| 37 | + const { execFileSync } = require('node:child_process'); |
| 38 | + const { version } = require('./package.json'); |
| 39 | + const tag = process.env.RELEASE_TAG; |
| 40 | + if (tag !== `v${version}`) { |
| 41 | + throw new Error('Release tag must match the package.json version'); |
| 42 | + } |
| 43 | + const commit = ref => execFileSync('git', ['rev-parse', '--verify', ref], { encoding: 'utf8' }).trim(); |
| 44 | + if (commit(`refs/tags/${tag}^{commit}`) !== commit('HEAD')) { |
| 45 | + throw new Error('The checked-out commit must match the release tag'); |
| 46 | + } |
| 47 | + NODE |
27 | 48 |
|
28 | | - # Step 3: Install dependencies using npm ci |
29 | 49 | - name: Install dependencies |
30 | 50 | run: npm ci |
31 | 51 |
|
32 | | - # Step 4: Build package and bundles |
33 | | - - name: Build package and bundles |
34 | | - id: build |
35 | | - run: npm run build |
| 52 | + - name: Check formatting, lint, and tests |
| 53 | + id: verify |
| 54 | + run: npm run format:check && npm run lint && npm test |
36 | 55 |
|
37 | | - # Step 5: Publish the package to npm using Trusted Publishing (OIDC) |
38 | 56 | - name: Publish to npm |
39 | | - run: npm publish --provenance --access public |
| 57 | + # Verification already built and tested these artifacts; local publishing keeps prepublishOnly. |
| 58 | + run: npm publish --provenance --access public --ignore-scripts |
40 | 59 |
|
41 | | - # Step 6: Upload bundle assets to release |
42 | 60 | - name: Upload bundle assets to release |
43 | | - if: always() && steps.build.outcome == 'success' |
| 61 | + if: always() && steps.verify.outcome == 'success' |
44 | 62 | uses: softprops/action-gh-release@v2 |
45 | 63 | with: |
| 64 | + tag_name: ${{ env.RELEASE_TAG }} |
| 65 | + fail_on_unmatched_files: true |
46 | 66 | files: | |
47 | 67 | dist/umd/arabic-services.umd.js |
48 | 68 | dist/umd/arabic-services.umd.js.map |
|
0 commit comments