-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.sh
executable file
Β·169 lines (144 loc) Β· 6.36 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
set -euo pipefail
TEST_BOT="${1}"
DEBUG="${2}"
if [[ "${DEBUG}" == 'true' ]]; then
set -x
fi
MAX_GIT_RETRIES=5
function git_retry {
local try=0
until git "$@"; do
exit_code="$?"
try=$(($try + 1))
if [ $try -lt $MAX_GIT_RETRIES ]; then
sleep $((2 ** $try))
else
return $exit_code
fi
done
return 0
}
# Clone Homebrew/brew and Homebrew/linuxbrew-core if necessary.
if ! which brew &>/dev/null; then
HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew
HOMEBREW_REPOSITORY="$HOMEBREW_PREFIX/Homebrew"
sudo mkdir -p "$HOMEBREW_PREFIX"
sudo git_retry clone --depth=1 https://github.com/Homebrew/brew "$HOMEBREW_REPOSITORY"
HOMEBREW_CORE_REPOSITORY="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core"
sudo mkdir -p "$HOMEBREW_CORE_REPOSITORY"
sudo rm -rf "$HOMEBREW_CORE_REPOSITORY"
sudo git_retry clone --depth=1 https://github.com/Homebrew/linuxbrew-core "$HOMEBREW_CORE_REPOSITORY"
cd "$HOMEBREW_PREFIX"
sudo mkdir -p bin etc include lib opt sbin share var/homebrew/linked Cellar
sudo ln -vs ../Homebrew/bin/brew "$HOMEBREW_PREFIX/bin/"
cd -
export PATH="$HOMEBREW_PREFIX/bin:$PATH"
else
HOMEBREW_PREFIX="$(brew --prefix)"
HOMEBREW_REPOSITORY="$(brew --repo)"
HOMEBREW_CORE_REPOSITORY="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core"
fi
HOMEBREW_CASK_REPOSITORY="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-cask"
echo "::add-path::$HOMEBREW_PREFIX/bin"
# Setup Homebrew/brew
if [[ "$GITHUB_REPOSITORY" =~ ^.+/brew$ ]]; then
cd "$HOMEBREW_REPOSITORY"
rm -rf "$GITHUB_WORKSPACE"
if [[ -n "${GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED-}" ]]; then
mkdir -vp "$GITHUB_WORKSPACE"
else
ln -vs "$HOMEBREW_REPOSITORY" "$GITHUB_WORKSPACE"
fi
git remote set-url origin "https://github.com/$GITHUB_REPOSITORY"
git_retry fetch --tags origin "$GITHUB_SHA" '+refs/heads/*:refs/remotes/origin/*'
git remote set-head origin --auto
git checkout --force -B master FETCH_HEAD
cd -
else
git_retry -C "$HOMEBREW_REPOSITORY" fetch --force origin
git -C "$HOMEBREW_REPOSITORY" checkout --force -B master origin/HEAD
fi
# Setup Homebrew Bundler RubyGems cache
GEMS_PATH="$HOMEBREW_REPOSITORY/Library/Homebrew/vendor/bundle/ruby/"
GEMS_HASH="$(shasum -a 256 "$HOMEBREW_REPOSITORY/Library/Homebrew/Gemfile.lock" | cut -f1 -d' ')"
echo "::set-output name=gems-path::$GEMS_PATH"
echo "::set-output name=gems-hash::$GEMS_HASH"
# Setup Homebrew/(home|linux)brew-core tap
if [[ "$GITHUB_REPOSITORY" =~ ^.+/(home|linux)brew-core$ ]]; then
cd "$HOMEBREW_CORE_REPOSITORY"
rm -rf "$GITHUB_WORKSPACE"
if [[ -n "${GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED-}" ]]; then
mkdir -vp "$GITHUB_WORKSPACE"
else
ln -vs "$HOMEBREW_CORE_REPOSITORY" "$GITHUB_WORKSPACE"
fi
git remote set-url origin "https://github.com/$GITHUB_REPOSITORY"
git_retry fetch origin "$GITHUB_SHA" '+refs/heads/*:refs/remotes/origin/*'
git remote set-head origin --auto
git checkout --force -B master FETCH_HEAD
cd -
else
if [[ "$GITHUB_REPOSITORY" =~ ^.+/homebrew-.+$ ]]; then
if [[ -n "${GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED-}" ]]; then
echo "Self-hosted runners not supported for this tap!"
exit 1
fi
HOMEBREW_TAP_REPOSITORY="$(brew --repo "$GITHUB_REPOSITORY")"
if [[ "$GITHUB_REPOSITORY" =~ ^.+/homebrew-cask(-.+)*$ ]]; then
# Tap or update homebrew/cask for other cask repos.
if [[ "${HOMEBREW_TAP_REPOSITORY}" != "${HOMEBREW_CASK_REPOSITORY}" ]] && [[ -d "${HOMEBREW_CASK_REPOSITORY}" ]]; then
git_retry -C "$HOMEBREW_CASK_REPOSITORY" fetch --force origin
git -C "$HOMEBREW_CASK_REPOSITORY" remote set-head origin --auto
git -C "$HOMEBREW_CASK_REPOSITORY" checkout --force -B master origin/HEAD
elif ! [[ -d "${HOMEBREW_CASK_REPOSITORY}" ]]; then
git_retry clone --depth=1 https://github.com/Homebrew/homebrew-cask "${HOMEBREW_CASK_REPOSITORY}"
fi
for cask_repo in \
"${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-cask-drivers" \
"${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-cask-fonts" \
"${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-cask-versions"
do
if [[ "${HOMEBREW_TAP_REPOSITORY}" != "${cask_repo}" ]] && [[ -d "${cask_repo}" ]]; then
git_retry -C "${cask_repo}" fetch --force origin
git -C "${cask_repo}" remote set-head origin --auto
git -C "${cask_repo}" checkout --force -B master origin/HEAD
fi
done
fi
if [[ -d "$HOMEBREW_TAP_REPOSITORY" ]]; then
cd "$HOMEBREW_TAP_REPOSITORY"
git remote set-url origin "https://github.com/$GITHUB_REPOSITORY"
else
mkdir -vp "$HOMEBREW_TAP_REPOSITORY"
cd "$HOMEBREW_TAP_REPOSITORY"
git init
git remote add origin "https://github.com/$GITHUB_REPOSITORY"
fi
rm -rf "$GITHUB_WORKSPACE"
ln -vs "$HOMEBREW_TAP_REPOSITORY" "$GITHUB_WORKSPACE"
git_retry fetch origin "$GITHUB_SHA" '+refs/heads/*:refs/remotes/origin/*'
git remote set-head origin --auto
git checkout --force -B master FETCH_HEAD
cd -
fi
git_retry -C "$HOMEBREW_CORE_REPOSITORY" fetch --force origin
git -C "$HOMEBREW_CORE_REPOSITORY" remote set-head origin --auto
git -C "$HOMEBREW_CORE_REPOSITORY" checkout --force -B master origin/HEAD
fi
if [[ "${TEST_BOT}" == 'true' ]]; then
# Setup Homebrew/homebrew-test-bot
HOMEBREW_TEST_BOT_REPOSITORY="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-test-bot"
if ! [[ -d "$HOMEBREW_TEST_BOT_REPOSITORY" ]]; then
git_retry clone --depth=1 https://github.com/Homebrew/homebrew-test-bot "$HOMEBREW_TEST_BOT_REPOSITORY"
elif [[ "$GITHUB_REPOSITORY" != "Homebrew/homebrew-test-bot" ]]; then
git_retry -C "$HOMEBREW_TEST_BOT_REPOSITORY" fetch --force origin
git -C "$HOMEBREW_TEST_BOT_REPOSITORY" remote set-head origin --auto
git -C "$HOMEBREW_TEST_BOT_REPOSITORY" checkout --force -B master origin/HEAD
fi
fi
# Setup Linux permissions
if [[ "$RUNNER_OS" = "Linux" ]]; then
sudo chown -R "$(whoami)" "$HOMEBREW_PREFIX"
sudo chmod -R g-w,o-w /home/linuxbrew $HOME /opt
fi