Skip to content

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

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 14 commits into from
Mar 15, 2022
25 changes: 23 additions & 2 deletions ci/steps/publish-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ main() {
exit 1
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
if [[ ${CI-} ]]; then
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
Expand Down Expand Up @@ -86,6 +93,10 @@ main() {
# See: https://github.com/coder/code-server/pull/3935
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
# We only need to run npm version for "development" and "staging".
# This is because our release:prep script automatically bumps the version
Expand All @@ -112,22 +123,29 @@ main() {
# Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550
PR_NUMBER=$(echo "$GITHUB_REF" | awk 'BEGIN { FS = "/" } ; { print $3 }')
NPM_VERSION="$VERSION-$PR_NUMBER-$COMMIT_SHA"
PACKAGE_NAME="@coder/code-server-pr"
# This means the npm version will be tagged with "<pr number>"
# and installed when a user runs `yarn install code-server@<pr number>`
NPM_TAG="$PR_NUMBER"
fi

echo "using tag: $NPM_TAG"
echo "using package name: $PACKAGE_NAME"

# We modify the version in the package.json
# to be the current version + the PR number + commit SHA
# or we use current version + beta + commit SHA
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
# Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040"
pushd release
# NOTE:@jsjoeio
# NOTE@jsjoeio
# I originally tried to use `yarn version` but ran into issues and abandoned it.
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
fi

Expand All @@ -141,7 +159,10 @@ main() {
return
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 "$@"