From 70d4ceb16c1639b5a9f2c4dcfd847e8d0cc528e6 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Mon, 24 Jun 2024 09:36:59 -0400 Subject: [PATCH 1/6] only show packages in the dry run that need publishing --- scripts/publish.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 58a76c3..99046a1 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -24,7 +24,8 @@ else fi fi -if [[ -z $YARN_NPM_AUTH_TOKEN ]]; then +# "dry-run" for polyrepo +if [[ -z $YARN_NPM_AUTH_TOKEN && ! -n "$1" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $INSTALL_CMD $PACK_CMD @@ -51,6 +52,13 @@ if [[ -n "$1" ]]; then PACKAGE_NAME=$(jq --raw-output .name package.json) LATEST_PACKAGE_VERSION=$(npm view "$PACKAGE_NAME" dist-tags --workspaces false --json | jq --raw-output --arg tag "$PUBLISH_NPM_TAG" '.[$tag]' || echo "") + # "dry-run" for monorepo + if [ -z $YARN_NPM_AUTH_TOKEN && ! "$LATEST_PACKAGE_VERSION" = "$CURRENT_PACKAGE_VERSION" ]; then + echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." + $PACK_CMD + exit 0 + fi + if [ "$LATEST_PACKAGE_VERSION" = "$CURRENT_PACKAGE_VERSION" ]; then echo "Notice: This module is already published at $CURRENT_PACKAGE_VERSION. aborting publish." exit 0 From c1f50496da49d13b65e12356422aa5d3d8dc7d0e Mon Sep 17 00:00:00 2001 From: rickycodes Date: Mon, 24 Jun 2024 09:43:24 -0400 Subject: [PATCH 2/6] address shellcheck nits --- scripts/publish.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 99046a1..81d7e6d 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -11,10 +11,9 @@ if [[ "$YARN_MAJOR" -ge "3" ]]; then PACK_CMD="yarn pack --out /tmp/%s-%v.tgz" # install is handled by yarn berry pack/publish INSTALL_CMD="" - LOGIN_CMD="" else echo "Warning: Did not detect compatible yarn version. This action officially supports Yarn v3 and newer. Falling back to using npm." >&2 - echo "//registry.npmjs.org/:_authToken=${YARN_NPM_AUTH_TOKEN}" >> $HOME/.npmrc + echo "//registry.npmjs.org/:_authToken=${YARN_NPM_AUTH_TOKEN}" >> "$HOME/.npmrc" PUBLISH_CMD="npm publish --tag $PUBLISH_NPM_TAG" PACK_CMD="npm pack --pack-destination=/tmp/" if [[ -f 'yarn.lock' ]]; then @@ -25,7 +24,7 @@ else fi # "dry-run" for polyrepo -if [[ -z $YARN_NPM_AUTH_TOKEN && ! -n "$1" ]]; then +if [[ -z "$YARN_NPM_AUTH_TOKEN" && -z "$1" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $INSTALL_CMD $PACK_CMD @@ -53,7 +52,7 @@ if [[ -n "$1" ]]; then LATEST_PACKAGE_VERSION=$(npm view "$PACKAGE_NAME" dist-tags --workspaces false --json | jq --raw-output --arg tag "$PUBLISH_NPM_TAG" '.[$tag]' || echo "") # "dry-run" for monorepo - if [ -z $YARN_NPM_AUTH_TOKEN && ! "$LATEST_PACKAGE_VERSION" = "$CURRENT_PACKAGE_VERSION" ]; then + if [[ -z "$YARN_NPM_AUTH_TOKEN" && ! "$LATEST_PACKAGE_VERSION" = "$CURRENT_PACKAGE_VERSION" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $PACK_CMD exit 0 @@ -67,4 +66,4 @@ fi $INSTALL_CMD $PUBLISH_CMD -rm -f $HOME/.npmrc +rm -f "$HOME/.npmrc" From bfdde894700e590b37d706d8a9aed27758bd9642 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Mon, 24 Jun 2024 10:35:33 -0400 Subject: [PATCH 3/6] test --- scripts/publish.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/publish.sh b/scripts/publish.sh index 81d7e6d..c6edde3 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -24,6 +24,7 @@ else fi # "dry-run" for polyrepo +echo "$1" if [[ -z "$YARN_NPM_AUTH_TOKEN" && -z "$1" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $INSTALL_CMD From e115348fee1f68a26cd55de3f7c7fa0beb20f526 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Mon, 24 Jun 2024 10:48:08 -0400 Subject: [PATCH 4/6] add PUBLISH_NPM_TAG to test-monorepo --- .github/workflows/test-monorepo.yml | 2 +- scripts/publish.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-monorepo.yml b/.github/workflows/test-monorepo.yml index 9799e9e..be35987 100644 --- a/.github/workflows/test-monorepo.yml +++ b/.github/workflows/test-monorepo.yml @@ -21,7 +21,7 @@ jobs: cd skunkworks yarn install --immutable yarn plugin import workspace-tools - ../action-npm-publish/scripts/main.sh + PUBLISH_NPM_TAG="latest" ../action-npm-publish/scripts/main.sh # test that publishing is skipped when attempting to republish the latest version checkout_publish_skunkworks_skip: runs-on: ubuntu-20.04 diff --git a/scripts/publish.sh b/scripts/publish.sh index c6edde3..81d7e6d 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -24,7 +24,6 @@ else fi # "dry-run" for polyrepo -echo "$1" if [[ -z "$YARN_NPM_AUTH_TOKEN" && -z "$1" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $INSTALL_CMD From b1df0ec5fbdd947a4f6569493b2f9d11d6d89b0e Mon Sep 17 00:00:00 2001 From: rickycodes Date: Fri, 28 Jun 2024 13:49:31 -0400 Subject: [PATCH 5/6] only `set -e` if `$ACTIONS_RUNNER_DEBUG` is set --- scripts/publish.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 81d7e6d..1919250 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -set -e +if [[ -z $ACTIONS_RUNNER_DEBUG ]]; then + set -e +fi set -o pipefail export YARN_NPM_AUTH_TOKEN="${YARN_NPM_AUTH_TOKEN:-$NPM_TOKEN}" From df6359275e92ffdf9ee5de293f8042c0441996b4 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Fri, 28 Jun 2024 20:15:14 -0400 Subject: [PATCH 6/6] wrap `set -x` instead --- scripts/main.sh | 4 +++- scripts/publish.sh | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/main.sh b/scripts/main.sh index 358d7a4..2081567 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -set -x +if [[ -z $ACTIONS_RUNNER_DEBUG ]]; then + set -x +fi set -e set -o pipefail diff --git a/scripts/publish.sh b/scripts/publish.sh index 1919250..81d7e6d 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash -if [[ -z $ACTIONS_RUNNER_DEBUG ]]; then - set -e -fi +set -e set -o pipefail export YARN_NPM_AUTH_TOKEN="${YARN_NPM_AUTH_TOKEN:-$NPM_TOKEN}"