2021-02-25 03:49:48 +07:00
|
|
|
#!/usr/bin/env bash
|
2021-03-11 07:04:27 +07:00
|
|
|
# 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
|
|
|
|
|
2021-02-25 03:49:48 +07:00
|
|
|
set -euo pipefail
|
|
|
|
|
2021-03-11 05:27:55 +07:00
|
|
|
# This function expects two arguments
|
|
|
|
# 1. the vscode version we're updating to
|
|
|
|
# 2. the list of merge conflict files
|
2021-03-11 07:04:27 +07:00
|
|
|
make_pr_body() {
|
2021-03-11 05:27:55 +07:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2021-02-25 03:49:48 +07:00
|
|
|
main() {
|
|
|
|
cd "$(dirname "$0")/../.."
|
|
|
|
|
|
|
|
# Check if the remote exists
|
|
|
|
# if it doesn't, we add it
|
2021-06-28 23:36:55 +07:00
|
|
|
if ! git config remote.vscode.url > /dev/null; then
|
2021-02-25 03:49:48 +07:00
|
|
|
echo "Could not find 'vscode' as a remote"
|
2021-03-11 05:09:00 +07:00
|
|
|
echo "Adding with: git remote add vscode https://github.com/microsoft/vscode.git"
|
|
|
|
git remote add vscode https://github.com/microsoft/vscode.git
|
2021-02-25 03:49:48 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Ask which version we should update to
|
|
|
|
# In the future, we'll automate this and grab the latest version automatically
|
2021-02-26 02:40:49 +07:00
|
|
|
read -r -p "What version of VSCode would you like to update to? (i.e. 1.52) " VSCODE_VERSION_TO_UPDATE
|
2021-02-25 03:49:48 +07:00
|
|
|
|
|
|
|
# Check that this version exists
|
2021-02-26 02:40:49 +07:00
|
|
|
if [[ -z $(git ls-remote --heads vscode release/"$VSCODE_VERSION_TO_UPDATE") ]]; then
|
2021-02-25 03:49:48 +07:00
|
|
|
echo "Oops, that doesn't look like a valid version."
|
|
|
|
echo "You entered: $VSCODE_VERSION_TO_UPDATE"
|
|
|
|
echo "Verify that this branches exists here: https://github.com/microsoft/vscode/branches/all?query=release%2F$VSCODE_VERSION_TO_UPDATE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-11 05:09:00 +07:00
|
|
|
# Check that they have jq installed
|
2021-06-28 23:36:55 +07:00
|
|
|
if ! command -v jq &> /dev/null; then
|
2021-03-11 05:09:00 +07:00
|
|
|
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/"
|
2021-04-16 02:37:28 +07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Note: `git subtree` returns 129 when installed, and prints help;
|
|
|
|
# but when uninstalled, returns 1.
|
|
|
|
set +e
|
2021-06-28 23:36:55 +07:00
|
|
|
git subtree &> /dev/null
|
2021-04-16 02:37:28 +07:00
|
|
|
if [ $? -ne 129 ]; then
|
|
|
|
echo "git-subtree could not be found."
|
|
|
|
echo "We use this to fetch and update the lib/vscode subtree."
|
|
|
|
echo -e "Please install git subtree."
|
|
|
|
exit 1
|
2021-03-11 05:09:00 +07:00
|
|
|
fi
|
2021-04-16 02:37:28 +07:00
|
|
|
set -e
|
2021-03-11 05:09:00 +07:00
|
|
|
|
|
|
|
# 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"
|
2021-02-25 03:49:48 +07:00
|
|
|
|
2021-03-11 05:27:55 +07:00
|
|
|
# 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
|
|
|
|
|
2021-02-25 03:49:48 +07:00
|
|
|
# Check if GitHub CLI is installed
|
2021-06-28 23:36:55 +07:00
|
|
|
if ! command -v gh &> /dev/null; then
|
2021-02-26 02:32:05 +07:00
|
|
|
echo "GitHub CLI could not be found."
|
|
|
|
echo "If you install it before you run this script next time, we'll open a draft PR for you!"
|
|
|
|
echo -e "See docs here: https://github.com/cli/cli#installation\n"
|
|
|
|
exit
|
2021-02-25 03:49:48 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
2021-03-25 06:35:55 +07:00
|
|
|
CURRENT_BRANCH=$(git branch | grep '\*' | cut -d' ' -f2-)
|
|
|
|
if [[ -z $(git config "branch.${CURRENT_BRANCH}.remote") ]]; then
|
2021-02-25 03:49:48 +07:00
|
|
|
echo "Doesn't look like you've pushed this branch to remote"
|
|
|
|
echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n"
|
2021-03-12 00:23:43 +07:00
|
|
|
# Note: we need to set upstream as well or the gh pr create step will fail
|
|
|
|
# See: https://github.com/cli/cli/issues/575
|
2021-03-25 06:35:55 +07:00
|
|
|
echo "Please set the upstream and re-run the script"
|
|
|
|
exit 1
|
2021-02-25 03:49:48 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
2021-03-11 05:27:55 +07:00
|
|
|
# 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
|
2021-03-12 00:50:06 +07:00
|
|
|
# so we can list them in the PR body as todo items
|
|
|
|
CONFLICTS=$(git diff --name-only --diff-filter=U | while read -r line; do echo "- [ ] $line"; done)
|
2021-03-11 07:04:27 +07:00
|
|
|
PR_BODY=$(make_pr_body "$VSCODE_EXACT_VERSION" "$CONFLICTS")
|
2021-03-11 05:27:55 +07:00
|
|
|
|
2021-03-11 07:04:27 +07:00
|
|
|
echo -e "\nForcing a commit with conflicts"
|
2021-03-11 05:27:55 +07:00
|
|
|
echo "Note: this is intentional"
|
|
|
|
echo "If we don't do this, code review is impossible."
|
2021-03-11 07:04:27 +07:00
|
|
|
echo -e "For more info, see docs: docs/CONTRIBUTING.md#updating-vs-code\n"
|
2021-03-12 00:14:56 +07:00
|
|
|
# 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
|
2021-03-11 05:27:55 +07:00
|
|
|
|
|
|
|
# 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
|
2021-03-12 00:26:36 +07:00
|
|
|
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
|
2021-02-25 03:49:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|