@@ -408,6 +408,40 @@ jobs:
408408 name : bindings-universal-apple-darwin
409409 path : ${{ env.APP_NAME }}.*.node
410410 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+
411445 publish :
412446 name : Publish
413447 runs-on : ubuntu-latest
@@ -419,6 +453,11 @@ jobs:
419453 - test-linux-aarch64-musl-binding
420454 - test-linux-arm-gnueabihf-binding
421455 - universal-macOS
456+ - need-publish
457+ if : needs.need-publish.outputs.ABORT != 'true'
458+ env :
459+ CURRENT_VERSION : ' '
460+ PUBLISH_PARAMS : ' '
422461 steps :
423462 - name : Checkout
424463 uses : actions/checkout@v4
@@ -442,20 +481,52 @@ jobs:
442481 - name : List packages
443482 run : ls -R ./npm
444483 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+ # Get commit message
491+ - name : Get commit message
446492 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
493+ COMMIT_MESSAGE=$(git log --format=%s -n 1)
494+ echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
495+
496+ # Get & check npm publish
497+ - name : Get publish params
498+ run : |
499+ PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-`
500+ echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV
501+ echo "Publish pushing provide parameter [$PUBLISH_PARAMS]."
502+
503+ # Define ${CURRENT_VERSION}
504+ - name : Set Current Version
505+ shell : bash -ex {0}
506+ run : |
507+ CURRENT_VERSION=$(node -p 'require("./package.json").version')
508+ echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
509+
510+ # Check git tag
511+ - name : Tag Check
512+ id : tag_check
513+ shell : bash -ex {0}
514+ run : |
515+ GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${CURRENT_VERSION}"
516+ http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
517+ -H "Authorization: token ${GITHUB_TOKEN}")
518+ if [ "$http_status_code" -ne "404" ] ; then
519+ echo "::set-output name=exists_tag::true"
456520 else
457- echo "Not a release, skipping publish "
521+ echo "::set-output name=exists_tag::false "
458522 fi
459523 env :
460524 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
525+
526+ - name : Publish
527+ run : |
528+ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
529+ npm publish --registry=https://registry.npmjs.org/ $PUBLISH_PARAMS
530+ env :
531+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
461532 NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments