@@ -5,6 +5,21 @@ main() {
55 cd " $( dirname " $0 " ) /../.."
66 # Only sourcing this so we get access to $VERSION
77 source ./ci/lib.sh
8+ source ./ci/steps/steps-lib.sh
9+
10+ echo " Checking environment variables"
11+
12+ # We need VERSION to bump the brew formula
13+ if is_env_var_set " VERSION" ; then
14+ echo " VERSION is not set"
15+ exit 1
16+ fi
17+
18+ # We need HOMEBREW_GITHUB_API_TOKEN to push up commits
19+ if is_env_var_set " HOMEBREW_GITHUB_API_TOKEN" ; then
20+ echo " HOMEBREW_GITHUB_API_TOKEN is not set"
21+ exit 1
22+ fi
823
924 # NOTE: we need to make sure cdrci/homebrew-core
1025 # is up-to-date
@@ -13,27 +28,65 @@ main() {
1328 echo " Cloning cdrci/homebrew-core"
1429 git clone https://github.com/cdrci/homebrew-core.git
1530
31+ # 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."
34+ ls -la
35+ exit 1
36+ fi
37+
1638 echo " Changing into homebrew-core directory"
17- cd homebrew-core && pwd
39+ pushd homebrew-core && pwd
1840
19- echo " Adding Homebrew/homebrew-core as $( upstream ) "
41+ echo " Adding Homebrew/homebrew-core"
2042 git remote add upstream https://github.com/Homebrew/homebrew-core.git
2143
44+ # Make sure the git remote step is successful
45+ if ! git config remote.upstream.url > /dev/null; then
46+ echo " git remote add upstream failed."
47+ echo " Could not find upstream in list of remotes."
48+ git remote -v
49+ exit 1
50+ fi
51+
52+ # TODO@jsjoeio - can I somehow check that this succeeded?
2253 echo " Fetching upstream Homebrew/hombrew-core commits"
2354 git fetch upstream
2455
56+ # TODO@jsjoeio - can I somehow check that this succeeded?
2557 echo " Merging in latest Homebrew/homebrew-core changes"
2658 git merge upstream/master
2759
2860 echo " Pushing changes to cdrci/homebrew-core fork on GitHub"
61+
62+ # GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
63+ # See: https://serverfault.com/a/912788
64+ PATH_TO_GIT_ASKPASS=" $HOME /git-askpass.sh"
2965 # Source: https://serverfault.com/a/912788
3066 # shellcheck disable=SC2016,SC2028
31- echo ' #!/bin/sh\nexec echo "$HOMEBREW_GITHUB_API_TOKEN"' > " $HOME " /.git-askpass.sh
67+ echo ' echo $HOMEBREW_GITHUB_API_TOKEN' > " $PATH_TO_ASKPASS "
68+
69+ # Make sure the git-askpass.sh file creation is successful
70+ if file_exists " $PATH_TO_GIT_ASKPASS " ; then
71+ echo " git-askpass.sh not found in $HOME ."
72+ ls -la " $HOME "
73+ exit 1
74+ fi
75+
3276 # Ensure it's executable since we just created it
33- chmod +x " $HOME /.git-askpass.sh"
34- # GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
35- # See: https://serverfault.com/a/912788
36- GIT_ASKPASS=" $HOME /.git-askpass.sh" git push https://cdr-oss@github.com/cdr-oss/homebrew-core.git --all
77+ chmod +x " $PATH_TO_GIT_ASKPASS "
78+
79+ # Make sure the git-askpass.sh file is executable
80+ if is_executable " $PATH_TO_GIT_ASKPASS " ; then
81+ echo " $PATH_TO_GIT_ASKPASS is not executable."
82+ ls -la " $PATH_TO_GIT_ASKPASS "
83+ exit 1
84+ fi
85+
86+ # Export the variables so git sees them
87+ export HOMEBREW_GITHUB_API_TOKEN=" $HOMEBREW_GITHUB_API_TOKEN "
88+ export GIT_ASKPASS=" $PATH_TO_ASKPASS "
89+ git push https://cdr-oss@github.com/cdr-oss/homebrew-core.git --all
3790
3891 # Find the docs for bump-formula-pr here
3992 # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
@@ -48,8 +101,14 @@ main() {
48101 fi
49102
50103 # Clean up and remove homebrew-core
51- cd ..
104+ popd
52105 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
53112}
54113
55114main " $@ "
0 commit comments