@@ -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