-
Notifications
You must be signed in to change notification settings - Fork 5
feat(ci): automated npm publishing via trusted publishing #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| name: CI | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_call: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Publish to npm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| release: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types: [published] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id-token: write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ci: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: CI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: ./.github/workflows/ci.yml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| publish: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Publish packages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| needs: ci | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id-token: write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Setup Node.js | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/setup-node@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| node-version: "22" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| registry-url: "https://registry.npmjs.org" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Ensure npm >= 11.5.1 (required for trusted publishing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm install -g npm@latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Build all packages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| corepack enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yarn install --immutable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yarn all:prepare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Verify versions match release tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TAG="${GITHUB_REF_NAME}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for PKG in packages/purchasely packages/google packages/amazon packages/huawei packages/android-player; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VERSION=$(node -p "require('./$PKG/package.json').version") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "$VERSION" != "$TAG" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "::error::$PKG version ($VERSION) does not match release tag ($TAG)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "All package versions match release tag: $TAG" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Publish react-native-purchasely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| working-directory: packages/purchasely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm publish --access public --provenance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Publish @purchasely/react-native-purchasely-google | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| working-directory: packages/google | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm publish --access public --provenance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Publish @purchasely/react-native-purchasely-amazon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| working-directory: packages/amazon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm publish --access public --provenance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Publish @purchasely/react-native-purchasely-huawei | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| working-directory: packages/huawei | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm publish --access public --provenance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Publish @purchasely/react-native-purchasely-android-player | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| working-directory: packages/android-player | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: npm publish --access public --provenance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the workflow fails mid-way (e.g., packages 1–2 publish successfully but package 3 fails due to a transient network error), re-running the workflow will immediately fail on the already-published packages because npm rejects publishing an existing version. This creates an unrecoverable partial-publish state that requires manual intervention. Adding
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: .github/workflows/publish.yml
Line: 56-74
Comment:
**Publish steps are not idempotent — workflow cannot be safely retried**
If the workflow fails mid-way (e.g., packages 1–2 publish successfully but package 3 fails due to a transient network error), re-running the workflow will immediately fail on the already-published packages because npm rejects publishing an existing version. This creates an unrecoverable partial-publish state that requires manual intervention.
Adding `--if-not-exists` makes each step idempotent: npm skips re-publishing an already-published version and exits 0, so a re-run of the workflow will safely publish only the remaining packages.
```suggestion
- name: Publish react-native-purchasely
working-directory: packages/purchasely
run: npm publish --access public --provenance --if-not-exists
- name: Publish @purchasely/react-native-purchasely-google
working-directory: packages/google
run: npm publish --access public --provenance --if-not-exists
- name: Publish @purchasely/react-native-purchasely-amazon
working-directory: packages/amazon
run: npm publish --access public --provenance --if-not-exists
- name: Publish @purchasely/react-native-purchasely-huawei
working-directory: packages/huawei
run: npm publish --access public --provenance --if-not-exists
- name: Publish @purchasely/react-native-purchasely-android-player
working-directory: packages/android-player
run: npm publish --access public --provenance --if-not-exists
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm@latestintroduces non-determinismnpm install -g npm@latestinstalls whatever the current latest npm release is at the time of each workflow run. This means:>= 11.5.1— the actual installed version is never verified.Pin to an explicit version (and update it deliberately via Dependabot or a renovate rule):
Prompt To Fix With AI