@@ -30,8 +30,8 @@ main() {
30
30
# a developer to install this version with `yarn add code-server@beta`
31
31
# "production" - this means we tag with `latest` (default), allowing
32
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 ."
33
+ if ! is_env_var_set " NPM_ENVIRONMENT " ; then
34
+ echo " NPM_ENVIRONMENT is not set. Cannot determine npm tag without NPM_ENVIRONMENT ."
35
35
exit 1
36
36
fi
37
37
@@ -47,22 +47,37 @@ main() {
47
47
exit 1
48
48
fi
49
49
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."
50
+ # We use this to grab the PR_NUMBER
51
+ if ! is_env_var_set " GITHUB_REF" ; then
52
+ echo " GITHUB_REF is not set. Are you running this locally? We rely on values provided by GitHub."
55
53
exit 1
56
54
fi
57
55
58
- echo " using tag: $NPM_TAG "
56
+ # We use this to grab the branch name
57
+ if ! is_env_var_set " GITHUB_HEAD_REF" ; then
58
+ echo " GITHUB_HEAD_REF is not set. Are you running this locally? We rely on values provided by GitHub."
59
+ exit 1
60
+ fi
61
+
62
+ # We use this when setting NPM_VERSION
63
+ if ! is_env_var_set " GITHUB_SHA" ; then
64
+ echo " GITHUB_SHA is not set. Are you running this locally? We rely on values provided by GitHub."
65
+ exit 1
66
+ fi
59
67
60
68
# This allows us to publish to npm in CI workflows
61
69
if [[ ${CI-} ]]; then
62
70
echo " //registry.npmjs.org/:_authToken=${NPM_TOKEN} " > ~ /.npmrc
63
71
fi
64
72
65
- download_artifact npm-package ./release-npm-package
73
+ # Note: if this runs on a push to main or a release workflow
74
+ # There is no BRANCH so branch will be empty which is why
75
+ # we set a default.
76
+ # Source:https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
77
+ BRANCH=" ${GITHUB_HEAD_REF-main} "
78
+
79
+ # NOTE@jsjoeio - this script assumes we have the artifact downloaded on disk
80
+ # That happens in CI as a step before we run this.
66
81
# https://github.com/actions/upload-artifact/issues/38
67
82
tar -xzf release-npm-package/package.tar.gz
68
83
@@ -74,22 +89,40 @@ main() {
74
89
# We only need to run npm version for "development" and "staging".
75
90
# This is because our release:prep script automatically bumps the version
76
91
# in the package.json and we commit it as part of the release PR.
77
- if [[ " $ENVIRONMENT " == " production" ]]; then
92
+ if [[ " $NPM_ENVIRONMENT " == " production" ]]; then
78
93
NPM_VERSION=" $VERSION "
94
+ # This means the npm version will be published as "stable"
95
+ # and installed when a user runs `yarn install code-server`
96
+ NPM_TAG=" latest"
79
97
else
98
+ COMMIT_SHA=" $GITHUB_SHA "
80
99
echo " Not a production environment"
81
- echo " Found environment: $ENVIRONMENT "
100
+ echo " Found environment: $NPM_ENVIRONMENT "
82
101
echo " Manually bumping npm version..."
83
102
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
103
+ if [[ " $NPM_ENVIRONMENT " == " staging" ]]; then
104
+ NPM_VERSION=" $VERSION -beta-$COMMIT_SHA "
105
+ # This means the npm version will be tagged with "beta"
106
+ # and installed when a user runs `yarn install code-server@beta`
107
+ NPM_TAG=" beta"
108
+ fi
109
+
110
+ if [[ " $NPM_ENVIRONMENT " == " development" ]]; then
111
+ # Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550
112
+ PR_NUMBER=$( echo " $GITHUB_REF " | awk ' BEGIN { FS = "/" } ; { print $3 }' )
113
+ NPM_VERSION=" $VERSION -$PR_NUMBER -$COMMIT_SHA "
114
+ # This means the npm version will be tagged with "<pr number>"
115
+ # and installed when a user runs `yarn install code-server@<pr number>`
116
+ NPM_TAG=" $PR_NUMBER "
87
117
fi
88
118
119
+ echo " using tag: $NPM_TAG "
120
+
89
121
# We modify the version in the package.json
90
122
# to be the current version + the PR number + commit SHA
123
+ # or we use current version + beta + commit SHA
91
124
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
92
- NPM_VERSION= " $VERSION - $PR_NUMBER_AND_COMMIT_SHA "
125
+ # Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040 "
93
126
pushd release
94
127
# NOTE:@jsjoeio
95
128
# I originally tried to use `yarn version` but ran into issues and abandoned it.
0 commit comments