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
Merged
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ jobs:
name: "npm-package"
path: release-npm-package

# NOTE@jsjoeio - we need to make sure we're using
# v7 or higher of the npm CLI because it's used
# in the yarn publish:npm script in development builds
# to modify package.json name.
- name: Install Node & npm v8
uses: actions/setup-node@v3
with:
node-version: "16.14.0"

- name: Run ./ci/steps/publish-npm.sh
run: yarn publish:npm
env:
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/npm-brew.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
name: "npm-package"
path: release-npm-package

# NOTE@jsjoeio - we need to make sure we're using
# v7 or higher of the npm CLI because it's used
# in the yarn publish:npm script in development builds
# to modify package.json name.
- name: Install Node & npm v8
uses: actions/setup-node@v3
with:
node-version: "16.14.0"

- name: Publish npm package and tag with "latest"
run: yarn publish:npm
env:
Expand Down
22 changes: 21 additions & 1 deletion ci/steps/publish-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ main() {
exit 1
fi

# TODO@jsjoeio
# Check that we're using at least v7 of npm CLI
if ! command -v npm &> /dev/null; then
echo "npm v7 or higher could not be found."
echo "We use this to modify the package.json name for dev builds."
echo "Please upgrade and re-run the script."
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 @@ -85,6 +94,9 @@ main() {
# Ignore symlink when publishing npm package
# 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".
Expand Down Expand Up @@ -112,22 +124,30 @@ 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.
# Requires npm Version 7.x or higher
npm pkg set name="$PACKAGE_NAME"
popd
fi

Expand Down