@@ -21,20 +21,6 @@ main() {
21
21
exit 1
22
22
fi
23
23
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
-
38
24
# # Publishing Information
39
25
# All the variables below are used to determine how we should publish
40
26
# the npm package. We also use this information for bumping the version.
@@ -47,22 +33,52 @@ main() {
47
33
exit 1
48
34
fi
49
35
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."
55
45
exit 1
56
46
fi
57
47
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
59
53
60
54
# This allows us to publish to npm in CI workflows
61
55
if [[ ${CI-} ]]; then
62
56
echo " //registry.npmjs.org/:_authToken=${NPM_TOKEN} " > ~ /.npmrc
63
57
fi
64
58
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.
66
82
# https://github.com/actions/upload-artifact/issues/38
67
83
tar -xzf release-npm-package/package.tar.gz
68
84
@@ -74,22 +90,40 @@ main() {
74
90
# We only need to run npm version for "development" and "staging".
75
91
# This is because our release:prep script automatically bumps the version
76
92
# 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
78
94
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"
79
98
else
99
+ COMMIT_SHA=" $GITHUB_SHA "
80
100
echo " Not a production environment"
81
- echo " Found environment: $ENVIRONMENT "
101
+ echo " Found environment: $NPM_ENVIRONMENT "
82
102
echo " Manually bumping npm version..."
83
103
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 "
87
118
fi
88
119
120
+ echo " using tag: $NPM_TAG "
121
+
89
122
# We modify the version in the package.json
90
123
# to be the current version + the PR number + commit SHA
124
+ # or we use current version + beta + commit SHA
91
125
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
92
- NPM_VERSION= " $VERSION - $PR_NUMBER_AND_COMMIT_SHA "
126
+ # Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040 "
93
127
pushd release
94
128
# NOTE:@jsjoeio
95
129
# I originally tried to use `yarn version` but ran into issues and abandoned it.
0 commit comments