From f19ae171eaac012f974df6e85790baa30f0dac48 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 10 Mar 2021 15:09:00 -0700 Subject: [PATCH 1/6] feat(update-vscode): grab latest vscode version --- ci/dev/update-vscode.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index 3ae7090a..1238d984 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -8,9 +8,8 @@ main() { # if it doesn't, we add it if ! git config remote.vscode.url > /dev/null; then echo "Could not find 'vscode' as a remote" - echo "Adding with: git remote add -f vscode https://github.com/microsoft/vscode.git &> /dev/null" - echo "Supressing output with '&> /dev/null'" - git remote add -f vscode https://github.com/microsoft/vscode.git &> /dev/null + echo "Adding with: git remote add vscode https://github.com/microsoft/vscode.git" + git remote add vscode https://github.com/microsoft/vscode.git fi # Ask which version we should update to @@ -25,7 +24,18 @@ main() { exit 1 fi - echo -e "Great! We'll prep a PR for updating to $VSCODE_VERSION_TO_UPDATE\n" + # Check that they have jq installed + if ! command -v jq &> /dev/null; then + echo "jq could not be found." + echo "We use this when looking up the exact version to update to in the package.json in VS Code." + echo -e "See docs here: https://stedolan.github.io/jq/download/" + exit + fi + + # Grab the exact version from package.json + VSCODE_EXACT_VERSION=$(curl -s "https://raw.githubusercontent.com/microsoft/vscode/release/$VSCODE_VERSION_TO_UPDATE/package.json" | jq -r ".version") + + echo -e "Great! We'll prep a PR for updating to $VSCODE_EXACT_VERSION\n" # Check if GitHub CLI is installed if ! command -v gh &> /dev/null; then @@ -47,7 +57,7 @@ main() { echo "Opening 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 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 + gh pr create --base master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body "This PR updates vscode to version: $VSCODE_EXACT_VERSION" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft echo "Going to try to update vscode for you..." echo -e "Running: git subtree pull --prefix lib/vscode vscode release/${VSCODE_VERSION_TO_UPDATE} --squash\n" From 612b8314f993aff027d8a5b25408871a4fe882fa Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 10 Mar 2021 15:27:55 -0700 Subject: [PATCH 2/6] feat(update-vscode): add step to commit files --- ci/dev/update-vscode.sh | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index 1238d984..d780345c 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -1,6 +1,23 @@ #!/usr/bin/env bash set -euo pipefail +# This function expects two arguments +# 1. the vscode version we're updating to +# 2. the list of merge conflict files +make_pr_body(){ + local BODY="This PR updates vscode to $1 + +## TODOS + +- [ ] test editor locally +- [ ] test terminal locally +- [ ] make notes about any significant changes in docs/CONTRIBUTING.md#notes-about-changes + +## Files with conflicts (fix these) +$2" + echo "$BODY" +} + main() { cd "$(dirname "$0")/../.." @@ -37,6 +54,12 @@ main() { echo -e "Great! We'll prep a PR for updating to $VSCODE_EXACT_VERSION\n" + # For some reason the subtree update doesn't work + # unless we fetch all the branches + echo -e "Fetching vscode branches..." + echo -e "Note: this might take a while" + git fetch vscode + # Check if GitHub CLI is installed if ! command -v gh &> /dev/null; then echo "GitHub CLI could not be found." @@ -55,14 +78,30 @@ main() { git push origin "$CURRENT_BRANCH" fi - echo "Opening 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 master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body "This PR updates vscode to version: $VSCODE_EXACT_VERSION" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft - echo "Going to try to update vscode for you..." echo -e "Running: git subtree pull --prefix lib/vscode vscode release/${VSCODE_VERSION_TO_UPDATE} --squash\n" # Try to run subtree update command - git subtree pull --prefix lib/vscode vscode release/"${VSCODE_VERSION_TO_UPDATE}" --squash --message "chore(vscode): update to $VSCODE_VERSION_TO_UPDATE" + # Note: we add `|| true` because we want the script to keep running even if the squash fails + # We know the squash fails everytime because there will always be merge conflicts + git subtree pull --prefix lib/vscode vscode release/"${VSCODE_VERSION_TO_UPDATE}" --squash || true + + # Get the files with conflicts before we commit them + # so we can list them in the PR body + CONFLICTS=$(git diff --name-only --diff-filter=U | while read line; do echo "- $line"; done) + + PR_BODY=$(make_pr_body $VSCODE_EXACT_VERSION $CONFLICTS) + + echo "Forcing a commit with conflicts" + echo "Note: this is intentional" + echo "If we don't do this, code review is impossible." + echo "For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code" + git add . && git commit -am "chore(vscode): update to $VSCODE_EXACT_VERSION" + + # Note: we can't open a draft PR unless their are changes. + # Hence why we do this after the subtree update. + echo "Opening 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 master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body $PR_BODY --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft } main "$@" From 3e79a84152894a79aae4780d956cebb61f2a5b86 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 10 Mar 2021 17:04:27 -0700 Subject: [PATCH 3/6] feat: add docs and update PR body --- ci/dev/update-vscode.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index d780345c..e934303b 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -1,10 +1,20 @@ #!/usr/bin/env bash +# Description: This is a script to make the process of updating vscode versions easier +# Run it with `yarn update:vscode` and it will do the following: +# 1. Check that you have a remote called `vscode` +# 2. Ask you which version you want to upgrade to +# 3. Grab the exact version from the package.json i.e. 1.53.2 +# 4. Fetch the vscode remote branches to run the subtree update +# 5. Run the subtree update and pull in the vscode update +# 6. Commit the changes (including merge conflicts) +# 7. Open a draft PR + set -euo pipefail # This function expects two arguments # 1. the vscode version we're updating to # 2. the list of merge conflict files -make_pr_body(){ +make_pr_body() { local BODY="This PR updates vscode to $1 ## TODOS @@ -87,21 +97,20 @@ main() { # Get the files with conflicts before we commit them # so we can list them in the PR body - CONFLICTS=$(git diff --name-only --diff-filter=U | while read line; do echo "- $line"; done) + CONFLICTS=$(git diff --name-only --diff-filter=U | while read -r line; do echo "- $line"; done) + PR_BODY=$(make_pr_body "$VSCODE_EXACT_VERSION" "$CONFLICTS") - PR_BODY=$(make_pr_body $VSCODE_EXACT_VERSION $CONFLICTS) - - echo "Forcing a commit with conflicts" + echo -e "\nForcing a commit with conflicts" echo "Note: this is intentional" echo "If we don't do this, code review is impossible." - echo "For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code" + echo -e "For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code\n" git add . && git commit -am "chore(vscode): update to $VSCODE_EXACT_VERSION" # Note: we can't open a draft PR unless their are changes. # Hence why we do this after the subtree update. echo "Opening 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 master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body $PR_BODY --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft + gh pr create --base master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body "$PR_BODY" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft } main "$@" From b0861029c06fb1320a335f2e45962141d83c5f69 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 11 Mar 2021 10:14:56 -0700 Subject: [PATCH 4/6] fix: add no-verify for commit line --- ci/dev/update-vscode.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index e934303b..960cd189 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -104,7 +104,9 @@ main() { echo "Note: this is intentional" echo "If we don't do this, code review is impossible." echo -e "For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code\n" - git add . && git commit -am "chore(vscode): update to $VSCODE_EXACT_VERSION" + # We need --no-verify to skip the husky pre-commit hook + # which fails because of the merge conflicts + git add . && git commit -am "chore(vscode): update to $VSCODE_EXACT_VERSION" --no-verify # Note: we can't open a draft PR unless their are changes. # Hence why we do this after the subtree update. From 6f638f1329061c297b5d5ea498482df218e1ebd1 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 11 Mar 2021 10:23:43 -0700 Subject: [PATCH 5/6] fix: set upstream when pushing branch --- ci/dev/update-vscode.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index 960cd189..0fc6ec9a 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -85,7 +85,9 @@ main() { if [[ -z $(git ls-remote --heads origin "$CURRENT_BRANCH") ]]; then echo "Doesn't look like you've pushed this branch to remote" echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n" - git push origin "$CURRENT_BRANCH" + # 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" fi echo "Going to try to update vscode for you..." From 44a4a0bc206a43d4e67843cf35e02c8ddb1dd19d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 11 Mar 2021 10:26:36 -0700 Subject: [PATCH 6/6] fix: update base branch to main --- ci/dev/update-vscode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/dev/update-vscode.sh b/ci/dev/update-vscode.sh index 0fc6ec9a..0c05a490 100755 --- a/ci/dev/update-vscode.sh +++ b/ci/dev/update-vscode.sh @@ -114,7 +114,7 @@ main() { # Hence why we do this after the subtree update. echo "Opening 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 master --title "feat(vscode): update to version $VSCODE_EXACT_VERSION" --body "$PR_BODY" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft + 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 } main "$@"