Skip to content

chore: fix npm publish logic #5493

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

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Changes from all 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
23 changes: 11 additions & 12 deletions ci/steps/publish-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ main() {
# "production" - this means we tag with `latest` (default), allowing
# a developer to install this version with `yarn add code-server@latest`
if ! is_env_var_set "NPM_ENVIRONMENT"; then
echo "NPM_ENVIRONMENT is not set. Determining in script based on GITHUB environment variables."
echo "NPM_ENVIRONMENT is not set."
echo "Determining in script based on GITHUB environment variables."

if [[ "$GITHUB_EVENT_NAME" == 'push' && "$GITHUB_REF" == 'refs/heads/main' ]]; then
NPM_ENVIRONMENT="staging"
else
NPM_ENVIRONMENT="development"
fi

echo "Using npm environment: $NPM_ENVIRONMENT"
fi

# NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
Expand All @@ -96,9 +96,6 @@ main() {
NPM_TAG="latest"
else
COMMIT_SHA="$GITHUB_SHA"
echo "Not a production environment"
echo "Found environment: $NPM_ENVIRONMENT"
echo "Manually bumping npm version..."

if [[ "$NPM_ENVIRONMENT" == "staging" ]]; then
NPM_VERSION="$VERSION-beta-$COMMIT_SHA"
Expand All @@ -117,8 +114,10 @@ main() {
NPM_TAG="$PR_NUMBER"
fi

echo "using tag: $NPM_TAG"
echo "using package name: $PACKAGE_NAME"
echo "- tag: $NPM_TAG"
echo "- version: $NPM_VERSION"
echo "- package name: $PACKAGE_NAME"
echo "- npm environment: $NPM_ENVIRONMENT"

# We modify the version in the package.json
# to be the current version + the PR number + commit SHA
Expand All @@ -140,13 +139,13 @@ main() {
popd
fi

# NOTE@jsjoeio
# We need to make sure we haven't already published the version.
# This is because npm view won't exit with non-zero so we have
# to check the output.
# If we get error, continue with script because we want to publish
# If version is valid, we check if we're publishing the same one
local hasVersion
hasVersion=$(npm view "code-server@$NPM_VERSION" version)
if [[ $hasVersion == "$NPM_VERSION" ]]; then
echo "$NPM_VERSION is already published"
if hasVersion=$(npm view "$PACKAGE_NAME@$NPM_VERSION" version 2> /dev/null) && [[ $hasVersion == "$NPM_VERSION" ]]; then
echo "$NPM_VERSION is already published under $PACKAGE_NAME"
return
fi

Expand Down