From fe99aacc2258d50176d6eb77266b9f72ac5db14f Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 9 Mar 2022 16:48:15 -0700 Subject: [PATCH 01/10] feat(npm): use DEV_PACKAGE_NAME for development --- ci/steps/publish-npm.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 7ba3a0f97d2f..aedd174c5bfe 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -112,9 +112,15 @@ 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" + DEV_PACKAGE_NAME="@coder/code-server-pr" # This means the npm version will be tagged with "" # and installed when a user runs `yarn install code-server@` NPM_TAG="$PR_NUMBER" + # Use the development package name + # This is so we don't clutter the code-server versions on npm + # with development versions. + # NOTE: Requires npm Version 7.x or higher + npm pkg set name="$DEV_PACKAGE_NAME" fi echo "using tag: $NPM_TAG" From e207f5a512bd3d1ba5f8a65ea8727a77f5f117db Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 9 Mar 2022 16:48:46 -0700 Subject: [PATCH 02/10] feat(ci): use npm v7 in npm job --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 54381c20b4e6..7ade8b775fe8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -205,6 +205,8 @@ jobs: name: "npm-package" path: release-npm-package + # TODO@jsjoeio - we need to make sure we're using + # v7 or higher of the npm CLI - name: Run ./ci/steps/publish-npm.sh run: yarn publish:npm env: From 826a9b0070d470a52a9f8ff7cd03ef79e9b2cb44 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 11 Mar 2022 13:04:36 -0700 Subject: [PATCH 03/10] fixup: add npm version --- .github/workflows/ci.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7ade8b775fe8..340b32166232 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -205,8 +205,15 @@ jobs: name: "npm-package" path: release-npm-package - # TODO@jsjoeio - we need to make sure we're using - # v7 or higher of the npm CLI + # 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: From 02f1c56b41cec2005f8a3679862de8cac651108a Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 11 Mar 2022 16:58:58 -0700 Subject: [PATCH 04/10] fixup: always set package name --- ci/steps/publish-npm.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index aedd174c5bfe..a6f2a5b19a57 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -85,6 +85,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". @@ -112,15 +115,10 @@ 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" - DEV_PACKAGE_NAME="@coder/code-server-pr" + PACKAGE_NAME="@coder/code-server-pr" # This means the npm version will be tagged with "" # and installed when a user runs `yarn install code-server@` NPM_TAG="$PR_NUMBER" - # Use the development package name - # This is so we don't clutter the code-server versions on npm - # with development versions. - # NOTE: Requires npm Version 7.x or higher - npm pkg set name="$DEV_PACKAGE_NAME" fi echo "using tag: $NPM_TAG" @@ -131,9 +129,15 @@ main() { # 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 From 752cca620d306415329159abf16cb76f69c712a6 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 11 Mar 2022 17:03:59 -0700 Subject: [PATCH 05/10] wip --- .github/workflows/npm-brew.yaml | 9 +++++++++ ci/steps/publish-npm.sh | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/.github/workflows/npm-brew.yaml b/.github/workflows/npm-brew.yaml index 8c8b84fe2c38..ba2cd392423d 100644 --- a/.github/workflows/npm-brew.yaml +++ b/.github/workflows/npm-brew.yaml @@ -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: diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index a6f2a5b19a57..89f9ea4fc6f6 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -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 @@ -122,6 +131,7 @@ main() { 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 From f15d2d556ec479f2523e4c2991a703a58596391c Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 14 Mar 2022 16:32:10 -0700 Subject: [PATCH 06/10] fix: check for npm and npm v7 --- ci/steps/publish-npm.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 89f9ea4fc6f6..4de97922ea43 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -54,11 +54,24 @@ main() { # 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 "Couldn't find the npm CLI" + echo "Are you sure you have it installed?" + echo "Please check again with: npm -v" + echo "And re-run the script." + exit 1 + fi + + # NOTE@jsjoeio - this needs to run inside the release dir + # where the package.json for code-server is. + pushd release + if npm pkg get name && [ $? -eq 1 ]; then + echo "Couldn't get package.json name with 'npm pkg get name'" + echo "This usually means 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." + echo "Please upgrade to npm v7 or higher and re-run the script." exit 1 fi + popd # This allows us to publish to npm in CI workflows if [[ ${CI-} ]]; then @@ -161,7 +174,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 "$@" From cac1114d943cf88e8d324ac383fcf6623fee3e81 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 14 Mar 2022 16:34:14 -0700 Subject: [PATCH 07/10] fixup --- ci/steps/publish-npm.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 4de97922ea43..6d9fe1518d20 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -51,7 +51,6 @@ 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 "Couldn't find the npm CLI" From f88b1a6a7628b3c9b21e5effd2efe6d4ea7dad24 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 14 Mar 2022 16:47:35 -0700 Subject: [PATCH 08/10] fixup: move after release dir created --- ci/steps/publish-npm.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 6d9fe1518d20..29befaa373c7 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -60,18 +60,6 @@ main() { exit 1 fi - # NOTE@jsjoeio - this needs to run inside the release dir - # where the package.json for code-server is. - pushd release - if npm pkg get name && [ $? -eq 1 ]; then - echo "Couldn't get package.json name with 'npm pkg get name'" - echo "This usually means npm v7 or higher could not be found." - echo "We use this to modify the package.json name for dev builds." - echo "Please upgrade to npm v7 or higher and re-run the script." - exit 1 - fi - popd - # This allows us to publish to npm in CI workflows if [[ ${CI-} ]]; then echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc @@ -106,6 +94,19 @@ main() { # Ignore symlink when publishing npm package # See: https://github.com/coder/code-server/pull/3935 echo "node_modules.asar" > release/.npmignore + + # NOTE@jsjoeio - this needs to run inside the release dir + # where the package.json for code-server is. + pushd release + if npm pkg get name && [ $? -eq 1 ]; then + echo "Couldn't get package.json name with 'npm pkg get name'" + echo "This usually means npm v7 or higher could not be found." + echo "We use this to modify the package.json name for dev builds." + echo "Please upgrade to npm v7 or higher and re-run the script." + exit 1 + fi + popd + # We use this to set the name of the package in the # package.json PACKAGE_NAME="code-server" From 85a79876cb4494a4ca4a3da6ce30ac47aa8e32a4 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 15 Mar 2022 15:58:23 -0700 Subject: [PATCH 09/10] fixup: use jq --- .github/workflows/ci.yaml | 9 --------- .github/workflows/npm-brew.yaml | 9 --------- ci/steps/publish-npm.sh | 24 +++++------------------- 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ce70a0074537..9b7450d23b4f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -203,15 +203,6 @@ 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: diff --git a/.github/workflows/npm-brew.yaml b/.github/workflows/npm-brew.yaml index ba2cd392423d..8c8b84fe2c38 100644 --- a/.github/workflows/npm-brew.yaml +++ b/.github/workflows/npm-brew.yaml @@ -29,15 +29,6 @@ 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: diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 29befaa373c7..d8ce1eeec6a3 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -52,11 +52,9 @@ main() { fi # Check that we're using at least v7 of npm CLI - if ! command -v npm &> /dev/null; then - echo "Couldn't find the npm CLI" - echo "Are you sure you have it installed?" - echo "Please check again with: npm -v" - echo "And re-run the script." + 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 @@ -95,18 +93,6 @@ main() { # See: https://github.com/coder/code-server/pull/3935 echo "node_modules.asar" > release/.npmignore - # NOTE@jsjoeio - this needs to run inside the release dir - # where the package.json for code-server is. - pushd release - if npm pkg get name && [ $? -eq 1 ]; then - echo "Couldn't get package.json name with 'npm pkg get name'" - echo "This usually means npm v7 or higher could not be found." - echo "We use this to modify the package.json name for dev builds." - echo "Please upgrade to npm v7 or higher and re-run the script." - exit 1 - fi - popd - # We use this to set the name of the package in the # package.json PACKAGE_NAME="code-server" @@ -159,8 +145,8 @@ main() { # 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" + updated_package_json="$(jq '.name = "$PACKAGE_NAME"' package.json)" + echo -E "${updated_package_json}" > package.json popd fi From c2c78456d0cedb029e7dc4a772b82f25a22ddde1 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 15 Mar 2022 16:19:32 -0700 Subject: [PATCH 10/10] fixup: use jq correctly --- ci/steps/publish-npm.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index d8ce1eeec6a3..b2d87e51e04c 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -145,8 +145,7 @@ main() { # Use the development package name # This is so we don't clutter the code-server versions on npm # with development versions. - updated_package_json="$(jq '.name = "$PACKAGE_NAME"' package.json)" - echo -E "${updated_package_json}" > package.json + jq ".name |= \"$PACKAGE_NAME\"" package.json popd fi