-
Notifications
You must be signed in to change notification settings - Fork 878
194 lines (174 loc) · 7.42 KB
/
Copy pathwinappsdk-sync-apply.yml
File metadata and controls
194 lines (174 loc) · 7.42 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
name: WinAppSDK Sync Generator Apply
# Responds to `/apply-sync-gen` PR comments. Re-runs the sync generator and
# pushes `chore: Sync generator run` to the PR's head branch. Only works for
# PRs from branches in this repo — fork PRs must apply the patch manually.
#
# Safety:
# - `startsWith` on the comment body (not `contains`) so the drift-check
# workflow's instructional comment (which mentions `/apply-sync-gen`
# further down in its body) cannot self-trigger this workflow.
# - Bot comments are excluded via `comment.user.type`.
# - As an additional safety net, events caused by the default GITHUB_TOKEN
# do not trigger further workflow runs.
on:
issue_comment:
types: [created]
jobs:
apply:
if: >-
github.repository == 'unoplatform/uno' &&
github.event.issue.pull_request != null &&
github.event.comment.user.type != 'Bot' &&
startsWith(github.event.comment.body, '/apply-sync-gen')
name: Apply WinAppSDK Sync Generator
runs-on: windows-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Resolve PR and authorize commenter
id: pr
uses: actions/github-script@v9
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const head = pr.data.head;
const baseFullName = `${context.repo.owner}/${context.repo.repo}`;
const isFork = !head.repo || head.repo.full_name !== baseFullName;
const commenter = context.payload.comment.user.login;
const assoc = context.payload.comment.author_association;
const allowedAssoc = ['OWNER', 'MEMBER', 'COLLABORATOR'];
const isAuthor = commenter === pr.data.user.login;
if (!isAuthor && !allowedAssoc.includes(assoc)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `@${commenter} you are not permitted to trigger \`/apply-sync-gen\` on this PR (only the PR author or repo collaborators can).`,
});
core.setFailed(`User ${commenter} (${assoc}) is not permitted to trigger /apply-sync-gen.`);
return;
}
if (isFork) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'Cannot auto-apply to a fork branch. Please download the `sync-generator-patch` artifact from the latest **WinAppSDK Sync Generator Check** run and apply it locally (`git apply` + commit + push).',
});
core.setFailed('Fork PR — cannot auto-apply.');
return;
}
core.setOutput('ref', head.ref);
core.setOutput('sha', head.sha);
- name: Acknowledge with reaction
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'eyes',
});
- uses: actions/checkout@v7
with:
ref: ${{ steps.pr.outputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Pin .NET Version
shell: bash
run: cp build/ci/net10/_global.json global.json
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5.4.0
with:
global-json-file: global.json
- name: Install required .NET workloads
shell: bash
run: dotnet workload install android ios maccatalyst tvos
- name: Restore sync generator solution filter
working-directory: build
shell: bash
run: >
dotnet restore filters/Uno.UI-top-projects-for-sync-gen.slnf
-p:Configuration=Release
-p:CI_Build=true
-p:_IsCIBuild=true
-p:SyncGeneratorRunning=true
- name: Build WinAppSDKSyncGenerator
shell: bash
run: dotnet build src/Uno.WinAppSDKSyncGenerator/Uno.WinAppSDKSyncGenerator.csproj -c Release
- name: Build WinAppSDKSyncGenerator.References
shell: bash
run: dotnet build src/Uno.WinAppSDKSyncGenerator.References/Uno.WinAppSDKSyncGenerator.References.csproj -c Release
- name: Run WinAppSDKSyncGenerator (sync)
shell: bash
run: src/Uno.WinAppSDKSyncGenerator/bin/Release/Uno.WinAppSDKSyncGenerator.exe sync
- name: Restore pinned global.json so it is not committed
shell: bash
run: git checkout -- global.json
- name: Commit and push if drift
id: commit
shell: bash
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
if [ -z "$(git status --porcelain)" ]; then
echo "No drift — nothing to commit."
echo "pushed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git add -A
git commit -m 'chore: Sync generator run'
git push origin HEAD:${{ steps.pr.outputs.ref }}
echo "pushed=true" >> "$GITHUB_OUTPUT"
- name: Comment with outcome
if: always() && steps.pr.outputs.ref != ''
uses: actions/github-script@v9
with:
script: |
const pushed = '${{ steps.commit.outputs.pushed }}' === 'true';
const jobStatus = '${{ job.status }}';
let body;
if (jobStatus === 'success' && pushed) {
body = [
'Pushed `chore: Sync generator run` to this PR branch.',
'',
'GitHub does not re-trigger workflows for commits pushed by the default bot, so the **WinAppSDK Sync Generator Check** will not automatically re-run. To turn it green, push any additional commit (for example `git commit --allow-empty -m "ci: re-run"`) or ask a maintainer to re-run the check.',
].join('\n');
} else if (jobStatus === 'success' && !pushed) {
body = 'Ran the sync generator — no drift detected, nothing to commit.';
} else {
body = 'The apply workflow failed. See the workflow logs for details.';
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
- name: React success
if: success()
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '+1',
});
- name: React failure
if: failure()
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '-1',
});