From d664aba2637ed24d90dfab966e21c0d76086dc84 Mon Sep 17 00:00:00 2001 From: Zach Butler Date: Thu, 1 Aug 2024 21:03:02 -0400 Subject: [PATCH] Move npm publish step into build script, but only for newest supported node version in the cloud --- .github/workflows/ci.yml | 11 ++++------- scripts/build.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c139b5d..34ebb03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,17 +33,14 @@ jobs: - name: Test - node v${{ matrix.node-version }} run: yarn test - - name: Package - node v${{ matrix.node-version }} + - name: Build - node v${{ matrix.node-version }} run: yarn build + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }} + NODE_MAJOR_VERSION: ${{ matrix.node-version }} - name: Upload Artifacts uses: actions/upload-artifact@v4 with: name: kj4ezj-is-${{ matrix.node-version }} path: kj4ezj-is-*.tgz - - - name: Publish to NPM - run: npm publish --provenance --access public - if: startsWith(github.ref, 'refs/tags/') - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }} diff --git a/scripts/build.sh b/scripts/build.sh index 472f96e..06c158d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -87,6 +87,18 @@ if [[ "$CI" == 'true' ]]; then echo 'Validating package can be installed...' ee 'npm install -g kj4ezj-is-*.tgz' fi +# publish +echo 'Publishing...' +if [[ -z "$GIT_TAG" ]]; then + printf '\e[1;33mNOTICE: Not a tagged build, no software will be published.\e[0m\n' +elif [[ "$CI" != 'true' || -n "$ACT" ]]; then + printf '\e[1;33mNOTICE: Skipping publish step for local build.\e[0m\n' +elif [[ "$NODE_MAJOR_VERSION" != "$(cat .nvmrc | tr -d '[:space:]')" ]]; then + printf '\e[1;33mNOTICE: Skipping publish step for older Node.js matrix job.\e[0m\n' +else + ee 'npm publish --provenance --access public' + printf '\e[1;32mPublished to npm!\e[0m\n' +fi # clean up ee mv package.json.$UNIX_TIME.bak package.json popd