From fa19f8cac8b9fc94158d5161e7149e399a0c8415 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 22 Mar 2021 16:19:01 -0700 Subject: [PATCH 1/4] feat: add release-prep script --- ci/build/release-prep.sh | 101 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 102 insertions(+) create mode 100755 ci/build/release-prep.sh diff --git a/ci/build/release-prep.sh b/ci/build/release-prep.sh new file mode 100755 index 00000000..0b09bfeb --- /dev/null +++ b/ci/build/release-prep.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +# Description: This is a script to make the release process easier +# Run it with `yarn release:prep` and it will do the following: +# 1. Check that you have a $GITHUB_TOKEN set and hub installed +# 2. Update the version of code-server (package.json, docs, etc.) +# 3. Update the code coverage badge in the README +# 4. Open a draft PR using the release_template.md + +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + # Check that $GITHUB_TOKEN is set + if [[ -z "${GITHUB_TOKEN}" ]]; then + echo "We couldn't find an environment variable under GITHUB_TOKEN." + echo "This is needed for our scripts that use hub." + echo -e "See docs regarding GITHUB_TOKEN here under 'GitHub OAuth authentication': https://hub.github.com/hub.1.html" + exit + fi + + # Check that hub is installed + if ! command -v hub &>/dev/null; then + echo "hub could not be found." + echo "We use this with the release-github-draft.sh and release-github-assets.sh scripts." + echo -e "See docs here: https://github.com/github/hub#installation" + exit + fi + + # Check that they have jq installed + if ! command -v jq &>/dev/null; then + echo "jq could not be found." + echo "We use this to parse the package.json and grab the current version of code-server." + echo -e "See docs here: https://stedolan.github.io/jq/download/" + exit + fi + + # Check that they have rg installed + if ! command -v rg &>/dev/null; then + echo "rg could not be found." + echo "We use this when updating files across the codebase." + echo -e "See docs here: https://github.com/BurntSushi/ripgrep#installation" + exit + fi + + # Check that they have sd installed + if ! command -v sd &>/dev/null; then + echo "sd could not be found." + echo "We use this when updating files across the codebase." + echo -e "See docs here: https://github.com/chmln/sd#installation" + exit + fi + + # Check that they have node installed + if ! command -v node &>/dev/null; then + echo "node could not be found." + echo "That's surprising..." + echo "We use it in this script for getting the package.json version" + echo -e "See docs here: https://nodejs.org/en/download/" + exit + fi + + # credit to jakwuh for this solution + # https://gist.github.com/DarrenN/8c6a5b969481725a4413#gistcomment-1971123 + CODE_SERVER_CURRENT_VERSION=$(node -pe "require('./package.json').version") + # Ask which version we should update to + # In the future, we'll automate this and determine the latest version automatically + echo "Current version: ${CODE_SERVER_CURRENT_VERSION}" + # The $'\n' adds a line break. See: https://stackoverflow.com/a/39581815/3015595 + read -r -p "What version of code-server do you want to update to?"$'\n' CODE_SERVER_VERSION_TO_UPDATE + + echo -e "Great! We'll prep a PR for updating to $CODE_SERVER_VERSION_TO_UPDATE\n" + # I can't tell you why but + # when searching with rg, the version needs to in this format: '3\.7\.5' + # that's why we have the parameter expansion with the regex + rg -g '!yarn.lock' -g '!*.svg' --files-with-matches "${CODE_SERVER_CURRENT_VERSION//\./\\.}" | xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" + + # Ensure the tests are passing and code coverage is up-to-date + echo -e "Running unit tests and updating code coverage...\n" + yarn test:unit + # Updates the Lines badge in the README + yarn badges + # Updates the svg to be green for the badge + sd "red.svg" "green.svg" ../../README.md + + git add . && git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" + + CURRENT_BRANCH=$(git branch --show-current) + # Note: we need to set upstream as well or the gh pr create step will fail + # See: https://github.com/cli/cli/issues/575 + git push -u origin "$CURRENT_BRANCH" + + RELEASE_TEMPLATE_FILE="../../.github/PULL_REQUEST_TEMPLATE/pull_request_template.md" + echo -e "Opening a draft PR on GitHub\n" + # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create + 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 + + # TODO update docs under /ci +} + +main "$@" diff --git a/package.json b/package.json index 7e37de49..aa41eb42 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "release:standalone": "./ci/build/build-standalone-release.sh", "release:github-draft": "./ci/build/release-github-draft.sh", "release:github-assets": "./ci/build/release-github-assets.sh", + "release:prep": "./ci/build/release-prep.sh", "test:e2e": "./ci/dev/test-e2e.sh", "test:standalone-release": "./ci/build/test-standalone-release.sh", "test:unit": "./ci/dev/test-unit.sh", From a8858ea9fc81a5722e342fd85571d5bee9555837 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 23 Mar 2021 10:52:35 -0700 Subject: [PATCH 2/4] docs(ci): update step 1 of publish release --- ci/README.md | 13 +------------ ci/build/release-prep.sh | 10 ++++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/ci/README.md b/ci/README.md index 19d6778e..deea4c8f 100644 --- a/ci/README.md +++ b/ci/README.md @@ -12,18 +12,7 @@ Any file or directory in this subdirectory should be documented here. ## Publishing a release -Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub) installed. - -1. Update the version of code-server and make a PR. - 1. Update in `package.json` - 2. Update in [./docs/install.md](../docs/install.md) - 3. Update in [./ci/helm-chart/README.md](../ci/helm-chart/README.md) - - Remember to update the chart version as well on top of appVersion in `Chart.yaml`. - - Run `rg -g '!yarn.lock' -g '!*.svg' '3\.7\.5'` to ensure all values have been - changed. Replace the numbers as needed. - - You can install `rg` or `ripgrep` on macOS [here](https://formulae.brew.sh/formula/ripgrep). - 4. Update the code coverage badge (see [here](#updating-code-coverage-in-readme) for instructions) - 5. Update the docs badge in [./README.md](../README.md) +1. Run `yarn release:prep` and type in the new version i.e. 3.8.1 2. GitHub actions will generate the `npm-package`, `release-packages` and `release-images` artifacts. 1. You do not have to wait for these. 3. Run `yarn release:github-draft` to create a GitHub draft release from the template with diff --git a/ci/build/release-prep.sh b/ci/build/release-prep.sh index 0b09bfeb..ee40f0f5 100755 --- a/ci/build/release-prep.sh +++ b/ci/build/release-prep.sh @@ -4,7 +4,7 @@ # 1. Check that you have a $GITHUB_TOKEN set and hub installed # 2. Update the version of code-server (package.json, docs, etc.) # 3. Update the code coverage badge in the README -# 4. Open a draft PR using the release_template.md +# 4. Open a draft PR using the release_template.md and view in browser set -euo pipefail @@ -90,12 +90,14 @@ main() { # See: https://github.com/cli/cli/issues/575 git push -u origin "$CURRENT_BRANCH" - RELEASE_TEMPLATE_FILE="../../.github/PULL_REQUEST_TEMPLATE/pull_request_template.md" + RELEASE_TEMPLATE_STRING=$(cat ../../.github/PULL_REQUEST_TEMPLATE/release_template.md) + echo -e "Opening a draft PR on GitHub\n" # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create - 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 + gh pr create --base main --title "release: $CODE_SERVER_VERSION_TO_UPDATE" --body "$RELEASE_TEMPLATE_STRING" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft - # TODO update docs under /ci + # Open PR in browser + gh pr view --web } main "$@" From a1dca6da294c861da2ad297267931c2b17e48731 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 23 Mar 2021 11:26:05 -0700 Subject: [PATCH 3/4] feat: add dry run option to release-prep.sh --- .../PULL_REQUEST_TEMPLATE/release_template.md | 7 +++-- ci/build/release-prep.sh | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/release_template.md b/.github/PULL_REQUEST_TEMPLATE/release_template.md index 3d0f13ba..95b67681 100644 --- a/.github/PULL_REQUEST_TEMPLATE/release_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/release_template.md @@ -1,4 +1,5 @@ -This PR is to generate a new release of `code-server` at `0.0.0` + +This PR is to generate a new release of `code-server` at `$CODE_SERVER_VERSION_TO_UPDATE` ## Screenshot @@ -6,10 +7,10 @@ TODO ## TODOs -- [ ] update the AUR package -- [ ] upload assets to draft release - [ ] test locally +- [ ] upload assets to draft release - [ ] double-check github release tag is the commit with artifacts - [ ] publish release - [ ] merge PR - [ ] update the homebrew package +- [ ] update the AUR package diff --git a/ci/build/release-prep.sh b/ci/build/release-prep.sh index ee40f0f5..9f8b0e00 100755 --- a/ci/build/release-prep.sh +++ b/ci/build/release-prep.sh @@ -5,14 +5,22 @@ # 2. Update the version of code-server (package.json, docs, etc.) # 3. Update the code coverage badge in the README # 4. Open a draft PR using the release_template.md and view in browser +# If you want to perform a dry run of this script run DRY_RUN=0 yarn release:prep set -euo pipefail main() { + if [ "${DRY_RUN-}" = 1 ]; then + echo "Performing a dry run..." + CMD="echo" + else + CMD='' + fi + cd "$(dirname "$0")/../.." # Check that $GITHUB_TOKEN is set - if [[ -z "${GITHUB_TOKEN}" ]]; then + if [[ -z ${GITHUB_TOKEN-} ]]; then echo "We couldn't find an environment variable under GITHUB_TOKEN." echo "This is needed for our scripts that use hub." echo -e "See docs regarding GITHUB_TOKEN here under 'GitHub OAuth authentication': https://hub.github.com/hub.1.html" @@ -73,31 +81,32 @@ main() { # I can't tell you why but # when searching with rg, the version needs to in this format: '3\.7\.5' # that's why we have the parameter expansion with the regex - rg -g '!yarn.lock' -g '!*.svg' --files-with-matches "${CODE_SERVER_CURRENT_VERSION//\./\\.}" | xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" + $CMD rg -g '!yarn.lock' -g '!*.svg' --files-with-matches "${CODE_SERVER_CURRENT_VERSION//\./\\.}" | $CMD xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" # Ensure the tests are passing and code coverage is up-to-date echo -e "Running unit tests and updating code coverage...\n" - yarn test:unit + $CMD yarn test:unit # Updates the Lines badge in the README - yarn badges + $CMD yarn badges # Updates the svg to be green for the badge - sd "red.svg" "green.svg" ../../README.md + $CMD sd "red.svg" "green.svg" ../../README.md - git add . && git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" + $CMD git add . && $CMD git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" CURRENT_BRANCH=$(git branch --show-current) # Note: we need to set upstream as well or the gh pr create step will fail # See: https://github.com/cli/cli/issues/575 - git push -u origin "$CURRENT_BRANCH" + $CMD git push -u origin "$CURRENT_BRANCH" - RELEASE_TEMPLATE_STRING=$(cat ../../.github/PULL_REQUEST_TEMPLATE/release_template.md) + # This runs from the root so that's why we use this path vs. ../../ + RELEASE_TEMPLATE_STRING=$(cat ./.github/PULL_REQUEST_TEMPLATE/release_template.md) - echo -e "Opening a draft PR on GitHub\n" + echo -e "\nOpening a draft PR on GitHub" # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create - gh pr create --base main --title "release: $CODE_SERVER_VERSION_TO_UPDATE" --body "$RELEASE_TEMPLATE_STRING" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft + $CMD gh pr create --base main --title "release: $CODE_SERVER_VERSION_TO_UPDATE" --body "$RELEASE_TEMPLATE_STRING" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft # Open PR in browser - gh pr view --web + $CMD gh pr view --web } main "$@" From 299e17e6d9da73ba027b57c95b69c723373e651d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 24 Mar 2021 16:35:55 -0700 Subject: [PATCH 4/4] refactor: update script command to get git branch --- .../PULL_REQUEST_TEMPLATE/release_template.md | 1 + ci/build/release-prep.sh | 20 +++++++++++-------- ci/dev/update-vscode.sh | 7 ++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/release_template.md b/.github/PULL_REQUEST_TEMPLATE/release_template.md index 95b67681..028b9753 100644 --- a/.github/PULL_REQUEST_TEMPLATE/release_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/release_template.md @@ -1,4 +1,5 @@ + This PR is to generate a new release of `code-server` at `$CODE_SERVER_VERSION_TO_UPDATE` ## Screenshot diff --git a/ci/build/release-prep.sh b/ci/build/release-prep.sh index 9f8b0e00..c430c1ea 100755 --- a/ci/build/release-prep.sh +++ b/ci/build/release-prep.sh @@ -5,7 +5,7 @@ # 2. Update the version of code-server (package.json, docs, etc.) # 3. Update the code coverage badge in the README # 4. Open a draft PR using the release_template.md and view in browser -# If you want to perform a dry run of this script run DRY_RUN=0 yarn release:prep +# If you want to perform a dry run of this script run DRY_RUN=1 yarn release:prep set -euo pipefail @@ -78,10 +78,7 @@ main() { read -r -p "What version of code-server do you want to update to?"$'\n' CODE_SERVER_VERSION_TO_UPDATE echo -e "Great! We'll prep a PR for updating to $CODE_SERVER_VERSION_TO_UPDATE\n" - # I can't tell you why but - # when searching with rg, the version needs to in this format: '3\.7\.5' - # that's why we have the parameter expansion with the regex - $CMD rg -g '!yarn.lock' -g '!*.svg' --files-with-matches "${CODE_SERVER_CURRENT_VERSION//\./\\.}" | $CMD xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" + $CMD rg -g '!yarn.lock' -g '!*.svg' --files-with-matches --fixed-strings "${CODE_SERVER_CURRENT_VERSION}" | $CMD xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" # Ensure the tests are passing and code coverage is up-to-date echo -e "Running unit tests and updating code coverage...\n" @@ -91,12 +88,19 @@ main() { # Updates the svg to be green for the badge $CMD sd "red.svg" "green.svg" ../../README.md - $CMD git add . && $CMD git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" + $CMD git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" - CURRENT_BRANCH=$(git branch --show-current) # Note: we need to set upstream as well or the gh pr create step will fail # See: https://github.com/cli/cli/issues/575 - $CMD git push -u origin "$CURRENT_BRANCH" + CURRENT_BRANCH=$(git branch | grep '\*' | cut -d' ' -f2-) + if [[ -z $(git config "branch.${CURRENT_BRANCH}.remote") ]]; then + echo "Doesn't look like you've pushed this branch to remote" + echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n" + # Note: we need to set upstream as well or the gh pr create step will fail + # See: https://github.com/cli/cli/issues/575 + echo "Please set the upstream and re-run the script" + exit 1 + fi # This runs from the root so that's why we use this path vs. ../../ RELEASE_TEMPLATE_STRING=$(cat ./.github/PULL_REQUEST_TEMPLATE/release_template.md) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index 169b122a..65daedcc 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -81,13 +81,14 @@ main() { # Push branch to remote if not already pushed # If we don't do this, the opening a draft PR step won't work # because it will stop and ask where you want to push the branch - CURRENT_BRANCH=$(git branch --show-current) - if [[ -z $(git ls-remote --heads origin "$CURRENT_BRANCH") ]]; then + CURRENT_BRANCH=$(git branch | grep '\*' | cut -d' ' -f2-) + if [[ -z $(git config "branch.${CURRENT_BRANCH}.remote") ]]; then echo "Doesn't look like you've pushed this branch to remote" echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n" # Note: we need to set upstream as well or the gh pr create step will fail # See: https://github.com/cli/cli/issues/575 - git push -u origin "$CURRENT_BRANCH" + echo "Please set the upstream and re-run the script" + exit 1 fi echo "Going to try to update vscode for you..."