Skip to content

Commit 4fa2fc1

Browse files
authored
fix: add trusted publisher to v4-client-js (#478)
Remove GAT usage in publish script
1 parent e83382f commit 4fa2fc1

3 files changed

Lines changed: 47 additions & 37 deletions

File tree

.github/workflows/js-publish.yml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,27 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
build-and-publish:
15+
publish:
1616
runs-on: ubuntu-latest
17-
defaults:
18-
run:
19-
working-directory: ./v4-client-js
2017
permissions:
2118
contents: write
19+
id-token: write
20+
2221
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v3
22+
- uses: actions/checkout@v3
2523
with:
26-
fetch-depth: 0 # fetch all history for all tags and branches
24+
fetch-depth: 0
2725

28-
- name: Npm
29-
uses: actions/setup-node@v3
26+
- name: Setup Node
27+
uses: actions/setup-node@v4
3028
with:
31-
node-version: 20.8.1
32-
registry-url: https://registry.npmjs.org
33-
cache: "npm"
29+
node-version-file: '.nvmrc'
30+
registry-url: https://registry.npmjs.org/
31+
cache: npm
3432
cache-dependency-path: '**/package-lock.json'
3533

36-
- name: Install
34+
- name: Install dependencies
3735
run: npm ci
38-
env:
39-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_READ }}
40-
41-
# Run semantic-release to automatically bump the version based on PR title
42-
- name: Run semantic-release
43-
run: npm run release
44-
env:
45-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_WRITE }}
46-
4736

37+
- name: Publish if needed
38+
run: ./v4-client-js/scripts/publish-if-not-exists.sh

v4-client-js/.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.8.1
1+
v24
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
#!/bin/bash
2-
set -euxo pipefail
1+
#!/usr/bin/env bash
2+
set -euo pipefail
33

4-
VERSION=$(cat package.json | jq -r '.version')
5-
NAME=$(cat package.json | jq -r '.name')
4+
VERSION=$(jq -r '.version' package.json)
5+
NAME=$(jq -r '.name' package.json)
6+
TAG="v${VERSION}"
67

7-
test -z "$(npm info $NAME@$VERSION)"
8-
if [ $? -eq 0 ]; then
9-
set -e
8+
echo "Checking npm registry for ${NAME}@${VERSION}..."
109

11-
git config --global user.email "ci@dydx.exchange"
12-
git config --global user.name "github_actions"
10+
set +e
11+
VIEW_OUTPUT=$(npm view "${NAME}@${VERSION}" 2>&1)
12+
VIEW_EXIT=$?
13+
set -e
1314

14-
# Get version and tag
15-
git tag v4-client-js@${VERSION}
16-
git push --tags
15+
if [ $VIEW_EXIT -eq 0 ]; then
16+
echo "Skipping publish: ${NAME}@${VERSION} already exists"
17+
exit 0
18+
fi
19+
20+
if ! echo "$VIEW_OUTPUT" | grep -qiE 'E404|not found|No matching version'; then
21+
echo "Registry check failed unexpectedly:"
22+
echo "$VIEW_OUTPUT"
23+
exit 1
24+
fi
1725

18-
npm publish
26+
echo "Version not found. Proceeding with release."
27+
28+
git fetch --tags --quiet
29+
git config user.email "ci@dydx.exchange"
30+
git config user.name "github_actions"
31+
32+
if git show-ref --tags --verify --quiet "refs/tags/$TAG"; then
33+
echo "Tag $TAG already exists"
1934
else
20-
echo "skipping publish, package $NAME@$VERSION already published"
35+
git tag -a "$TAG" -m "Release $TAG"
36+
git push origin "$TAG"
2137
fi
38+
39+
unset NODE_AUTH_TOKEN
40+
npm publish --provenance --access public

0 commit comments

Comments
 (0)