feat(ci): publish dev builds to @coder/code-server-pr (#4972)

* feat(npm): use DEV_PACKAGE_NAME for development

* feat(ci): use npm v7 in npm job

* fixup: add npm version

* fixup: always set package name

* wip

* fix: check for npm and npm v7

* fixup

* fixup: move after release dir created

* fixup: use jq

* fixup: use jq correctly
This commit is contained in:
Joe Previte 2022-03-15 16:59:40 -07:00 committed by GitHub
parent d22f312cab
commit a0561c7685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 2 deletions

View File

@ -51,6 +51,13 @@ main() {
exit 1 exit 1
fi fi
# Check that we're using at least v7 of npm CLI
if ! command -v jq &> /dev/null; then
echo "Couldn't find jq"
echo "We need this in order to modify the package.json for dev builds."
exit 1
fi
# This allows us to publish to npm in CI workflows # This allows us to publish to npm in CI workflows
if [[ ${CI-} ]]; then if [[ ${CI-} ]]; then
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
@ -86,6 +93,10 @@ main() {
# See: https://github.com/coder/code-server/pull/3935 # See: https://github.com/coder/code-server/pull/3935
echo "node_modules.asar" > release/.npmignore echo "node_modules.asar" > release/.npmignore
# We use this to set the name of the package in the
# package.json
PACKAGE_NAME="code-server"
# NOTES:@jsjoeio # NOTES:@jsjoeio
# We only need to run npm version for "development" and "staging". # We only need to run npm version for "development" and "staging".
# This is because our release:prep script automatically bumps the version # This is because our release:prep script automatically bumps the version
@ -112,12 +123,14 @@ main() {
# Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550 # Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550
PR_NUMBER=$(echo "$GITHUB_REF" | awk 'BEGIN { FS = "/" } ; { print $3 }') PR_NUMBER=$(echo "$GITHUB_REF" | awk 'BEGIN { FS = "/" } ; { print $3 }')
NPM_VERSION="$VERSION-$PR_NUMBER-$COMMIT_SHA" NPM_VERSION="$VERSION-$PR_NUMBER-$COMMIT_SHA"
PACKAGE_NAME="@coder/code-server-pr"
# This means the npm version will be tagged with "<pr number>" # This means the npm version will be tagged with "<pr number>"
# and installed when a user runs `yarn install code-server@<pr number>` # and installed when a user runs `yarn install code-server@<pr number>`
NPM_TAG="$PR_NUMBER" NPM_TAG="$PR_NUMBER"
fi fi
echo "using tag: $NPM_TAG" echo "using tag: $NPM_TAG"
echo "using package name: $PACKAGE_NAME"
# 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
@ -125,9 +138,14 @@ main() {
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040" # Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
# Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040" # Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040"
pushd release pushd release
# NOTE:@jsjoeio # NOTE@jsjoeio
# I originally tried to use `yarn version` but ran into issues and abandoned it. # I originally tried to use `yarn version` but ran into issues and abandoned it.
npm version "$NPM_VERSION" npm version "$NPM_VERSION"
# NOTE@jsjoeio
# Use the development package name
# This is so we don't clutter the code-server versions on npm
# with development versions.
jq ".name |= \"$PACKAGE_NAME\"" package.json
popd popd
fi fi
@ -141,7 +159,10 @@ main() {
return return
fi fi
yarn publish --non-interactive release --tag "$NPM_TAG" # NOTE@jsjoeio
# Since the dev builds are scoped to @coder
# We pass --access public to ensure npm knows it's not private.
yarn publish --non-interactive release --tag "$NPM_TAG" --access public
} }
main "$@" main "$@"