forked from shivammathur/homebrew-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (194 loc) · 7.36 KB
/
build.yml
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
name: Update and Build Formulae
on:
push:
branches:
- master
schedule:
- cron: '0 4 * * 4'
repository_dispatch:
workflow_dispatch:
pull_request:
env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_GITHUB_ACTIONS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_FROM_API: 1
HOMEBREW_RELOCATE_RPATHS: 1
jobs:
tap-syntax:
if: "!contains(github.event.head_commit.message, 'skip-build')"
runs-on: ubuntu-22.04
container:
image: ghcr.io/homebrew/ubuntu22.04:master
env:
HOMEBREW_SIMULATE_MACOS_ON_LINUX: 1
outputs:
testing_formulae: ${{ steps.formulae-detect.outputs.testing_formulae }}
added_formulae: ${{ steps.formulae-detect.outputs.added_formulae }}
deleted_formulae: ${{ steps.formulae-detect.outputs.deleted_formulae }}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: true
cask: false
test-bot: true
- run: brew test-bot --only-tap-syntax
- run: brew test-bot --only-formulae-detect
if: github.event_name == 'pull_request'
id: formulae-detect
get-matrix:
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message, 'skip-build')
needs: tap-syntax
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get matrix
id: set-matrix
env:
GITHUB_MESSAGE: ${{ github.event.head_commit.message }}
run: |
extensions=()
if [[ "$GITHUB_MESSAGE" != *--build-only-* ]]; then
mapfile -t extensions < <(find ./Formula -name "*@*.rb" -print0 | xargs -0 basename -a | sed "s/@.*//" | sort | uniq)
else
IFS=, read -ra extensions <<< "$(echo "$GITHUB_MESSAGE" | grep -Po 'build-only-.*' | cut -d '-' -f 3-)"
fi
json_array=""
first=true
for extension in "${extensions[@]}"; do
if [ "$first" = true ]; then
first=false
json_array="{\"extension\": \"$extension\"}"
else
json_array+=", {\"extension\": \"$extension\"}"
fi
done
echo "matrix={\"include\":[$json_array]}" >> "$GITHUB_OUTPUT"
create-pr:
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message, 'skip-build')
needs: get-matrix
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix: ${{fromJson(needs.get-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: false
cask: false
test-bot: false
- name: Patch formula
id: patch
env:
EXTENSION: ${{ matrix.extension }}
GITHUB_MESSAGE: ${{ github.event.head_commit.message }}
GITHUB_DEFAULT_BRANCH: master
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
GITHUB_SHA: ${{ github.sha }}
run: bash ./.github/scripts/pr.sh
set-environment:
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build')
runs-on: ubuntu-22.04
needs: tap-syntax
outputs:
syntax-only: ${{ steps.check-labels.outputs.syntax-only }}
linux-runner: ${{ steps.check-labels.outputs.linux-runner }}
fail-fast: ${{ steps.check-labels.outputs.fail-fast }}
test-dependents: ${{ steps.check-labels.outputs.test-dependents }}
timeout-minutes: ${{ steps.check-labels.outputs.timeout-minutes }}
container: ${{ steps.check-labels.outputs.container }}
test-bot-formulae-args: ${{ steps.check-labels.outputs.test-bot-formulae-args }}
test-bot-dependents-args: ${{ steps.check-labels.outputs.test-bot-dependents-args }}
steps:
- uses: actions/checkout@v4
- name: Check for CI labels
id: check-labels
uses: actions/github-script@v7
env:
SCRIPTS_PATH: .github/scripts
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const path = require('path')
const script = require(path.resolve(`${process.env.SCRIPTS_PATH}/environment.js`))
const formula_detect = {
testing_formulae: '${{needs.tap-syntax.outputs.testing_formulae}}',
added_formulae: '${{needs.tap-syntax.outputs.added_formulae}}',
deleted_formulae: '${{needs.tap-syntax.outputs.deleted_formulae}}'
}
try {
await script({github, context, core}, formula_detect)
} catch (error) {
console.error(error);
}
build-formula:
needs: set-environment
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build')
strategy:
matrix:
include:
- runner: 'macos-13-arm64'
cleanup: true
- runner: 'macos-15'
cleanup: true
- runner: 'macos-14'
cleanup: true
- runner: 'macos-13'
cleanup: true
- runner: ${{needs.set-environment.outputs.linux-runner}}
container: ${{fromJson(needs.set-environment.outputs.container)}}
workdir: /github/home
cleanup: false
timeout: 4320
fail-fast: ${{fromJson(needs.set-environment.outputs.fail-fast)}}
runs-on: ${{matrix.runner}}
container: ${{matrix.container}}
timeout-minutes: ${{ matrix.timeout || fromJson(needs.set-environment.outputs.timeout-minutes) }}
defaults:
run:
shell: /bin/bash -e {0}
working-directory: ${{matrix.workdir || github.workspace}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}}
BOTTLES_DIR: ${{matrix.workdir || github.workspace}}/bottles
steps:
- name: Pre-test steps
uses: Homebrew/actions/pre-build@master
with:
bottles-directory: ${{ env.BOTTLES_DIR }}
cleanup: ${{ matrix.cleanup }}
- name: Run brew test-bot ${{ needs.set-environment.outputs.test-bot-formulae-args }}
id: brew-test-bot-formulae
working-directory: ${{ env.BOTTLES_DIR }}
run: |
brew test-bot ${{ needs.set-environment.outputs.test-bot-formulae-args }}
- name: Post-build steps
if: always()
uses: Homebrew/actions/post-build@master
with:
runner: ${{ matrix.runner }}
cleanup: ${{ matrix.cleanup }}
bottles-directory: ${{ env.BOTTLES_DIR }}
logs-directory: ${{ format('{0}/logs', env.BOTTLES_DIR) }}
add-label:
needs: build-formula
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build') && github.event.pull_request.user.login == github.repository_owner
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Add Label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr edit "$(echo "$GITHUB_REF" | awk 'BEGIN { FS = "/" } ; { print $3 }')" --add-label "build-complete"