@@ -408,6 +408,40 @@ jobs:
408
408
name : bindings-universal-apple-darwin
409
409
path : ${{ env.APP_NAME }}.*.node
410
410
if-no-files-found : error
411
+
412
+ need-publish :
413
+ permissions :
414
+ actions : write # to cancel running workflow (andymckay/cancel-action)
415
+ name : Need Publish
416
+ runs-on : ubuntu-latest
417
+ outputs :
418
+ ABORT : ${{ env.ABORT }}
419
+ env :
420
+ ABORT : false
421
+ COMMIT_MESSAGE : ' '
422
+ steps :
423
+ # Setup
424
+ - name : Checkout
425
+ uses : actions/checkout@v4
426
+
427
+ # Log meta
428
+ - name : GITHUB CONTEXT
429
+ env :
430
+ GITHUB_CONTEXT : ${{ toJson(github) }}
431
+ run : echo "$GITHUB_CONTEXT"
432
+
433
+ # Get commit message
434
+ - name : Get commit message
435
+ run : |
436
+ COMMIT_MESSAGE=$(git log --format=%s -n 1)
437
+ echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
438
+ - name : Show commit message
439
+ run : echo "$COMMIT_MESSAGE"
440
+
441
+ - name : Commit message compliance verification
442
+ if : startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) != true
443
+ run : echo "ABORT=true" >> $GITHUB_ENV
444
+
411
445
publish :
412
446
name : Publish
413
447
runs-on : ubuntu-latest
@@ -419,6 +453,11 @@ jobs:
419
453
- test-linux-aarch64-musl-binding
420
454
- test-linux-arm-gnueabihf-binding
421
455
- universal-macOS
456
+ - need-publish
457
+ if : needs.need-publish.outputs.ABORT != 'true'
458
+ env :
459
+ CURRENT_VERSION : ' '
460
+ PUBLISH_PARAMS : ' '
422
461
steps :
423
462
- name : Checkout
424
463
uses : actions/checkout@v4
@@ -442,20 +481,53 @@ jobs:
442
481
- name : List packages
443
482
run : ls -R ./npm
444
483
shell : bash
445
- - name : Publish
484
+
485
+ # Log meta
486
+ - name : GITHUB CONTEXT
487
+ env :
488
+ GITHUB_CONTEXT : ${{ toJson(github) }}
489
+ run : echo "$GITHUB_CONTEXT"
490
+
491
+ # Get commit message
492
+ - name : Get commit message
446
493
run : |
447
- npm config set provenance true
448
- if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
449
- then
450
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
451
- npm publish --access public
452
- elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
453
- then
454
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
455
- npm publish --tag next --access public
494
+ COMMIT_MESSAGE=$(git log --format=%s -n 1)
495
+ echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
496
+
497
+ # Get & check npm publish
498
+ - name : Get publish params
499
+ run : |
500
+ PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-`
501
+ echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV
502
+ echo "Publish pushing provide parameter [$PUBLISH_PARAMS]."
503
+
504
+ # Define ${CURRENT_VERSION}
505
+ - name : Set Current Version
506
+ shell : bash -ex {0}
507
+ run : |
508
+ CURRENT_VERSION=$(node -p 'require("./package.json").version')
509
+ echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
510
+
511
+ # Check git tag
512
+ - name : Tag Check
513
+ id : tag_check
514
+ shell : bash -ex {0}
515
+ run : |
516
+ GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${CURRENT_VERSION}"
517
+ http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
518
+ -H "Authorization: token ${GITHUB_TOKEN}")
519
+ if [ "$http_status_code" -ne "404" ] ; then
520
+ echo "::set-output name=exists_tag::true"
456
521
else
457
- echo "Not a release, skipping publish "
522
+ echo "::set-output name=exists_tag::false "
458
523
fi
459
524
env :
460
525
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
526
+
527
+ - name : Publish
528
+ run : |
529
+ npm config set provenance true
530
+ pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ github.ref_name }} -r ${{ env.PUBLISH_PARAMS }}
531
+ env :
532
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
461
533
NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments