mirror of https://github.com/coder/code-server.git
chore: fix npm publish logic (#5493)
* chore: clean up logging in npm script * fix: catch error if npm version missing npm changed the way the `npm view` command handles missing versions. Before it exited with a non-error. Now it errors. Ref: https://github.com/npm/cli/pull/5035 This modifies the script logic to handle those new changes.
This commit is contained in:
parent
ccbf0bebb7
commit
d1acfad2a8
|
@ -65,7 +65,8 @@ main() {
|
||||||
# "production" - this means we tag with `latest` (default), allowing
|
# "production" - this means we tag with `latest` (default), allowing
|
||||||
# a developer to install this version with `yarn add code-server@latest`
|
# a developer to install this version with `yarn add code-server@latest`
|
||||||
if ! is_env_var_set "NPM_ENVIRONMENT"; then
|
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
|
if [[ "$GITHUB_EVENT_NAME" == 'push' && "$GITHUB_REF" == 'refs/heads/main' ]]; then
|
||||||
NPM_ENVIRONMENT="staging"
|
NPM_ENVIRONMENT="staging"
|
||||||
|
@ -73,7 +74,6 @@ main() {
|
||||||
NPM_ENVIRONMENT="development"
|
NPM_ENVIRONMENT="development"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Using npm environment: $NPM_ENVIRONMENT"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
|
# NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
|
||||||
|
@ -96,9 +96,6 @@ main() {
|
||||||
NPM_TAG="latest"
|
NPM_TAG="latest"
|
||||||
else
|
else
|
||||||
COMMIT_SHA="$GITHUB_SHA"
|
COMMIT_SHA="$GITHUB_SHA"
|
||||||
echo "Not a production environment"
|
|
||||||
echo "Found environment: $NPM_ENVIRONMENT"
|
|
||||||
echo "Manually bumping npm version..."
|
|
||||||
|
|
||||||
if [[ "$NPM_ENVIRONMENT" == "staging" ]]; then
|
if [[ "$NPM_ENVIRONMENT" == "staging" ]]; then
|
||||||
NPM_VERSION="$VERSION-beta-$COMMIT_SHA"
|
NPM_VERSION="$VERSION-beta-$COMMIT_SHA"
|
||||||
|
@ -117,8 +114,10 @@ main() {
|
||||||
NPM_TAG="$PR_NUMBER"
|
NPM_TAG="$PR_NUMBER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "using tag: $NPM_TAG"
|
echo "- tag: $NPM_TAG"
|
||||||
echo "using package name: $PACKAGE_NAME"
|
echo "- version: $NPM_VERSION"
|
||||||
|
echo "- package name: $PACKAGE_NAME"
|
||||||
|
echo "- npm environment: $NPM_ENVIRONMENT"
|
||||||
|
|
||||||
# We modify the version in the package.json
|
# We modify the version in the package.json
|
||||||
# to be the current version + the PR number + commit SHA
|
# to be the current version + the PR number + commit SHA
|
||||||
|
@ -140,13 +139,13 @@ main() {
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# NOTE@jsjoeio
|
||||||
# We need to make sure we haven't already published the version.
|
# 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
|
# If we get error, continue with script because we want to publish
|
||||||
# to check the output.
|
# If version is valid, we check if we're publishing the same one
|
||||||
local hasVersion
|
local hasVersion
|
||||||
hasVersion=$(npm view "code-server@$NPM_VERSION" version)
|
if hasVersion=$(npm view "$PACKAGE_NAME@$NPM_VERSION" version 2> /dev/null) && [[ $hasVersion == "$NPM_VERSION" ]]; then
|
||||||
if [[ $hasVersion == "$NPM_VERSION" ]]; then
|
echo "$NPM_VERSION is already published under $PACKAGE_NAME"
|
||||||
echo "$NPM_VERSION is already published"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue