|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +main() { |
| 5 | + cd "$(dirname "$0")/../.." |
| 6 | + |
| 7 | + # Check if the remote exists |
| 8 | + # if it doesn't, we add it |
| 9 | + if ! git config remote.vscode.url > /dev/null; then |
| 10 | + 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 |
| 14 | + fi |
| 15 | + |
| 16 | + # Ask which version we should update to |
| 17 | + # In the future, we'll automate this and grab the latest version automatically |
| 18 | + read -p "What version of VSCode would you like to update to? (i.e. 1.52) " VSCODE_VERSION_TO_UPDATE |
| 19 | + |
| 20 | + # Check that this version exists |
| 21 | + if [[ -z $(git ls-remote --heads vscode release/$VSCODE_VERSION_TO_UPDATE) ]]; then |
| 22 | + echo "Oops, that doesn't look like a valid version." |
| 23 | + echo "You entered: $VSCODE_VERSION_TO_UPDATE" |
| 24 | + echo "Verify that this branches exists here: https://github.com/microsoft/vscode/branches/all?query=release%2F$VSCODE_VERSION_TO_UPDATE" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + echo -e "Great! We'll prep a PR for updating to $VSCODE_VERSION_TO_UPDATE\n" |
| 29 | + |
| 30 | + # Check if GitHub CLI is installed |
| 31 | + if ! command -v gh &> /dev/null; then |
| 32 | + echo "GitHub CLI could not be found." |
| 33 | + echo "If you install it before you run this script next time, we'll open a draft PR for you!" |
| 34 | + echo -e "See docs here: https://github.com/cli/cli#installation\n" |
| 35 | + exit |
| 36 | + fi |
| 37 | + |
| 38 | + # Push branch to remote if not already pushed |
| 39 | + # If we don't do this, the opening a draft PR step won't work |
| 40 | + # because it will stop and ask where you want to push the branch |
| 41 | + CURRENT_BRANCH=$(git branch --show-current) |
| 42 | + if [[ -z $(git ls-remote --heads origin $CURRENT_BRANCH) ]]; then |
| 43 | + echo "Doesn't look like you've pushed this branch to remote" |
| 44 | + echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n" |
| 45 | + git push origin $CURRENT_BRANCH |
| 46 | + fi |
| 47 | + |
| 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 `/lib/vscode` to version: $VSCODE_VERSION_TO_UPDATE" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft |
| 51 | + |
| 52 | + |
| 53 | + echo "Going to try to update vscode for you..." |
| 54 | + echo -e "Running: git subtree pull --prefix lib/vscode vscode release/${VSCODE_VERSION_TO_UPDATE} --squash\n" |
| 55 | + # Try to run subtree update command |
| 56 | + git subtree pull --prefix lib/vscode vscode release/${VSCODE_VERSION_TO_UPDATE} --squash --message "chore(vscode): update to $VSCODE_VERSION_TO_UPDATE" |
| 57 | +} |
| 58 | + |
| 59 | +main "$@" |
0 commit comments