2
2
set -euo pipefail
3
3
4
4
main () {
5
- cd " $( dirname " $0 " ) /../.."
5
+ REPO=" homebrew-core"
6
+ GITHUB_USERNAME=" cdrci"
7
+ UPSTREAM_USERNAME_AND_REPO=" Homebrew/$REPO "
6
8
# Only sourcing this so we get access to $VERSION
7
9
source ./ci/lib.sh
8
10
source ./ci/steps/steps-lib.sh
@@ -21,25 +23,18 @@ main() {
21
23
exit 1
22
24
fi
23
25
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
-
31
26
# 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."
34
29
ls -la
35
30
exit 1
36
31
fi
37
32
38
- echo " Changing into homebrew-core directory"
39
- pushd homebrew-core && pwd
33
+ echo " Changing into $REPO directory"
34
+ pushd " $REPO " && pwd
40
35
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"
43
38
44
39
# Make sure the git remote step is successful
45
40
if ! git config remote.upstream.url > /dev/null; then
@@ -50,24 +45,22 @@ main() {
50
45
fi
51
46
52
47
# 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
55
50
56
51
# 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 "
58
53
git merge upstream/master
59
54
60
- echo " Pushing changes to coderci/homebrew-core fork on GitHub"
61
-
62
55
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
63
56
# See: https://serverfault.com/a/912788
64
57
PATH_TO_GIT_ASKPASS=" $HOME /git-askpass.sh"
65
58
# Source: https://serverfault.com/a/912788
66
59
# 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 "
68
61
69
62
# 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
71
64
echo " git-askpass.sh not found in $HOME ."
72
65
ls -la " $HOME "
73
66
exit 1
@@ -77,38 +70,33 @@ main() {
77
70
chmod +x " $PATH_TO_GIT_ASKPASS "
78
71
79
72
# 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
81
74
echo " $PATH_TO_GIT_ASKPASS is not executable."
82
75
ls -la " $PATH_TO_GIT_ASKPASS "
83
76
exit 1
84
77
fi
85
78
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"
86
83
# Export the variables so git sees them
87
84
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
90
87
91
88
# Find the docs for bump-formula-pr here
92
89
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
93
90
local output
94
91
if ! output=$( brew bump-formula-pr --version=" ${VERSION} " code-server --no-browse --no-audit 2>&1 ) ; then
95
92
if [[ $output == * " Duplicate PRs should not be opened" * ]]; then
96
93
echo " $VERSION is already submitted"
94
+ exit 0
97
95
else
98
96
echo " $output "
99
97
exit 1
100
98
fi
101
99
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
112
100
}
113
101
114
102
main " $@ "
0 commit comments