Skip to content

Commit 6db1ac2

Browse files
authored
Merge branch 'main' into jsjoeio-hash-test
2 parents cd488fb + fd643dc commit 6db1ac2

File tree

5 files changed

+95
-88
lines changed

5 files changed

+95
-88
lines changed

.github/workflows/ci.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,33 @@ jobs:
177177
name: npm-package
178178
path: ./package.tar.gz
179179

180+
npm:
181+
# the npm-package gets uploaded as an artifact in Build
182+
# so we need that to complete before this runs
183+
needs: build
184+
# This environment "npm" requires someone from
185+
# coder/code-server-reviewers to approve the PR before this job runs.
186+
environment: npm
187+
runs-on: ubuntu-latest
188+
steps:
189+
- uses: actions/checkout@v2
190+
191+
- uses: actions/download-artifact@v2
192+
id: download
193+
with:
194+
name: "npm-package"
195+
path: release-npm-package
196+
197+
- name: Run ./ci/steps/publish-npm.sh
198+
run: yarn publish:npm
199+
env:
200+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
202+
# NOTE@jsjoeio
203+
# NPM_ENVIRONMENT intentionally not set here.
204+
# Instead, itis determined in publish-npm.sh script
205+
# using GITHUB environment variables
206+
180207
# TODO: cache building yarn --production
181208
# possibly 2m30s of savings(?)
182209
# this requires refactoring our release scripts

.github/workflows/npm-beta.yaml

-29
This file was deleted.

.github/workflows/npm-brew.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818

19+
- uses: actions/download-artifact@v2
20+
id: download
21+
with:
22+
name: "npm-package"
23+
path: release-npm-package
24+
1925
- name: Publish npm package and tag with "latest"
2026
run: yarn publish:npm
2127
env:
22-
ENVIRONMENT: "production"
2328
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2429
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25-
NPM_TAG: "latest"
30+
NPM_ENVIRONMENT: "production"
2631

2732
homebrew:
2833
# The newest version of code-server needs to be available on npm when this runs

.github/workflows/npm-dev.yaml

-30
This file was deleted.

ci/steps/publish-npm.sh

