Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show packages in the dry run that need publishing #90

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
rickycodes marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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
rickycodes marked this conversation as resolved.
Show resolved Hide resolved
echo "Notice: 'npm-token' not set. Running '$PACK_CMD'."
$INSTALL_CMD
$PACK_CMD
Expand All @@ -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 "")
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved

# "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
Expand All @@ -59,4 +66,4 @@ fi

$INSTALL_CMD
$PUBLISH_CMD
rm -f $HOME/.npmrc
rm -f "$HOME/.npmrc"
Loading