-
-
Notifications
You must be signed in to change notification settings - Fork 24
Added npm publish workflow for both sdks #53
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| name: NPM Publish | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| paths: | ||
| - 'djed-sdk/package.json' | ||
| - 'stablepay-sdk/package.json' | ||
|
|
||
| jobs: | ||
| publish-djed-sdk: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| defaults: | ||
| run: | ||
| working-directory: ./djed-sdk | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Check version change | ||
| id: check | ||
| run: | | ||
| PACKAGE_NAME=$(node -p "require('./package.json').name") | ||
| LOCAL_VERSION=$(node -p "require('./package.json').version") | ||
|
|
||
| echo "Checking registry for $PACKAGE_NAME..." | ||
|
|
||
| # Retry loop for npm view to handle network flakes | ||
| PUBLISHED_VERSION="" | ||
| for i in {1..3}; do | ||
| if OUTPUT=$(npm view "$PACKAGE_NAME" version 2>/dev/null); then | ||
| PUBLISHED_VERSION=$OUTPUT | ||
| break | ||
| else | ||
| # Check if it's a 404 (package doesn't exist) | ||
| if npm view "$PACKAGE_NAME" version 2>&1 | grep -q "E404"; then | ||
| echo "Package not found on registry. Assuming new package." | ||
| PUBLISHED_VERSION="0.0.0" | ||
| break | ||
| fi | ||
|
|
||
| if [ $i -lt 3 ]; then | ||
| echo "Attempt $i failed. Retrying in 5 seconds..." | ||
| sleep 5 | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| if [ -z "$PUBLISHED_VERSION" ]; then | ||
| echo "Failed to retrieve published version after 3 attempts. Assuming 0.0.0 to err on side of attempting publish." | ||
| PUBLISHED_VERSION="0.0.0" | ||
| fi | ||
|
|
||
| echo "Local version: $LOCAL_VERSION" | ||
| echo "Published version: $PUBLISHED_VERSION" | ||
|
|
||
| if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then | ||
| echo "Version changed." | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Version unchanged." | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
Comment on lines
+67
to
+73
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. Publish gate should require a version increase, not just inequality. On Line 67 and Line 169, 🔧 Proposed fix- if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then
- echo "Version changed."
+ if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ] && \
+ [ "$(printf '%s\n' "$PUBLISHED_VERSION" "$LOCAL_VERSION" | sort -V | tail -n1)" = "$LOCAL_VERSION" ]; then
+ echo "Version increased."
echo "changed=true" >> "$GITHUB_OUTPUT"
else
- echo "Version unchanged."
+ echo "Version not increased."
echo "changed=false" >> "$GITHUB_OUTPUT"
fiApply the same update to both Also applies to: 169-175 🤖 Prompt for AI Agents |
||
|
|
||
| - name: Install dependencies | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: | | ||
| SUCCESS=false | ||
| for i in {1..3}; do | ||
| if npm ci; then | ||
| SUCCESS=true | ||
| break | ||
| else | ||
| echo "Install failed, retrying in 10 seconds..." | ||
| sleep 10 | ||
| fi | ||
| done | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [ "$SUCCESS" != "true" ]; then | ||
| echo "Failed to install dependencies after 3 attempts" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Build | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: npm run build | ||
|
|
||
| - name: Publish to NPM | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: | | ||
| SUCCESS=false | ||
| for i in {1..3}; do | ||
| if npm publish; then | ||
| SUCCESS=true | ||
| break | ||
| else | ||
| echo "Publish failed, retrying in 10 seconds..." | ||
| sleep 10 | ||
| fi | ||
| done | ||
| if [ "$SUCCESS" != "true" ]; then | ||
| echo "Failed to publish after 3 attempts" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| publish-stablepay-sdk: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| defaults: | ||
| run: | ||
| working-directory: ./stablepay-sdk | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Check version change | ||
| id: check | ||
| run: | | ||
| PACKAGE_NAME=$(node -p "require('./package.json').name") | ||
| LOCAL_VERSION=$(node -p "require('./package.json').version") | ||
|
|
||
| echo "Checking registry for $PACKAGE_NAME..." | ||
|
|
||
| PUBLISHED_VERSION="" | ||
| for i in {1..3}; do | ||
| if OUTPUT=$(npm view "$PACKAGE_NAME" version 2>/dev/null); then | ||
| PUBLISHED_VERSION=$OUTPUT | ||
| break | ||
| else | ||
| if npm view "$PACKAGE_NAME" version 2>&1 | grep -q "E404"; then | ||
| echo "Package not found on registry. Assuming new package." | ||
| PUBLISHED_VERSION="0.0.0" | ||
| break | ||
| fi | ||
|
|
||
| if [ $i -lt 3 ]; then | ||
| echo "Attempt $i failed. Retrying in 5 seconds..." | ||
| sleep 5 | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| if [ -z "$PUBLISHED_VERSION" ]; then | ||
| echo "Failed to retrieve published version after 3 attempts. Assuming 0.0.0 to err on side of attempting publish." | ||
| PUBLISHED_VERSION="0.0.0" | ||
| fi | ||
|
|
||
| echo "Local version: $LOCAL_VERSION" | ||
| echo "Published version: $PUBLISHED_VERSION" | ||
|
|
||
| if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then | ||
| echo "Version changed." | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Version unchanged." | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Install dependencies | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: | | ||
| SUCCESS=false | ||
| for i in {1..3}; do | ||
| if npm ci; then | ||
| SUCCESS=true | ||
| break | ||
| else | ||
| echo "Install failed, retrying in 10 seconds..." | ||
| sleep 10 | ||
| fi | ||
| done | ||
| if [ "$SUCCESS" != "true" ]; then | ||
| echo "Failed to install dependencies after 3 attempts" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Build | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: npm run build | ||
|
|
||
| - name: Publish to NPM | ||
| if: steps.check.outputs.changed == 'true' | ||
| run: | | ||
| SUCCESS=false | ||
| for i in {1..3}; do | ||
| if npm publish; then | ||
| SUCCESS=true | ||
| break | ||
| else | ||
| echo "Publish failed, retrying in 10 seconds..." | ||
| sleep 10 | ||
| fi | ||
| done | ||
| if [ "$SUCCESS" != "true" ]; then | ||
| echo "Failed to publish after 3 attempts" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
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.
Drop unused
id-token: writepermission (least privilege).id-token: writeis not used by any step here (no OIDC/provenance flow), so this grants unnecessary privilege in both jobs.🔧 Proposed fix
permissions: contents: read - id-token: writeAlso applies to: 123-125
🤖 Prompt for AI Agents