11#! /usr/bin/env bash
2+ # Description: This is a script to make the process of updating vscode versions easier
3+ # Run it with `yarn update:vscode` and it will do the following:
4+ # 1. Check that you have a remote called `vscode`
5+ # 2. Ask you which version you want to upgrade to
6+ # 3. Grab the exact version from the package.json i.e. 1.53.2
7+ # 4. Fetch the vscode remote branches to run the subtree update
8+ # 5. Run the subtree update and pull in the vscode update
9+ # 6. Commit the changes (including merge conflicts)
10+ # 7. Open a draft PR
11+
212set -euo pipefail
313
14+ # This function expects two arguments
15+ # 1. the vscode version we're updating to
16+ # 2. the list of merge conflict files
17+ make_pr_body () {
18+ local BODY=" This PR updates vscode to $1
19+
20+ ## TODOS
21+
22+ - [ ] test editor locally
23+ - [ ] test terminal locally
24+ - [ ] make notes about any significant changes in docs/CONTRIBUTING.md#notes-about-changes
25+
26+ ## Files with conflicts (fix these)
27+ $2 "
28+ echo " $BODY "
29+ }
30+
431main () {
532 cd " $( dirname " $0 " ) /../.."
633
734 # Check if the remote exists
835 # if it doesn't, we add it
936 if ! git config remote.vscode.url > /dev/null; then
1037 echo " Could not find 'vscode' as a remote"
11- echo " Adding with: git remote add -f vscode https://github.com/microsoft/vscode.git &> /dev/null"
12- echo " Supressing output with '&> /dev/null'"
13- git remote add -f vscode https://github.com/microsoft/vscode.git & > /dev/null
38+ echo " Adding with: git remote add vscode https://github.com/microsoft/vscode.git"
39+ git remote add vscode https://github.com/microsoft/vscode.git
1440 fi
1541
1642 # Ask which version we should update to
@@ -25,7 +51,24 @@ main() {
2551 exit 1
2652 fi
2753
28- echo -e " Great! We'll prep a PR for updating to $VSCODE_VERSION_TO_UPDATE \n"
54+ # Check that they have jq installed
55+ if ! command -v jq & > /dev/null; then
56+ echo " jq could not be found."
57+ echo " We use this when looking up the exact version to update to in the package.json in VS Code."
58+ echo -e " See docs here: https://stedolan.github.io/jq/download/"
59+ exit
60+ fi
61+
62+ # Grab the exact version from package.json
63+ VSCODE_EXACT_VERSION=$( curl -s " https://raw.githubusercontent.com/microsoft/vscode/release/$VSCODE_VERSION_TO_UPDATE /package.json" | jq -r " .version" )
64+
65+ echo -e " Great! We'll prep a PR for updating to $VSCODE_EXACT_VERSION \n"
66+
67+ # For some reason the subtree update doesn't work
68+ # unless we fetch all the branches
69+ echo -e " Fetching vscode branches..."
70+ echo -e " Note: this might take a while"
71+ git fetch vscode
2972
3073 # Check if GitHub CLI is installed
3174 if ! command -v gh & > /dev/null; then
@@ -42,17 +85,36 @@ main() {
4285 if [[ -z $( git ls-remote --heads origin " $CURRENT_BRANCH " ) ]]; then
4386 echo " Doesn't look like you've pushed this branch to remote"
4487 echo -e " Pushing now using: git push origin $CURRENT_BRANCH \n"
45- git push origin " $CURRENT_BRANCH "
88+ # Note: we need to set upstream as well or the gh pr create step will fail
89+ # See: https://github.com/cli/cli/issues/575
90+ git push -u origin " $CURRENT_BRANCH "
4691 fi
4792
48- echo " Opening a draft PR on GitHub"
49- # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create
50- gh pr create --base master --title " feat(vscode): update to version $VSCODE_VERSION_TO_UPDATE " --body " This PR updates vscode to version: $VSCODE_VERSION_TO_UPDATE " --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft
51-
5293 echo " Going to try to update vscode for you..."
5394 echo -e " Running: git subtree pull --prefix lib/vscode vscode release/${VSCODE_VERSION_TO_UPDATE} --squash\n"
5495 # Try to run subtree update command
55- git subtree pull --prefix lib/vscode vscode release/" ${VSCODE_VERSION_TO_UPDATE} " --squash --message " chore(vscode): update to $VSCODE_VERSION_TO_UPDATE "
96+ # Note: we add `|| true` because we want the script to keep running even if the squash fails
97+ # We know the squash fails everytime because there will always be merge conflicts
98+ git subtree pull --prefix lib/vscode vscode release/" ${VSCODE_VERSION_TO_UPDATE} " --squash || true
99+
100+ # Get the files with conflicts before we commit them
101+ # so we can list them in the PR body
102+ CONFLICTS=$( git diff --name-only --diff-filter=U | while read -r line; do echo " - $line " ; done)
103+ PR_BODY=$( make_pr_body " $VSCODE_EXACT_VERSION " " $CONFLICTS " )
104+
105+ echo -e " \nForcing a commit with conflicts"
106+ echo " Note: this is intentional"
107+ echo " If we don't do this, code review is impossible."
108+ echo -e " For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code\n"
109+ # We need --no-verify to skip the husky pre-commit hook
110+ # which fails because of the merge conflicts
111+ git add . && git commit -am " chore(vscode): update to $VSCODE_EXACT_VERSION " --no-verify
112+
113+ # Note: we can't open a draft PR unless their are changes.
114+ # Hence why we do this after the subtree update.
115+ echo " Opening a draft PR on GitHub"
116+ # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create
117+ gh pr create --base main --title " feat(vscode): update to version $VSCODE_EXACT_VERSION " --body " $PR_BODY " --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft
56118}
57119
58120main " $@ "
0 commit comments