-
Notifications
You must be signed in to change notification settings - Fork 39
207 lines (196 loc) · 8.96 KB
/
Copy pathpr_dispatch.yml
File metadata and controls
207 lines (196 loc) · 8.96 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
name: pr_dispatch
on:
issue_comment:
types: [created]
permissions:
pull-requests: write
contents: read
statuses: write
concurrency:
group: pr-dispatch-${{ github.event.issue.number }}
cancel-in-progress: true
jobs:
parse:
if: >-
github.event.issue.pull_request != null
&& startsWith(github.event.comment.body, '/build')
&& contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-latest
outputs:
head_sha: ${{ steps.pr.outputs.head_sha }}
au_owner: ${{ steps.cfg.outputs.au_owner }}
au_repo: ${{ steps.cfg.outputs.au_repo }}
au_branch: ${{ steps.cfg.outputs.au_branch }}
au_platforms: ${{ steps.cfg.outputs.au_platforms }}
mu_owner: ${{ steps.cfg.outputs.mu_owner }}
mu_repo: ${{ steps.cfg.outputs.mu_repo }}
mu_branch: ${{ steps.cfg.outputs.mu_branch }}
mu_platforms: ${{ steps.cfg.outputs.mu_platforms }}
steps:
- name: React with eyes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api -X POST \
"repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
-f content=eyes
- name: Fetch PR
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_json=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}")
head_sha=$(echo "$pr_json" | jq -r .head.sha)
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
echo "$pr_json" | jq -r .body > /tmp/pr_body.txt
- name: Parse build configuration
id: cfg
run: |
extract() {
grep -m1 -E "^${1}:[[:space:]]*" /tmp/pr_body.txt | sed -E "s/^${1}:[[:space:]]*//" || true
}
parse_combo() {
local label="$1" combo="$2" default="$3"
[ -z "$combo" ] && combo="$default"
local owner repo branch
owner=$(echo "$combo" | cut -d/ -f1)
repo=$(echo "$combo" | cut -d/ -f2)
branch=$(echo "$combo" | cut -d/ -f3-)
if [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$branch" ]; then
echo "::error::$label field must be {owner}/{repo}/{branch}, got '$combo'" >&2
return 1
fi
echo "$owner $repo $branch"
}
au_combo=$(extract "audacity")
au_platforms=$(extract "audacity platforms")
[ -z "$au_platforms" ] && au_platforms="linux_x64 macos windows_x64"
read -r au_owner au_repo au_branch < <(parse_combo "audacity" "$au_combo" "audacity/audacity/master")
mu_combo=$(extract "musescore")
mu_platforms=$(extract "musescore platforms")
[ -z "$mu_platforms" ] && mu_platforms="linux_x64 macos windows_x64"
read -r mu_owner mu_repo mu_branch < <(parse_combo "musescore" "$mu_combo" "musescore/MuseScore/master")
{
echo "au_owner=$au_owner"
echo "au_repo=$au_repo"
echo "au_branch=$au_branch"
echo "au_platforms=$au_platforms"
echo "mu_owner=$mu_owner"
echo "mu_repo=$mu_repo"
echo "mu_branch=$mu_branch"
echo "mu_platforms=$mu_platforms"
} >> "$GITHUB_OUTPUT"
- name: Post pending statuses + run-link comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ steps.pr.outputs.head_sha }}
AU_PLATFORMS: ${{ steps.cfg.outputs.au_platforms }}
MU_PLATFORMS: ${{ steps.cfg.outputs.mu_platforms }}
run: |
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
post_pending() {
gh api -X POST "repos/${{ github.repository }}/statuses/$SHA" \
-f state=pending -f context="$1" -f target_url="$RUN_URL" -f description="dispatched"
}
[[ "$AU_PLATFORMS" == *linux_x64* ]] && post_pending "build / Audacity Linux"
[[ "$AU_PLATFORMS" == *macos* ]] && post_pending "build / Audacity macOS"
[[ "$AU_PLATFORMS" == *windows_x64* ]] && post_pending "build / Audacity Windows"
[[ "$MU_PLATFORMS" =~ linux_(x64|arm64) ]] && post_pending "build / MuseScore Linux"
[[ "$MU_PLATFORMS" == *macos* ]] && post_pending "build / MuseScore macOS"
[[ "$MU_PLATFORMS" =~ windows_(x64|portable) ]] && post_pending "build / MuseScore Windows"
gh pr comment "${{ github.event.issue.number }}" --repo "${{ github.repository }}" \
--body "Build dispatched: $RUN_URL"
build_au_linux:
needs: parse
if: contains(needs.parse.outputs.au_platforms, 'linux_x64')
uses: audacity/audacity/.github/workflows/au4_build_linux.yml@master
with:
app_repo: ${{ needs.parse.outputs.au_owner }}/${{ needs.parse.outputs.au_repo }}
app_ref: ${{ needs.parse.outputs.au_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
build_au_macos:
needs: parse
if: contains(needs.parse.outputs.au_platforms, 'macos')
uses: audacity/audacity/.github/workflows/au4_build_macos.yml@master
with:
app_repo: ${{ needs.parse.outputs.au_owner }}/${{ needs.parse.outputs.au_repo }}
app_ref: ${{ needs.parse.outputs.au_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
build_au_windows:
needs: parse
if: contains(needs.parse.outputs.au_platforms, 'windows_x64')
uses: audacity/audacity/.github/workflows/au4_build_windows.yml@master
with:
app_repo: ${{ needs.parse.outputs.au_owner }}/${{ needs.parse.outputs.au_repo }}
app_ref: ${{ needs.parse.outputs.au_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
build_mu_linux:
needs: parse
if: contains(needs.parse.outputs.mu_platforms, 'linux_x64') || contains(needs.parse.outputs.mu_platforms, 'linux_arm64')
uses: musescore/MuseScore/.github/workflows/build_linux.yml@master
with:
app_repo: ${{ needs.parse.outputs.mu_owner }}/${{ needs.parse.outputs.mu_repo }}
app_ref: ${{ needs.parse.outputs.mu_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
platforms: ${{ needs.parse.outputs.mu_platforms }}
build_mode: devel
build_mu_macos:
needs: parse
if: contains(needs.parse.outputs.mu_platforms, 'macos')
uses: musescore/MuseScore/.github/workflows/build_macos.yml@master
with:
app_repo: ${{ needs.parse.outputs.mu_owner }}/${{ needs.parse.outputs.mu_repo }}
app_ref: ${{ needs.parse.outputs.mu_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
build_mode: devel
build_mu_windows:
needs: parse
if: contains(needs.parse.outputs.mu_platforms, 'windows_x64') || contains(needs.parse.outputs.mu_platforms, 'windows_portable')
uses: musescore/MuseScore/.github/workflows/build_windows.yml@master
with:
app_repo: ${{ needs.parse.outputs.mu_owner }}/${{ needs.parse.outputs.mu_repo }}
app_ref: ${{ needs.parse.outputs.mu_branch }}
framework_repo: ${{ github.repository }}
framework_ref: ${{ needs.parse.outputs.head_sha }}
platforms: ${{ needs.parse.outputs.mu_platforms }}
build_mode: devel
report:
needs: [parse, build_au_linux, build_au_macos, build_au_windows, build_mu_linux, build_mu_macos, build_mu_windows]
if: always() && needs.parse.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Forward final statuses to PR head
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ needs.parse.outputs.head_sha }}
AU_LINUX: ${{ needs.build_au_linux.result }}
AU_MACOS: ${{ needs.build_au_macos.result }}
AU_WINDOWS: ${{ needs.build_au_windows.result }}
MU_LINUX: ${{ needs.build_mu_linux.result }}
MU_MACOS: ${{ needs.build_mu_macos.result }}
MU_WINDOWS: ${{ needs.build_mu_windows.result }}
run: |
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
post() {
local context="$1" result="$2" state
case "$result" in
success) state=success ;;
skipped) return 0 ;;
cancelled) state=error ;;
*) state=failure ;;
esac
gh api -X POST "repos/${{ github.repository }}/statuses/$SHA" \
-f state="$state" -f context="$context" -f target_url="$RUN_URL" \
-f description="$context: $result"
}
post "build / Audacity Linux" "$AU_LINUX"
post "build / Audacity macOS" "$AU_MACOS"
post "build / Audacity Windows" "$AU_WINDOWS"
post "build / MuseScore Linux" "$MU_LINUX"
post "build / MuseScore macOS" "$MU_MACOS"
post "build / MuseScore Windows" "$MU_WINDOWS"