Skip to content

Commit 0dc88c8

Browse files
committed
fixup! move NPM_ENVIRONMENT logic to script
1 parent 955145d commit 0dc88c8

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

.github/workflows/ci.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,15 @@ jobs:
194194
name: "npm-package"
195195
path: release-npm-package
196196

197-
- name: Set NPM_ENVIRONMENT
198-
run: |
199-
if [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == 'refs/heads/master' ]]; then
200-
echo "NPM_ENVIRONMENT=staging" >> "$GITHUB_ENV"
201-
else
202-
echo "NPM_ENVIRONMENT=development" >> "$GITHUB_ENV"
203-
fi
204197
- name: Run ./ci/steps/publish-npm.sh
205198
run: yarn publish:npm
206199
env:
207200
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208201
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
209206

210207
# TODO: cache building yarn --production
211208
# possibly 2m30s of savings(?)

ci/steps/publish-npm.sh

+27-14
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 "NPM_ENVIRONMENT"; then
34-
echo "NPM_ENVIRONMENT is not set. Cannot determine npm tag without NPM_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.
@@ -59,11 +45,38 @@ main() {
5945
exit 1
6046
fi
6147

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
53+
6254
# This allows us to publish to npm in CI workflows
6355
if [[ ${CI-} ]]; then
6456
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
6557
fi
6658

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+
6780
# NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
6881
# That happens in CI as a step before we run this.
6982
# https://github.com/actions/upload-artifact/issues/38

0 commit comments

Comments
 (0)