Skip to content

Commit f408b78

Browse files
committed
refactor: clean up brew-bump.sh script
1 parent fca292f commit f408b78

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

.github/workflows/npm-brew.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ jobs:
5252
- name: Checkout code-server
5353
uses: actions/checkout@v3
5454

55-
- name: Checkout coder/homebrew-core
55+
- name: Checkout cdrci/homebrew-core
5656
uses: actions/checkout@v3
5757
with:
58-
repository: coder/homebrew-core
58+
repository: cdrci/homebrew-core
5959

6060
- name: Configure git
6161
run: |

ci/steps/brew-bump.sh

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
set -euo pipefail
33

44
main() {
5-
cd "$(dirname "$0")/../.."
5+
REPO="homebrew-core"
6+
GITHUB_USERNAME="cdrci"
7+
UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO"
68
# Only sourcing this so we get access to $VERSION
7-
source ./ci/lib.sh
8-
source ./ci/steps/steps-lib.sh
9+
source ./lib.sh
10+
source ./steps-lib.sh
911

1012
echo "Checking environment variables"
1113

@@ -22,17 +24,17 @@ main() {
2224
fi
2325

2426
# Make sure the git clone step is successful
25-
if ! directory_exists "homebrew-core"; then
26-
echo "git clone failed. Cannot find homebrew-core directory."
27+
if ! directory_exists "$REPO"; then
28+
echo "git clone failed. Cannot find $REPO directory."
2729
ls -la
2830
exit 1
2931
fi
3032

31-
echo "Changing into homebrew-core directory"
32-
pushd homebrew-core && pwd
33+
echo "Changing into $REPO directory"
34+
pushd "$REPO" && pwd
3335

34-
echo "Adding Homebrew/homebrew-core"
35-
git remote add upstream https://github.com/Homebrew/homebrew-core.git
36+
echo "Adding $UPSTREAM_USERNAME_AND_REPO"
37+
git remote add upstream "https://github.com/$UPSTREAM_USERNAME_AND_REPO.git"
3638

3739
# Make sure the git remote step is successful
3840
if ! git config remote.upstream.url > /dev/null; then
@@ -43,21 +45,19 @@ main() {
4345
fi
4446

4547
# TODO@jsjoeio - can I somehow check that this succeeded?
46-
echo "Fetching upstream Homebrew/hombrew-core commits"
47-
git fetch upstream
48+
echo "Fetching upstream $UPSTREAM_USERNAME_AND_REPO commits"
49+
git fetch upstream master
4850

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

53-
echo "Pushing changes to coderci/homebrew-core fork on GitHub"
54-
5555
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
5656
# See: https://serverfault.com/a/912788
5757
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
5858
# Source: https://serverfault.com/a/912788
5959
# shellcheck disable=SC2016,SC2028
60-
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
60+
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_GIT_ASKPASS"
6161

6262
# Make sure the git-askpass.sh file creation is successful
6363
if ! file_exists "$PATH_TO_GIT_ASKPASS"; then
@@ -76,30 +76,27 @@ main() {
7676
exit 1
7777
fi
7878

79+
# NOTE: we need to make sure our fork is up-to-date
80+
# otherwise, brew bump-formula-pr will use an
81+
# outdated base
82+
echo "Pushing changes to $GITHUB_USERNAME/$REPO fork on GitHub"
7983
# Export the variables so git sees them
8084
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
81-
export GIT_ASKPASS="$PATH_TO_ASKPASS"
82-
git push https://coder-oss@github.com/coder-oss/homebrew-core.git --all
85+
export GIT_ASKPASS="$PATH_TO_GIT_ASKPASS"
86+
git push "https://$GITHUB_USERNAME@github.com/$GITHUB_USERNAME/$REPO.git" --all
8387

8488
# Find the docs for bump-formula-pr here
8589
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
86-
local output
87-
if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then
88-
if [[ $output == *"Duplicate PRs should not be opened"* ]]; then
89-
echo "$VERSION is already submitted"
90-
else
91-
echo "$output"
92-
exit 1
93-
fi
94-
fi
90+
# local output
91+
brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit
9592

9693
# Clean up and remove homebrew-core
9794
popd
98-
rm -rf homebrew-core
95+
rm -rf "$REPO"
9996

100-
# Make sure homebrew-core is removed
101-
if directory_exists "homebrew-core"; then
102-
echo "rm -rf homebrew-core failed."
97+
# Make sure $REPO is removed
98+
if directory_exists "$REPO"; then
99+
echo "rm -rf $REPO failed."
103100
ls -la
104101
fi
105102
}

0 commit comments

Comments
 (0)