Skip to content

Commit 4bfc3f4

Browse files
authored
Merge pull request #283 from contentstack/feat/DX-27614
chore(release): publish to npm with trusted publishing
2 parents 8c6c69c + c04ca39 commit 4bfc3f4

7 files changed

Lines changed: 918 additions & 781 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ on:
99
jobs:
1010
build-test:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
checks: write
15+
pull-requests: write
1216
steps:
1317
- uses: actions/checkout@v3
14-
- uses: ArtiomTr/jest-coverage-report-action@v2
18+
- uses: ArtiomTr/jest-coverage-report-action@7f750dd50f5585533321eb7ebc482b936b49a5d4 # v2
1519
id: coverage-utils-js
1620
with:
1721
output: comment, report-markdown

‎.github/workflows/npm-publish.yml‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎.github/workflows/release.yml‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish package to npmjs registry
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
publish-npm:
8+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v7
15+
with:
16+
ref: ${{ github.event.release.tag_name }}
17+
persist-credentials: false
18+
- uses: actions/setup-node@v7
19+
with:
20+
node-version: 24
21+
registry-url: https://registry.npmjs.org/
22+
cache: 'npm'
23+
- name: Check the release tag matches package.json
24+
env:
25+
RELEASE_TAG: ${{ github.event.release.tag_name }}
26+
run: |
27+
PKG_VERSION="v$(node -p "require('./package.json').version")"
28+
if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then
29+
echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION"
30+
exit 1
31+
fi
32+
- run: npm ci
33+
- name: Update npm
34+
run: npm install -g npm@latest
35+
- name: Release
36+
run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }}
37+
38+
publish-github:
39+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: read
43+
packages: write
44+
steps:
45+
- uses: actions/checkout@v7
46+
with:
47+
ref: ${{ github.event.release.tag_name }}
48+
persist-credentials: false
49+
- uses: actions/setup-node@v7
50+
with:
51+
node-version: 24
52+
registry-url: https://npm.pkg.github.com/
53+
cache: 'npm'
54+
- name: Check the release tag matches package.json
55+
env:
56+
RELEASE_TAG: ${{ github.event.release.tag_name }}
57+
run: |
58+
PKG_VERSION="v$(node -p "require('./package.json').version")"
59+
if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then
60+
echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION"
61+
exit 1
62+
fi
63+
- run: npm ci
64+
- name: Update npm
65+
run: npm install -g npm@latest
66+
- name: Release
67+
run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }}
68+
env:
69+
NODE_AUTH_TOKEN: ${{ github.token }}

‎.talismanrc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ fileignoreconfig:
22
- filename: .github/workflows/secrets-scan.yml
33
ignore_detectors:
44
- filecontent
5+
- filename: .github/workflows/ci.yml
6+
checksum: 14991153c5531029f3ac14dbce6fab70aa4b654d445a3514083d446bfadc8813
57
- filename: package-lock.json
6-
checksum: 8e62821551e64c0fbd23ce2951b44e41561196f0d38b6a2da7de1f6921b48865
8+
ignore_detectors:
9+
- filecontent
10+
- base64content

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ npm run download-regions # regions.json only (also run as part of prebuild)
2929

3030
`npm test` runs **`pretest` → `npm run build`**, then Jest with coverage; outputs under **`reports/`**. Use **`npm run test:debug`** for Jest watch mode (`--runInBand`).
3131

32-
**CI:** `.github/workflows/ci.yml` (unit tests / coverage on `development`, `master`). Publish: `.github/workflows/npm-publish.yml` (GitHub **Release** created for tag `v*`; draft releases are skipped). Back-merge automation: `.github/workflows/back-merge-pr.yml`.
32+
**CI:** `.github/workflows/ci.yml` (unit tests / coverage on `development`, `master`). Publish: `.github/workflows/release.yml` (runs when a GitHub **Release** is published for tag `v*`; drafts are skipped) — npm through OIDC trusted publishing, GitHub Packages with the job token. Back-merge automation: `.github/workflows/back-merge-pr.yml`.
3333

3434
Install: `npm i @contentstack/utils` — see root **`README.md`** and **`package.json`** for the current version.
3535

0 commit comments

Comments
 (0)