+61-27
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ main() {
2121
exit 1
2222
fi
2323

24-
## Environment
25-
# This string is used to determine how we should tag the npm release.
26-
# Environment can be one of three choices:
27-
# "development" - this means we tag with the PR number, allowing
28-
# a developer to install this version with `yarn add code-server@<pr-number>`
29-
# "staging" - this means we tag with `beta`, allowing
30-
# a developer to install this version with `yarn add code-server@beta`
31-
# "production" - this means we tag with `latest` (default), allowing
32-
# a developer to install this version with `yarn add code-server@latest`
33-
if ! is_env_var_set "ENVIRONMENT"; then
34-
echo "ENVIRONMENT is not set. Cannot determine npm tag without ENVIRONMENT."
35-
exit 1
36-
fi
37-
3824
## Publishing Information
3925
# All the variables below are used to determine how we should publish
4026
# the npm package. We also use this information for bumping the version.
@@ -47,22 +33,52 @@ main() {
4733
exit 1
4834
fi
4935

50-
# We need TAG to know what to publish under on npm
51-
# Options are "latest", "beta", or "<pr number >"
52-
# See Environment comments above to know when each is used.
53-
if ! is_env_var_set "NPM_TAG"; then
54-
echo "NPM_TAG is not set. This is needed for tagging the npm release."
36+
# We use this to grab the PR_NUMBER
37+
if ! is_env_var_set "GITHUB_REF"; then
38+
echo "GITHUB_REF is not set. Are you running this locally? We rely on values provided by GitHub."
39+
exit 1
40+
fi
41+
42+
# We use this when setting NPM_VERSION
43+
if ! is_env_var_set "GITHUB_SHA"; then
44+
echo "GITHUB_SHA is not set. Are you running this locally? We rely on values provided by GitHub."
5545
exit 1
5646
fi
5747

58-
echo "using tag: $NPM_TAG"
48+
# We use this to determine the NPM_ENVIRONMENT
49+
if ! is_env_var_set "GITHUB_EVENT_NAME"; then
50+
echo "GITHUB_EVENT_NAME is not set. Are you running this locally? We rely on values provided by GitHub."
51+
exit 1
52+
fi
5953

6054
# This allows us to publish to npm in CI workflows
6155
if [[ ${CI-} ]]; then
6256
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
6357
fi
6458

65-
download_artifact npm-package ./release-npm-package
59+
## Environment
60+
# This string is used to determine how we should tag the npm release.
61+
# Environment can be one of three choices:
62+
# "development" - this means we tag with the PR number, allowing
63+
# a developer to install this version with `yarn add code-server@<pr-number>`
64+
# "staging" - this means we tag with `beta`, allowing
65+
# a developer to install this version with `yarn add code-server@beta`
66+
# "production" - this means we tag with `latest` (default), allowing
67+
# a developer to install this version with `yarn add code-server@latest`
68+
if ! is_env_var_set "NPM_ENVIRONMENT"; then
69+
echo "NPM_ENVIRONMENT is not set. Determining in script based on GITHUB environment variables."
70+
71+
if [[ "$GITHUB_EVENT_NAME" == 'push' && "$GITHUB_REF" == 'refs/heads/main' ]]; then
72+
NPM_ENVIRONMENT="staging"
73+
else
74+
NPM_ENVIRONMENT="development"
75+
fi
76+
77+
echo "Using npm environment: $NPM_ENVIRONMENT"
78+
fi
79+
80+
# NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
81+
# That happens in CI as a step before we run this.
6682
# https://github.com/actions/upload-artifact/issues/38
6783
tar -xzf release-npm-package/package.tar.gz
6884

@@ -74,22 +90,40 @@ main() {
7490
# We only need to run npm version for "development" and "staging".
7591
# This is because our release:prep script automatically bumps the version
7692
# in the package.json and we commit it as part of the release PR.
77-
if [[ "$ENVIRONMENT" == "production" ]]; then
93+
if [[ "$NPM_ENVIRONMENT" == "production" ]]; then
7894
NPM_VERSION="$VERSION"
95+
# This means the npm version will be published as "stable"
96+
# and installed when a user runs `yarn install code-server`
97+
NPM_TAG="latest"
7998
else
99+
COMMIT_SHA="$GITHUB_SHA"
80100
echo "Not a production environment"
81-
echo "Found environment: $ENVIRONMENT"
101+
echo "Found environment: $NPM_ENVIRONMENT"
82102
echo "Manually bumping npm version..."
83103

84-
if ! is_env_var_set "PR_NUMBER_AND_COMMIT_SHA"; then
85-
echo "PR_NUMBER_AND_COMMIT_SHA is not set. This is needed for setting the npm version in non-production environments."
86-
exit 1
104+
if [[ "$NPM_ENVIRONMENT" == "staging" ]]; then
105+
NPM_VERSION="$VERSION-beta-$COMMIT_SHA"
106+
# This means the npm version will be tagged with "beta"
107+
# and installed when a user runs `yarn install code-server@beta`
108+
NPM_TAG="beta"
109+
fi
110+
111+
if [[ "$NPM_ENVIRONMENT" == "development" ]]; then
112+
# Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550
113+
PR_NUMBER=$(echo "$GITHUB_REF" | awk 'BEGIN { FS = "/" } ; { print $3 }')
114+
NPM_VERSION="$VERSION-$PR_NUMBER-$COMMIT_SHA"
115+
# This means the npm version will be tagged with "<pr number>"
116+
# and installed when a user runs `yarn install code-server@<pr number>`
117+
NPM_TAG="$PR_NUMBER"
87118
fi
88119

120+
echo "using tag: $NPM_TAG"
121+
89122
# We modify the version in the package.json
90123
# to be the current version + the PR number + commit SHA
124+
# or we use current version + beta + commit SHA
91125
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
92-
NPM_VERSION="$VERSION-$PR_NUMBER_AND_COMMIT_SHA"
126+
# Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040"
93127
pushd release
94128
# NOTE:@jsjoeio
95129
# I originally tried to use `yarn version` but ran into issues and abandoned it.

0 commit comments

Comments
 (0)