From 32d300a09464654de83742b784e06f55f49d6560 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 9 Jul 2024 11:17:07 -0400 Subject: [PATCH 1/2] Only show packages in the dry run that need publishing (#90) * only show packages in the dry run that need publishing * address shellcheck nits * test * add PUBLISH_NPM_TAG to test-monorepo * only `set -e` if `$ACTIONS_RUNNER_DEBUG` is set * wrap `set -x` instead --- .github/workflows/test-monorepo.yml | 2 +- scripts/main.sh | 4 +++- scripts/publish.sh | 15 +++++++++++---- 3 files changed, 15 insertions(+), 6 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/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 58a76c3..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 @@ -24,7 +23,8 @@ else fi fi -if [[ -z $YARN_NPM_AUTH_TOKEN ]]; then +# "dry-run" for polyrepo +if [[ -z "$YARN_NPM_AUTH_TOKEN" && -z "$1" ]]; then echo "Notice: 'npm-token' not set. Running '$PACK_CMD'." $INSTALL_CMD $PACK_CMD @@ -51,6 +51,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 @@ -59,4 +66,4 @@ fi $INSTALL_CMD $PUBLISH_CMD -rm -f $HOME/.npmrc +rm -f "$HOME/.npmrc" From 4d330a9888270bfd567aa555b7df100976407636 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 11 Jul 2024 12:52:33 +0200 Subject: [PATCH 2/2] Fix report script for unpublished packages (#93) * Fix report script for unpublished packages * Simplify --- scripts/report.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/report.sh b/scripts/report.sh index a9f8d64..47ba151 100755 --- a/scripts/report.sh +++ b/scripts/report.sh @@ -15,6 +15,6 @@ for file in "$directory"/*.tgz; do pkdiff "$name@latest" "$file" \ --no-exit-code \ --no-open \ - --output "$directory/$basename.html" + --output "$directory/$basename.html" || true fi done