Skip to content

refactor: fix brew-bump.sh script and automate homebrew releases #4996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 21, 2022
11 changes: 10 additions & 1 deletion .github/workflows/npm-brew.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ jobs:
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- uses: actions/checkout@v3
- name: Checkout code-server
uses: actions/checkout@v3

- name: Checkout cdrci/homebrew-core
uses: actions/checkout@v3
with:
repository: cdrci/homebrew-core
path: homebrew-core

- name: Configure git
run: |
git config user.name github-actions
git config user.email [email protected]

- name: Bump code-server homebrew version
env:
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
Expand Down
56 changes: 22 additions & 34 deletions ci/steps/brew-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
set -euo pipefail

main() {
cd "$(dirname "$0")/../.."
REPO="homebrew-core"
GITHUB_USERNAME="cdrci"
UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO"
# Only sourcing this so we get access to $VERSION
source ./ci/lib.sh
source ./ci/steps/steps-lib.sh
Expand All @@ -21,25 +23,18 @@ main() {
exit 1
fi

# NOTE: we need to make sure coderci/homebrew-core
# is up-to-date
# otherwise, brew bump-formula-pr will use an
# outdated base
echo "Cloning coderci/homebrew-core"
git clone https://github.com/coderci/homebrew-core.git

# Make sure the git clone step is successful
if directory_exists "homebrew-core"; then
echo "git clone failed. Cannot find homebrew-core directory."
if ! directory_exists "$REPO"; then
echo "git clone failed. Cannot find $REPO directory."
ls -la
exit 1
fi

echo "Changing into homebrew-core directory"
pushd homebrew-core && pwd
echo "Changing into $REPO directory"
pushd "$REPO" && pwd

echo "Adding Homebrew/homebrew-core"
git remote add upstream https://github.com/Homebrew/homebrew-core.git
echo "Adding $UPSTREAM_USERNAME_AND_REPO"
git remote add upstream "https://github.com/$UPSTREAM_USERNAME_AND_REPO.git"

# Make sure the git remote step is successful
if ! git config remote.upstream.url > /dev/null; then
Expand All @@ -50,24 +45,22 @@ main() {
fi

# TODO@jsjoeio - can I somehow check that this succeeded?
echo "Fetching upstream Homebrew/hombrew-core commits"
git fetch upstream
echo "Fetching upstream $UPSTREAM_USERNAME_AND_REPO commits"
git fetch upstream master

# TODO@jsjoeio - can I somehow check that this succeeded?
echo "Merging in latest Homebrew/homebrew-core changes"
echo "Merging in latest $UPSTREAM_USERNAME_AND_REPO changes branch master"
git merge upstream/master

echo "Pushing changes to coderci/homebrew-core fork on GitHub"

# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
# See: https://serverfault.com/a/912788
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
# Source: https://serverfault.com/a/912788
# shellcheck disable=SC2016,SC2028
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_GIT_ASKPASS"

# Make sure the git-askpass.sh file creation is successful
if file_exists "$PATH_TO_GIT_ASKPASS"; then
if ! file_exists "$PATH_TO_GIT_ASKPASS"; then
echo "git-askpass.sh not found in $HOME."
ls -la "$HOME"
exit 1
Expand All @@ -77,38 +70,33 @@ main() {
chmod +x "$PATH_TO_GIT_ASKPASS"

# Make sure the git-askpass.sh file is executable
if is_executable "$PATH_TO_GIT_ASKPASS"; then
if ! is_executable "$PATH_TO_GIT_ASKPASS"; then
echo "$PATH_TO_GIT_ASKPASS is not executable."
ls -la "$PATH_TO_GIT_ASKPASS"
exit 1
fi

# 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"
# Export the variables so git sees them
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
export GIT_ASKPASS="$PATH_TO_ASKPASS"
git push https://coder-oss@github.com/coder-oss/homebrew-core.git --all
export GIT_ASKPASS="$PATH_TO_GIT_ASKPASS"
git push "https://$GITHUB_USERNAME@github.com/$GITHUB_USERNAME/$REPO.git" --all

# Find the docs for bump-formula-pr here
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
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"
exit 0
else
echo "$output"
exit 1
fi
fi

# Clean up and remove homebrew-core
popd
rm -rf homebrew-core

# Make sure homebrew-core is removed
if directory_exists "homebrew-core"; then
echo "rm -rf homebrew-core failed."
ls -la
fi
}

main "$@"