-
-
Notifications
You must be signed in to change notification settings - Fork 17
283 lines (248 loc) · 9.89 KB
/
Copy pathtests.yml
File metadata and controls
283 lines (248 loc) · 9.89 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
---
name: brew test-bot
permissions: {}
env:
UBUNTU_VERSION: "24.04"
on:
push:
branches:
- master
pull_request:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
# Check syntax and detect which platforms need testing
setup:
uses: ./.github/workflows/_detect-formulas.yml
permissions:
contents: read
with:
base-sha: ${{ github.event.pull_request.base.sha || '' }}
before-sha: ${{ github.event.before || '' }}
event-name: ${{ github.event_name }}
head-sha: ${{ github.sha }}
run-homebrew-setup: true
# Build bottles on required platforms
build-bottles:
if: needs.setup.outputs.has-formulae == 'true'
needs: setup
permissions:
actions: read
checks: read
contents: read
packages: read
pull-requests: read
runs-on: ${{ matrix.os }}
strategy:
fail-fast: ${{ needs.setup.outputs.disable-failfast == 'false' }}
matrix:
os: ${{ fromJson(needs.setup.outputs.platforms) }}
steps:
- name: More space
if: runner.os == 'Linux'
uses: LizardByte/actions/actions/more_space@d0ae7f82215a479fe2b74f4088c53ee6460513dd # v2026.728.214955
with:
analyze-space-savings: true
clean-all: true
safe-packages: brew
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@main
with:
stable: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Select configured Xcode
if: runner.os == 'macOS'
env:
MATRIX_OS: ${{ matrix.os }}
TESTING_FORMULAE: ${{ needs.setup.outputs.testing-formulae }}
run: |
TAP_PATH="$(brew --repository "${GITHUB_REPOSITORY}")"
XCODE_CONFIG="${TAP_PATH}/ci_config/xcode_versions.json"
MACOS_VERSION="${MATRIX_OS#macos-}"
XCODE_VERSIONS=$(jq -r \
--arg formulae "${TESTING_FORMULAE}" \
--arg macos_version "${MACOS_VERSION}" \
'[($formulae | split(",")[]) as $formula |
.[$formula][$macos_version] // empty] | unique[]' \
"${XCODE_CONFIG}")
XCODE_VERSION_COUNT=$(printf '%s\n' "${XCODE_VERSIONS}" | sed '/^$/d' | wc -l | tr -d ' ')
if [ "${XCODE_VERSION_COUNT}" -eq 0 ]; then
echo "No custom Xcode version configured for macOS ${MACOS_VERSION}."
exit 0
fi
if [ "${XCODE_VERSION_COUNT}" -gt 1 ]; then
echo "Conflicting Xcode versions configured for ${TESTING_FORMULAE} on macOS ${MACOS_VERSION}:"
echo "${XCODE_VERSIONS}"
exit 1
fi
XCODE_PATH="/Applications/Xcode_${XCODE_VERSIONS}.app"
if [ ! -d "${XCODE_PATH}" ]; then
echo "Configured Xcode installation does not exist: ${XCODE_PATH}"
exit 1
fi
echo "Selecting Xcode ${XCODE_VERSIONS} for ${TESTING_FORMULAE} on macOS ${MACOS_VERSION}."
sudo xcode-select --switch "${XCODE_PATH}"
xcodebuild -version
- name: Cache Homebrew Bundler RubyGems
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ matrix.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
restore-keys: ${{ matrix.os }}-rubygems-
# TODO: periodically check if this gets fixed in Homebrew
# https://github.com/orgs/Homebrew/discussions/6615
# https://github.com/ruby/rubygems/issues/7983
- name: Fix ruby gems directory permissions
if: matrix.os == format('ubuntu-{0}-arm', env.UBUNTU_VERSION)
run: |
# Fix ownership first so current user can write, then remove world-writable
BUNDLE_DIR="$(brew --prefix)/Homebrew/Library/Homebrew/vendor/bundle/ruby"
if [ -d "${BUNDLE_DIR}" ]; then
# Take ownership so we can write to it
sudo chown -R "$(whoami):$(id -gn)" "${BUNDLE_DIR}"
# Remove world-writable permissions to satisfy Bundler security
chmod -R o-w "${BUNDLE_DIR}"
echo "Fixed ownership and permissions for ${BUNDLE_DIR}"
fi
- name: Brew cleanup before
run: brew test-bot --fail-fast --only-cleanup-before
# Homebrew's Linux sandbox requires bwrap on PATH before brew test-bot runs brew doctor.
# Install it after cleanup-before, which prunes formulae from the prefix.
# The sysctls enable the rootless user namespaces that bwrap needs to create the sandbox.
- name: Set up Homebrew Linux sandbox
if: runner.os == 'Linux'
run: |
brew install bubblewrap
sudo sysctl -w kernel.unprivileged_userns_clone=1
sudo sysctl -w user.max_user_namespaces=28633
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 || true
- name: Brew setup
run: brew test-bot --fail-fast --only-setup
- name: Base64-encode GITHUB_TOKEN for HOMEBREW_DOCKER_REGISTRY_TOKEN
id: base64-encode
if: github.event_name == 'pull_request'
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
base64_token=$(echo -n "${TOKEN}" | base64 | tr -d "\n")
echo "::add-mask::${base64_token}"
echo "token=${base64_token}" >> "${GITHUB_OUTPUT}"
- name: Build bottles
if: github.event_name == 'pull_request'
env:
HOMEBREW_DOCKER_REGISTRY_TOKEN: ${{ steps.base64-encode.outputs.token }}
TESTING_FORMULAE: ${{ needs.setup.outputs.testing-formulae }}
run: |
test_bot_args=(
--fail-fast
--only-formulae
--root-url=https://ghcr.io/v2/lizardbyte/homebrew
)
if [ -n "${TESTING_FORMULAE}" ]; then
test_bot_args+=("--testing-formulae=${TESTING_FORMULAE}")
fi
brew test-bot "${test_bot_args[@]}"
- name: Upload bottles as artifact
if: always() && github.event_name == 'pull_request'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: bottles_${{ matrix.os }}
path: '*.bottle.*'
# Conclusion job that checks test results
conclusion:
if: always()
needs:
- setup
- build-bottles
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Check workflow results
env:
SETUP_RESULT: ${{ needs.setup.result }}
BOTTLES_RESULT: ${{ needs.build-bottles.result }}
HAS_FORMULAE: ${{ needs.setup.outputs.has-formulae }}
run: |
echo "Workflow Status Summary:"
echo " setup: ${SETUP_RESULT}"
echo " build-bottles: ${BOTTLES_RESULT}"
echo " has-formulae: ${HAS_FORMULAE}"
# If no formulae were changed, workflow should succeed
if [ "${HAS_FORMULAE}" == "false" ]; then
echo "✅ No formula changes detected - workflow succeeded"
exit 0
fi
# Check for failures (not skipped or cancelled)
if [ "${SETUP_RESULT}" == "failure" ]; then
echo "❌ Setup and detection failed"
exit 1
fi
if [ "${BOTTLES_RESULT}" == "failure" ]; then
echo "❌ Test bot failed"
exit 1
fi
# Success if all required jobs succeeded or were skipped
echo "✅ All tests passed"
exit 0
# Check if bottles have been published (for PRs with formula changes)
check-bottle-published:
if: always() && github.event_name == 'pull_request'
needs:
- setup
- conclusion
permissions:
pull-requests: read
runs-on: ubuntu-latest
steps:
- name: Check for bottle published label
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
HAS_FORMULAE: ${{ needs.setup.outputs.has-formulae }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const hasFormulae = process.env.HAS_FORMULAE === 'true';
const prNumber = context.issue.number;
// If no formula changes, pass automatically
if (!hasFormulae) {
console.log('✅ No formula changes detected - skipping bottle published check');
return;
}
console.log(`Checking for bottle-published label on PR #${prNumber}...`);
// Get PR labels
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const labelNames = labels.map(label => label.name);
console.log(`PR labels: ${labelNames.join(', ')}`);
// Check if bottle published label exists
const hasBottlePublished = labelNames.includes('bottle-published');
if (hasBottlePublished) {
console.log('✅ bottle-published label found - PR can be merged');
} else {
console.log('❌ bottle-published label not found - bottles must be published before merging');
throw new Error('bottle-published label not found');
}
auto-approve-lizardbyte-bot:
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'LizardByte-bot'
needs: conclusion
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Label PR with pr-pull
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['pr-pull']
});