2021-04-01 05:55:43 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
main() {
|
2022-03-22 07:57:36 +08:00
|
|
|
REPO="homebrew-core"
|
|
|
|
GITHUB_USERNAME="cdrci"
|
|
|
|
UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO"
|
2021-04-01 05:55:43 +08:00
|
|
|
# Only sourcing this so we get access to $VERSION
|
|
|
|
source ./ci/lib.sh
|
2021-09-24 07:08:28 +08:00
|
|
|
source ./ci/steps/steps-lib.sh
|
|
|
|
|
|
|
|
echo "Checking environment variables"
|
|
|
|
|
|
|
|
# We need VERSION to bump the brew formula
|
2022-01-13 06:51:11 +08:00
|
|
|
if ! is_env_var_set "VERSION"; then
|
2021-09-24 07:08:28 +08:00
|
|
|
echo "VERSION is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We need HOMEBREW_GITHUB_API_TOKEN to push up commits
|
2022-01-13 06:51:11 +08:00
|
|
|
if ! is_env_var_set "HOMEBREW_GITHUB_API_TOKEN"; then
|
2021-09-24 07:08:28 +08:00
|
|
|
echo "HOMEBREW_GITHUB_API_TOKEN is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-22 05:56:01 +08:00
|
|
|
|
2021-09-24 07:08:28 +08:00
|
|
|
# Make sure the git clone step is successful
|
2022-03-22 07:57:36 +08:00
|
|
|
if ! directory_exists "$REPO"; then
|
|
|
|
echo "git clone failed. Cannot find $REPO directory."
|
2021-09-24 07:08:28 +08:00
|
|
|
ls -la
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-22 07:57:36 +08:00
|
|
|
echo "Changing into $REPO directory"
|
|
|
|
pushd "$REPO" && pwd
|
2021-05-22 05:56:01 +08:00
|
|
|
|
2022-03-22 07:57:36 +08:00
|
|
|
echo "Adding $UPSTREAM_USERNAME_AND_REPO"
|
|
|
|
git remote add upstream "https://github.com/$UPSTREAM_USERNAME_AND_REPO.git"
|
2021-05-22 05:56:01 +08:00
|
|
|
|
2021-09-24 07:08:28 +08:00
|
|
|
# Make sure the git remote step is successful
|
|
|
|
if ! git config remote.upstream.url > /dev/null; then
|
|
|
|
echo "git remote add upstream failed."
|
|
|
|
echo "Could not find upstream in list of remotes."
|
|
|
|
git remote -v
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO@jsjoeio - can I somehow check that this succeeded?
|
2022-03-22 07:57:36 +08:00
|
|
|
echo "Fetching upstream $UPSTREAM_USERNAME_AND_REPO commits"
|
|
|
|
git fetch upstream master
|
2021-05-22 05:56:01 +08:00
|
|
|
|
2021-09-24 07:08:28 +08:00
|
|
|
# TODO@jsjoeio - can I somehow check that this succeeded?
|
2022-03-22 07:57:36 +08:00
|
|
|
echo "Merging in latest $UPSTREAM_USERNAME_AND_REPO changes branch master"
|
2021-05-22 05:56:01 +08:00
|
|
|
git merge upstream/master
|
|
|
|
|
2021-09-24 07:08:28 +08:00
|
|
|
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
|
|
|
|
# See: https://serverfault.com/a/912788
|
2021-09-25 06:26:20 +08:00
|
|
|
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
|
2021-05-25 07:47:55 +08:00
|
|
|
# Source: https://serverfault.com/a/912788
|
|
|
|
# shellcheck disable=SC2016,SC2028
|
2022-03-22 07:57:36 +08:00
|
|
|
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_GIT_ASKPASS"
|
2021-09-24 07:08:28 +08:00
|
|
|
|
|
|
|
# Make sure the git-askpass.sh file creation is successful
|
2022-03-22 07:57:36 +08:00
|
|
|
if ! file_exists "$PATH_TO_GIT_ASKPASS"; then
|
2021-09-24 07:08:28 +08:00
|
|
|
echo "git-askpass.sh not found in $HOME."
|
|
|
|
ls -la "$HOME"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-26 05:18:04 +08:00
|
|
|
# Ensure it's executable since we just created it
|
2021-09-25 06:26:20 +08:00
|
|
|
chmod +x "$PATH_TO_GIT_ASKPASS"
|
2021-09-24 07:08:28 +08:00
|
|
|
|
|
|
|
# Make sure the git-askpass.sh file is executable
|
2022-03-22 07:57:36 +08:00
|
|
|
if ! is_executable "$PATH_TO_GIT_ASKPASS"; then
|
2021-09-25 06:26:20 +08:00
|
|
|
echo "$PATH_TO_GIT_ASKPASS is not executable."
|
|
|
|
ls -la "$PATH_TO_GIT_ASKPASS"
|
2021-09-24 07:08:28 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-22 07:57:36 +08:00
|
|
|
# NOTE: we need to make sure our fork is up-to-date
|
|
|
|
# otherwise, brew bump-formula-pr will use an
|
|
|
|
# outdated base
|
|
|
|
echo "Pushing changes to $GITHUB_USERNAME/$REPO fork on GitHub"
|
2021-09-25 06:26:20 +08:00
|
|
|
# Export the variables so git sees them
|
|
|
|
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
|
2022-03-22 07:57:36 +08:00
|
|
|
export GIT_ASKPASS="$PATH_TO_GIT_ASKPASS"
|
|
|
|
git push "https://$GITHUB_USERNAME@github.com/$GITHUB_USERNAME/$REPO.git" --all
|
2021-05-22 05:56:01 +08:00
|
|
|
|
2021-04-01 05:55:43 +08:00
|
|
|
# Find the docs for bump-formula-pr here
|
|
|
|
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
|
2021-07-17 06:02:18 +08:00
|
|
|
local output
|
|
|
|
if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then
|
|
|
|
if [[ $output == *"Duplicate PRs should not be opened"* ]]; then
|
|
|
|
echo "$VERSION is already submitted"
|
2022-03-22 07:57:36 +08:00
|
|
|
exit 0
|
2021-07-17 06:02:18 +08:00
|
|
|
else
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2021-04-01 05:55:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|