Skip to content

Commit 2e31e8f

Browse files
authored
Merge pull request #1623 from cdr/automate-release
Automate draft release
2 parents b706e85 + 169f8c6 commit 2e31e8f

9 files changed

+98
-38
lines changed

ci/README.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ Any file and directory added into this tree should be documented here.
88

99
## Publishing a release
1010

11+
Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub) installed.
12+
1113
1. Update the version of code-server in `package.json` and push a commit
12-
1. CI will run and generate the `npm-package` and `release-packages` artifacts on the GH actions workflow
13-
1. Create a new draft release and attach all files in `release-packages`
14-
1. Run some basic sanity tests on one of the released packages
15-
1. Summarize the major changes in the release notes and link to the relevant issues.
16-
1. Make sure to mention the VS Code version in the release notes
14+
1. GitHub actions will generate the `npm-package` and `release-packages` artifacts
15+
1. Run `yarn release:github-draft` to create a GitHub draft release from the template with
16+
the updated version.
17+
1. Summarize the major changes in the release notes and link to the relevant issues.
18+
1. Wait for the artifacts in step 2 to build
19+
1. Run `yarn release:github-assets` to download the artifacts and then upload them to the draft release
20+
1. Run some basic sanity tests on one of the released packages
1721
1. Publish the release
1822
1. CI will automatically grab the artifacts and then
1923
1. Publish the NPM package
@@ -45,7 +49,7 @@ This directory contains scripts used for the development of code-server.
4549

4650
## build
4751

48-
This directory contains the scripts used to build code-server.
52+
This directory contains the scripts used to build and release code-server.
4953
You can disable minification by setting `MINIFY=`.
5054

5155
- [./lib.sh](./lib.sh)
@@ -74,6 +78,12 @@ You can disable minification by setting `MINIFY=`.
7478
- Used to configure [nfpm](https://github.com/goreleaser/nfpm) to generate .deb and .rpm
7579
- [./build/code-server-nfpm.sh](./build/code-server-nfpm.sh)
7680
- Entrypoint script for code-server for .deb and .rpm
81+
- [./build/release-github-draft.sh](./build/release-github-draft.sh) (`yarn release:github-draft`)
82+
- Uses [hub](https://github.com/github/hub) to create a draft release with a template description
83+
- [./build/release-github-assets.sh](./build/release-github-assets.sh) (`yarn release:github-assets`)
84+
- Downloads the release-package artifacts for the current commit from CI
85+
- Uses [hub](https://github.com/github/hub) to upload the artifacts to the release
86+
specified in `package.json`
7787

7888
## release-container
7989

ci/build/release-github-assets.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Downloads the release artifacts from CI for the current
5+
# commit and then uploads them to the release with the version
6+
# in package.json.
7+
# You will need $GITHUB_TOKEN set.
8+
9+
main() {
10+
cd "$(dirname "$0")/../.."
11+
source ./ci/lib.sh
12+
13+
download_artifact release-packages ./release-packages
14+
local assets=(./release-packages/*)
15+
for i in "${!assets[@]}"; do
16+
assets[$i]="--attach=${assets[$i]}"
17+
done
18+
EDITOR=true hub release edit --draft "${assets[@]}" "v$(pkg_json_version)"
19+
}
20+
21+
main "$@"

ci/build/release-github-draft.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Creates a draft release with the template for the version in package.json
5+
6+
main() {
7+
cd "$(dirname "$0")/../.."
8+
source ./ci/lib.sh
9+
10+
hub release create \
11+
--file - \
12+
--draft "${assets[@]}" "v$(pkg_json_version)" << EOF
13+
v$(pkg_json_version)
14+
15+
VS Code v$(vscode_version)
16+
17+
- Summarize changes here with references to issues
18+
EOF
19+
}
20+
21+
main "$@"

ci/dev/lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ main() {
77
eslint --max-warnings=0 --fix $(git ls-files "*.ts" "*.tsx" "*.js")
88
stylelint $(git ls-files "*.css")
99
tsc --noEmit
10-
shellcheck -e SC2046,SC2164 $(git ls-files "*.sh")
10+
shellcheck -e SC2046,SC2164,SC2154 $(git ls-files "*.sh")
1111
}
1212

1313
main "$@"

ci/lib.sh

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pkg_json_version() {
1212
jq -r .version package.json
1313
}
1414

15+
vscode_version() {
16+
jq -r .version lib/vscode/package.json
17+
}
18+
1519
os() {
1620
local os
1721
os=$(uname | tr '[:upper:]' '[:lower:]')
@@ -41,3 +45,34 @@ arch() {
4145
;;
4246
esac
4347
}
48+
49+
curl() {
50+
command curl -H "Authorization: token $GITHUB_TOKEN" "$@"
51+
}
52+
53+
# Grabs the most recent ci.yaml github workflow run that was successful and triggered from the same commit being pushd.
54+
# This will contain the artifacts we want.
55+
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
56+
get_artifacts_url() {
57+
curl -sSL 'https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=push' | jq -r ".workflow_runs[] | select(.head_sha == \"$(git rev-parse HEAD)\") | .artifacts_url" | head -n 1
58+
}
59+
60+
# Grabs the artifact's download url.
61+
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
62+
get_artifact_url() {
63+
local artifact_name="$1"
64+
curl -sSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
65+
}
66+
67+
# Uses the above two functions to download a artifact into a directory.
68+
download_artifact() {
69+
local artifact_name="$1"
70+
local dst="$2"
71+
72+
local tmp_file
73+
tmp_file="$(mktemp)"
74+
75+
curl -sSL "$(get_artifact_url "$artifact_name")" > "$tmp_file"
76+
unzip -o "$tmp_file" -d "$dst"
77+
rm "$tmp_file"
78+
}

ci/steps/lib.sh

-29
This file was deleted.

ci/steps/publish-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
source ./ci/steps/lib.sh
6+
source ./ci/lib.sh
77

88
if [[ ${CI-} ]]; then
99
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

ci/steps/publish-npm.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
source ./ci/steps/lib.sh
6+
source ./ci/lib.sh
77

88
if [[ ${CI-} ]]; then
99
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"build:vscode": "./ci/build/build-vscode.sh",
1818
"release": "./ci/build/build-release.sh",
1919
"release:static": "./ci/build/build-static-release.sh",
20+
"release:github-draft": "./ci/build/release-github-draft.sh",
21+
"release:github-assets": "./ci/build/release-github-assets.sh",
2022
"test:static-release": "./ci/build/test-static-release.sh",
2123
"package": "./ci/build/build-packages.sh",
2224
"_____": "",

0 commit comments

Comments
 (0)