1
1
#! /usr/bin/env bash
2
2
set -euo pipefail
3
3
4
- # TODOs refactor this to determine ENVIRONMENT, NPM_TAG and NPM_VERSION
5
-
6
4
main () {
7
5
cd " $( dirname " $0 " ) /../.."
8
6
source ./ci/lib.sh
@@ -32,8 +30,8 @@ main() {
32
30
# a developer to install this version with `yarn add code-server@beta`
33
31
# "production" - this means we tag with `latest` (default), allowing
34
32
# a developer to install this version with `yarn add code-server@latest`
35
- if ! is_env_var_set " ENVIRONMENT " ; then
36
- 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 ."
37
35
exit 1
38
36
fi
39
37
@@ -49,27 +47,35 @@ main() {
49
47
exit 1
50
48
fi
51
49
52
- # We need TAG to know what to publish under on npm
53
- # Options are "latest", "beta", or "<pr number >"
54
- # See Environment comments above to know when each is used.
55
- # TODO@jsjoeio - we need to determine this ourselves
56
- if ! is_env_var_set " NPM_TAG" ; then
57
- 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."
58
53
exit 1
59
54
fi
60
55
61
- echo " using tag: $NPM_TAG "
56
+ # We use this to grab the branch name
57
+ if ! is_env_var_set " GITHUB_REF_NAME" ; then
58
+ echo " GITHUB_REF_NAME 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
62
67
63
68
# This allows us to publish to npm in CI workflows
64
69
if [[ ${CI-} ]]; then
65
70
echo " //registry.npmjs.org/:_authToken=${NPM_TOKEN} " > ~ /.npmrc
66
71
fi
67
72
68
- # TODO@jsjoeio we need to refactor to download this based on environment
69
- # for "development", use the branch artifacts
70
- # for "staging" (merges into main),
71
- # for "production" look for release branch (currently we do this)
72
- 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_REF_NAME: main} "
78
+ download_artifact npm-package ./release-npm-package " $NPM_ENVIRONMENT " " $BRANCH "
73
79
# https://github.com/actions/upload-artifact/issues/38
74
80
tar -xzf release-npm-package/package.tar.gz
75
81
@@ -81,22 +87,40 @@ main() {
81
87
# We only need to run npm version for "development" and "staging".
82
88
# This is because our release:prep script automatically bumps the version
83
89
# in the package.json and we commit it as part of the release PR.
84
- if [[ " $ENVIRONMENT " == " production" ]]; then
90
+ if [[ " $NPM_ENVIRONMENT " == " production" ]]; then
85
91
NPM_VERSION=" $VERSION "
92
+ # This means the npm version will be published as "stable"
93
+ # and installed when a user runs `yarn install code-server`
94
+ NPM_TAG=" latest"
86
95
else
96
+ COMMIT_SHA=" $GITHUB_SHA "
87
97
echo " Not a production environment"
88
- echo " Found environment: $ENVIRONMENT "
98
+ echo " Found environment: $NPM_ENVIRONMENT "
89
99
echo " Manually bumping npm version..."
90
100
91
- if ! is_env_var_set " PR_NUMBER_AND_COMMIT_SHA" ; then
92
- echo " PR_NUMBER_AND_COMMIT_SHA is not set. This is needed for setting the npm version in non-production environments."
93
- exit 1
101
+ if [[ " $NPM_ENVIRONMENT " == " beta" ]]; then
102
+ NPM_VERSION=" $VERSION -beta-$COMMIT_SHA "
103
+ # This means the npm version will be tagged with "beta"
104
+ # and installed when a user runs `yarn install code-server@beta`
105
+ NPM_TAG=" beta"
106
+ fi
107
+
108
+ if [[ " $NPM_ENVIRONMENT " == " development" ]]; then
109
+ # Source: https://github.com/actions/checkout/issues/58#issuecomment-614041550
110
+ PR_NUMBER=$( echo " $GITHUB_REF " | awk ' BEGIN { FS = "/" } ; { print $3 }' )
111
+ NPM_VERSION=" $VERSION -$PR_NUMBER -$COMMIT_SHA "
112
+ # This means the npm version will be tagged with "<pr number>"
113
+ # and installed when a user runs `yarn install code-server@<pr number>`
114
+ NPM_TAG=" $PR_NUMBER "
94
115
fi
95
116
117
+ echo " using tag: $NPM_TAG "
118
+
96
119
# We modify the version in the package.json
97
120
# to be the current version + the PR number + commit SHA
121
+ # or we use current version + beta + commit SHA
98
122
# Example: "version": "4.0.1-4769-ad7b23cfe6ffd72914e34781ef7721b129a23040"
99
- NPM_VERSION= " $VERSION - $PR_NUMBER_AND_COMMIT_SHA "
123
+ # Example: "version": "4.0.1-beta-ad7b23cfe6ffd72914e34781ef7721b129a23040 "
100
124
pushd release
101
125
# NOTE:@jsjoeio
102
126
# I originally tried to use `yarn version` but ran into issues and abandoned it.
0 commit comments