2021-03-31 21:55:43 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
main() {
|
|
|
|
cd "$(dirname "$0")/../.."
|
|
|
|
# Only sourcing this so we get access to $VERSION
|
|
|
|
source ./ci/lib.sh
|
2021-09-23 23:08:28 +00:00
|
|
|
source ./ci/steps/steps-lib.sh
|
|
|
|
|
|
|
|
echo "Checking environment variables"
|
|
|
|
|
|
|
|
# We need VERSION to bump the brew formula
|
|
|
|
if [[ $(is_env_var_set "VERSION") -eq 1 ]]; then
|
|
|
|
echo "VERSION is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We need HOMEBREW_GITHUB_API_TOKEN to push up commits
|
|
|
|
if [[ $(is_env_var_set "HOMEBREW_GITHUB_API_TOKEN") -eq 1 ]]; then
|
|
|
|
echo "HOMEBREW_GITHUB_API_TOKEN is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-21 21:56:01 +00:00
|
|
|
|
|
|
|
# NOTE: we need to make sure cdrci/homebrew-core
|
|
|
|
# is up-to-date
|
|
|
|
# otherwise, brew bump-formula-pr will use an
|
|
|
|
# outdated base
|
|
|
|
echo "Cloning cdrci/homebrew-core"
|
|
|
|
git clone https://github.com/cdrci/homebrew-core.git
|
|
|
|
|
2021-09-23 23:08:28 +00:00
|
|
|
# Make sure the git clone step is successful
|
|
|
|
if [[ $(directory_exists "homebrew-core") -eq 1 ]]; then
|
|
|
|
echo "git clone failed. Cannot find homebrew-core directory."
|
|
|
|
ls -la
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-21 21:56:01 +00:00
|
|
|
echo "Changing into homebrew-core directory"
|
|
|
|
cd homebrew-core && pwd
|
|
|
|
|
2021-09-23 23:08:28 +00:00
|
|
|
echo "Adding Homebrew/homebrew-core"
|
2021-05-21 21:56:01 +00:00
|
|
|
git remote add upstream https://github.com/Homebrew/homebrew-core.git
|
|
|
|
|
2021-09-23 23:08:28 +00: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?
|
2021-07-16 22:02:18 +00:00
|
|
|
echo "Fetching upstream Homebrew/hombrew-core commits"
|
2021-05-21 21:56:01 +00:00
|
|
|
git fetch upstream
|
|
|
|
|
2021-09-23 23:08:28 +00:00
|
|
|
# TODO@jsjoeio - can I somehow check that this succeeded?
|
2021-07-16 22:02:18 +00:00
|
|
|
echo "Merging in latest Homebrew/homebrew-core changes"
|
2021-05-21 21:56:01 +00:00
|
|
|
git merge upstream/master
|
|
|
|
|
|
|
|
echo "Pushing changes to cdrci/homebrew-core fork on GitHub"
|
2021-09-23 23:08:28 +00:00
|
|
|
|
|
|
|
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
|
|
|
|
# See: https://serverfault.com/a/912788
|
|
|
|
GIT_ASKPASS="$HOME/git-askpass.sh"
|
2021-05-24 23:47:55 +00:00
|
|
|
# Source: https://serverfault.com/a/912788
|
|
|
|
# shellcheck disable=SC2016,SC2028
|
2021-09-23 23:08:28 +00:00
|
|
|
echo '#!/bin/sh\nexec echo "$HOMEBREW_GITHUB_API_TOKEN"' > "$GIT_ASKPASS"
|
|
|
|
|
|
|
|
# Make sure the git-askpass.sh file creation is successful
|
|
|
|
if [[ $(file_exists "git-askpass.sh") -eq 1 ]]; then
|
|
|
|
echo "git-askpass.sh not found in $HOME."
|
|
|
|
ls -la "$HOME"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-25 21:18:04 +00:00
|
|
|
# Ensure it's executable since we just created it
|
2021-09-23 23:08:28 +00:00
|
|
|
chmod +x "$GIT_ASKPASS"
|
|
|
|
|
|
|
|
# Make sure the git-askpass.sh file is executable
|
|
|
|
if [[ $(is_executable "$GIT_ASKPASS") -eq 1 ]]; then
|
|
|
|
echo "git-askpass.sh is not executable."
|
|
|
|
ls -la "$GIT_ASKPASS"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git push https://cdr-oss@github.com/cdr-oss/homebrew-core.git --all
|
2021-05-21 21:56:01 +00:00
|
|
|
|
2021-03-31 21:55:43 +00: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-16 22:02:18 +00: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"
|
|
|
|
else
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2021-05-21 21:56:01 +00:00
|
|
|
|
|
|
|
# Clean up and remove homebrew-core
|
|
|
|
cd ..
|
|
|
|
rm -rf homebrew-core
|
2021-09-23 23:08:28 +00:00
|
|
|
|
|
|
|
# TODO@jsjoeio - check that homebrew-core was removed
|
2021-03-31 21:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|