@@ -4,15 +4,60 @@ set -euo pipefail
4
4
main () {
5
5
cd " $( dirname " $0 " ) /../.."
6
6
source ./ci/lib.sh
7
+ source ./ci/steps/steps-lib.sh
7
8
8
- # npm view won't exit with non-zero so we have to check the output.
9
- local hasVersion
10
- hasVersion=$( npm view " code-server@$VERSION " version)
11
- if [[ $hasVersion == " $VERSION " ]]; then
12
- echo " $VERSION is already published"
13
- return
9
+ # # Authentication tokens
10
+ # Needed to publish on NPM
11
+ if ! is_env_var_set " NPM_TOKEN" ; then
12
+ echo " NPM_TOKEN is not set. Cannot publish to npm without credentials."
13
+ exit 1
14
+ fi
15
+
16
+ # NOTE@jsjoeio - only needed if we use the download_artifact
17
+ # because we talk to the GitHub API.
18
+ # Needed to use GitHub API
19
+ if ! is_env_var_set " GITHUB_TOKEN" ; then
20
+ echo " GITHUB_TOKEN is not set. Cannot download npm release artifact without GitHub credentials."
21
+ exit 1
22
+ fi
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
+ # # Publishing Information
39
+ # All the variables below are used to determine how we should publish
40
+ # the npm package. We also use this information for bumping the version.
41
+ # This is because npm won't publish your package unless it's a new version.
42
+ # i.e. for development, we bump the version to <current version>-<pr number>-<commit sha>
43
+ # example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
44
+ # We need the current package.json VERSION
45
+ if ! is_env_var_set " VERSION" ; then
46
+ echo " VERSION is not set. Cannot publish to npm without VERSION."
47
+ exit 1
48
+ fi
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."
55
+ exit 1
14
56
fi
15
57
58
+ echo " using tag: $NPM_TAG "
59
+
60
+ # This allows us to publish to npm in CI workflows
16
61
if [[ ${CI-} ]]; then
17
62
echo " //registry.npmjs.org/:_authToken=${NPM_TOKEN} " > ~ /.npmrc
18
63
fi
@@ -24,7 +69,45 @@ main() {
24
69
# Ignore symlink when publishing npm package
25
70
# See: https://github.com/cdr/code-server/pull/3935
26
71
echo " node_modules.asar" > release/.npmignore
27
- yarn publish --non-interactive release
72
+
73
+ # NOTES:@jsjoeio
74
+ # We only need to run npm version for "development" and "staging".
75
+ # This is because our release:prep script automatically bumps the version
76
+ # in the package.json and we commit it as part of the release PR.
77
+ if [[ " $ENVIRONMENT " == " production" ]]; then
78
+ NPM_VERSION=" $VERSION "
79
+ else
80
+ echo " Not a production environment"
81
+ echo " Found environment: $ENVIRONMENT "
82
+ echo " Manually bumping npm version..."
83
+
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
87
+ fi
88
+
89
+ # We modify the version in the package.json
90
+ # to be the current version + the PR number + commit SHA
91
+ # Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
92
+ NPM_VERSION=" $VERSION -$PR_NUMBER_AND_COMMIT_SHA "
93
+ pushd release
94
+ # NOTE:@jsjoeio
95
+ # I originally tried to use `yarn version` but ran into issues and abandoned it.
96
+ npm version " $NPM_VERSION "
97
+ popd
98
+ fi
99
+
100
+ # We need to make sure we haven't already published the version.
101
+ # This is because npm view won't exit with non-zero so we have
102
+ # to check the output.
103
+ local hasVersion
104
+ hasVersion=$( npm view " code-server@$NPM_VERSION " version)
105
+ if [[ $hasVersion == " $NPM_VERSION " ]]; then
106
+ echo " $NPM_VERSION is already published"
107
+ return
108
+ fi
109
+
110
+ yarn publish --non-interactive release --tag " $NPM_TAG "
28
111
}
29
112
30
113
main " $@ "
0 commit comments