Skip to content

Commit be72787

Browse files
authoredMar 21, 2022
refactor: checkout homebrew-core in action instead of script (#4996)
* refactor: checkout homebrew-core in action instead of script This moves the git clone step from the `brew-bump.sh` script into the `npm-brew.yaml` as part of the job using actions/checkout instead. * refactor: clean up brew-bump.sh script * fixup * fixup!: remove step to clean up homebrew repo * fixup!: use correct ./ci path steps-lib.sh * fixup!: add exit code 0 for duplicate PRs
1 parent 60ebf2f commit be72787

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed
 

‎.github/workflows/npm-brew.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,20 @@ jobs:
5656
id: set-up-homebrew
5757
uses: Homebrew/actions/setup-homebrew@master
5858

59-
- uses: actions/checkout@v3
59+
- name: Checkout code-server
60+
uses: actions/checkout@v3
61+
62+
- name: Checkout cdrci/homebrew-core
63+
uses: actions/checkout@v3
64+
with:
65+
repository: cdrci/homebrew-core
66+
path: homebrew-core
67+
6068
- name: Configure git
6169
run: |
6270
git config user.name github-actions
6371
git config user.email github-actions@github.com
72+
6473
- name: Bump code-server homebrew version
6574
env:
6675
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}

‎ci/steps/brew-bump.sh

+22-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
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
79
source ./ci/lib.sh
810
source ./ci/steps/steps-lib.sh
@@ -21,25 +23,18 @@ main() {
2123
exit 1
2224
fi
2325

24-
# NOTE: we need to make sure coderci/homebrew-core
25-
# is up-to-date
26-
# otherwise, brew bump-formula-pr will use an
27-
# outdated base
28-
echo "Cloning coderci/homebrew-core"
29-
git clone https://github.com/coderci/homebrew-core.git
30-
3126
# Make sure the git clone step is successful
32-
if directory_exists "homebrew-core"; then
33-
echo "git clone failed. Cannot find homebrew-core directory."
27+
if ! directory_exists "$REPO"; then
28+
echo "git clone failed. Cannot find $REPO directory."
3429
ls -la
3530
exit 1
3631
fi
3732

38-
echo "Changing into homebrew-core directory"
39-
pushd homebrew-core && pwd
33+
echo "Changing into $REPO directory"
34+
pushd "$REPO" && pwd
4035

41-
echo "Adding Homebrew/homebrew-core"
42-
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"
4338

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

5247
# TODO@jsjoeio - can I somehow check that this succeeded?
53-
echo "Fetching upstream Homebrew/hombrew-core commits"
54-
git fetch upstream
48+
echo "Fetching upstream $UPSTREAM_USERNAME_AND_REPO commits"
49+
git fetch upstream master
5550

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

60-
echo "Pushing changes to coderci/homebrew-core fork on GitHub"
61-
6255
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
6356
# See: https://serverfault.com/a/912788
6457
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
6558
# Source: https://serverfault.com/a/912788
6659
# shellcheck disable=SC2016,SC2028
67-
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
60+
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_GIT_ASKPASS"
6861

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

7972
# Make sure the git-askpass.sh file is executable
80-
if is_executable "$PATH_TO_GIT_ASKPASS"; then
73+
if ! is_executable "$PATH_TO_GIT_ASKPASS"; then
8174
echo "$PATH_TO_GIT_ASKPASS is not executable."
8275
ls -la "$PATH_TO_GIT_ASKPASS"
8376
exit 1
8477
fi
8578

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"
8683
# Export the variables so git sees them
8784
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
88-
export GIT_ASKPASS="$PATH_TO_ASKPASS"
89-
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
9087

9188
# Find the docs for bump-formula-pr here
9289
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
9390
local output
9491
if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then
9592
if [[ $output == *"Duplicate PRs should not be opened"* ]]; then
9693
echo "$VERSION is already submitted"
94+
exit 0
9795
else
9896
echo "$output"
9997
exit 1
10098
fi
10199
fi
102-
103-
# Clean up and remove homebrew-core
104-
popd
105-
rm -rf homebrew-core
106-
107-
# Make sure homebrew-core is removed
108-
if directory_exists "homebrew-core"; then
109-
echo "rm -rf homebrew-core failed."
110-
ls -la
111-
fi
112100
}
113101

114102
main "$@"

0 commit comments

Comments
 (0)
Please sign in to comment.