Skip to content

Commit 5e4e57f

Browse files
committed
feat: add release-prep script
1 parent 24dc208 commit 5e4e57f

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

ci/build/release-prep.sh

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
# Description: This is a script to make the release process easier
3+
# Run it with `yarn release:prep` and it will do the following:
4+
# 1. Check that you have a $GITHUB_TOKEN set and hub installed
5+
# 2. Update the version of code-server (package.json, docs, etc.)
6+
# 3. Update the code coverage badge in the README
7+
# 4. Open a draft PR using the release_template.md
8+
9+
set -euo pipefail
10+
11+
main() {
12+
cd "$(dirname "$0")/../.."
13+
14+
# Check that $GITHUB_TOKEN is set
15+
if [[ -z "${GITHUB_TOKEN}" ]]; then
16+
echo "We couldn't find an environment variable under GITHUB_TOKEN."
17+
echo "This is needed for our scripts that use hub."
18+
echo -e "See docs regarding GITHUB_TOKEN here under 'GitHub OAuth authentication': https://hub.github.com/hub.1.html"
19+
exit
20+
fi
21+
22+
# Check that hub is installed
23+
if ! command -v hub &>/dev/null; then
24+
echo "hub could not be found."
25+
echo "We use this with the release-github-draft.sh and release-github-assets.sh scripts."
26+
echo -e "See docs here: https://github.com/github/hub#installation"
27+
exit
28+
fi
29+
30+
# Check that they have jq installed
31+
if ! command -v jq &>/dev/null; then
32+
echo "jq could not be found."
33+
echo "We use this to parse the package.json and grab the current version of code-server."
34+
echo -e "See docs here: https://stedolan.github.io/jq/download/"
35+
exit
36+
fi
37+
38+
# Check that they have rg installed
39+
if ! command -v rg &>/dev/null; then
40+
echo "rg could not be found."
41+
echo "We use this when updating files across the codebase."
42+
echo -e "See docs here: https://github.com/BurntSushi/ripgrep#installation"
43+
exit
44+
fi
45+
46+
# Check that they have sd installed
47+
if ! command -v sd &>/dev/null; then
48+
echo "sd could not be found."
49+
echo "We use this when updating files across the codebase."
50+
echo -e "See docs here: https://github.com/chmln/sd#installation"
51+
exit
52+
fi
53+
54+
# Check that they have node installed
55+
if ! command -v node &>/dev/null; then
56+
echo "node could not be found."
57+
echo "That's surprising..."
58+
echo "We use it in this script for getting the package.json version"
59+
echo -e "See docs here: https://nodejs.org/en/download/"
60+
exit
61+
fi
62+
63+
# credit to jakwuh for this solution
64+
# https://gist.github.com/DarrenN/8c6a5b969481725a4413#gistcomment-1971123
65+
CODE_SERVER_CURRENT_VERSION=$(node -pe "require('./package.json').version")
66+
# Ask which version we should update to
67+
# In the future, we'll automate this and determine the latest version automatically
68+
echo "Current version: ${CODE_SERVER_CURRENT_VERSION}"
69+
# The $'\n' adds a line break. See: https://stackoverflow.com/a/39581815/3015595
70+
read -r -p "What version of code-server do you want to update to?"$'\n' CODE_SERVER_VERSION_TO_UPDATE
71+
72+
echo -e "Great! We'll prep a PR for updating to $CODE_SERVER_VERSION_TO_UPDATE\n"
73+
# I can't tell you why but
74+
# when searching with rg, the version needs to in this format: '3\.7\.5'
75+
# that's why we have the parameter expansion with the regex
76+
rg -g '!yarn.lock' -g '!*.svg' --files-with-matches "${CODE_SERVER_CURRENT_VERSION//\./\\.}" | xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE"
77+
78+
# Ensure the tests are passing and code coverage is up-to-date
79+
echo -e "Running unit tests and updating code coverage...\n"
80+
yarn test:unit
81+
# Updates the Lines badge in the README
82+
yarn badges
83+
# Updates the svg to be green for the badge
84+
sd "red.svg" "green.svg" ../../README.md
85+
86+
git add . && git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE"
87+
88+
CURRENT_BRANCH=$(git branch --show-current)
89+
# Note: we need to set upstream as well or the gh pr create step will fail
90+
# See: https://github.com/cli/cli/issues/575
91+
git push -u origin "$CURRENT_BRANCH"
92+
93+
RELEASE_TEMPLATE_FILE="../../.github/PULL_REQUEST_TEMPLATE/pull_request_template.md"
94+
echo -e "Opening a draft PR on GitHub\n"
95+
# To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create
96+
gh pr create --base main --title "release: $CODE_SERVER_VERSION_TO_UPDATE" --body-file "$RELEASE_TEMPLATE_FILE" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft
97+
98+
# TODO update docs under /ci
99+
}
100+
101+
main "$@"

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"release:standalone": "./ci/build/build-standalone-release.sh",
1717
"release:github-draft": "./ci/build/release-github-draft.sh",
1818
"release:github-assets": "./ci/build/release-github-assets.sh",
19+
"release:prep": "./ci/build/release-prep.sh",
1920
"test:e2e": "./ci/dev/test-e2e.sh",
2021
"test:standalone-release": "./ci/build/test-standalone-release.sh",
2122
"test:unit": "./ci/dev/test-unit.sh",

0 commit comments

Comments
 (0)