-
Notifications
You must be signed in to change notification settings - Fork 139
183 lines (171 loc) · 7 KB
/
Copy pathmake_card_db_pr.yml
File metadata and controls
183 lines (171 loc) · 7 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
name: Make Card DB PR
on:
workflow_run:
workflows:
- Compile Card DB
types:
- completed
jobs:
make_pr:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
actions: read
contents: write
issues: write
pull-requests: write
steps:
- name: Download PR context artifact
id: pr-context
uses: actions/github-script@v8
with:
result-encoding: string
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = artifacts.data.artifacts.find(
(artifact) => artifact.name === 'pr_context'
);
if (!matchArtifact) {
return 'no_pr_context';
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_context.zip`, Buffer.from(download.data));
return 'found_pr_context';
- name: Unzip PR context artifact
if: ${{ steps.pr-context.outputs.result == 'found_pr_context' }}
run: unzip -o pr_context.zip
- name: Read PR context
id: read-pr-context
if: ${{ steps.pr-context.outputs.result == 'found_pr_context' }}
shell: bash
run: |
echo "pr_number=$(tr -d '\r\n' < pr_number)" >> "$GITHUB_OUTPUT"
echo "base_branch=$(tr -d '\r\n' < base_branch)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v6
if: ${{ steps.pr-context.outputs.result == 'found_pr_context' }}
with:
ref: ${{ steps.read-pr-context.outputs.base_branch }}
- name: Download compiled card DB artifact
id: compiled-card-db
if: ${{ steps.pr-context.outputs.result == 'found_pr_context' }}
uses: actions/github-script@v8
with:
result-encoding: string
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = artifacts.data.artifacts.find(
(artifact) => artifact.name === 'compiled-card-db'
);
if (!matchArtifact) {
return 'no_compiled_card_db';
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/compiled_card_db.zip`,
Buffer.from(download.data)
);
return 'found_compiled_card_db';
- name: Close stale auto PRs if no card DB changes
if: ${{ steps.pr-context.outputs.result == 'found_pr_context' && steps.compiled-card-db.outputs.result == 'no_compiled_card_db' }}
uses: actions/github-script@v8
env:
AUTO_PR_BRANCH: auto-card-db/source-pr-${{ steps.read-pr-context.outputs.pr_number }}
SOURCE_PR_NUMBER: ${{ steps.read-pr-context.outputs.pr_number }}
with:
script: |
const sourcePrNumber = Number(process.env.SOURCE_PR_NUMBER);
const targetTitle = `Auto Card DB compile for #${sourcePrNumber}`;
const targetHeadRef = process.env.AUTO_PR_BRANCH;
let page = 1;
let openAutoPrs = [];
while (true) {
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
page,
});
if (prs.length === 0) {
break;
}
openAutoPrs = openAutoPrs.concat(
prs.filter(
(pr) => pr.head.ref === targetHeadRef || pr.title === targetTitle
)
);
page += 1;
}
for (const pr of openAutoPrs) {
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed',
});
}
- name: Unzip compiled card DB artifact
if: ${{ steps.compiled-card-db.outputs.result == 'found_compiled_card_db' }}
run: unzip -o compiled_card_db.zip
- name: Extract compiled card DB
if: ${{ steps.compiled-card-db.outputs.result == 'found_compiled_card_db' }}
run: tar -xzf compiled_card_db.tgz
- name: Make PR
id: make-pr
if: ${{ steps.compiled-card-db.outputs.result == 'found_compiled_card_db' }}
uses: peter-evans/create-pull-request@v8
env:
AUTO_PR_BRANCH: auto-card-db/source-pr-${{ steps.read-pr-context.outputs.pr_number }}
with:
branch: ${{ env.AUTO_PR_BRANCH }}
title: 'Auto Card DB compile for #${{ steps.read-pr-context.outputs.pr_number }}'
body: |
Auto-generate package card DB to from source card DB for PR #${{ steps.read-pr-context.outputs.pr_number }}
delete-branch: true
reviewers: sumpfork
assignees: sumpfork
add-paths: |
src/domdiv/card_db/
- name: Comment on PR
if: ${{ steps.compiled-card-db.outputs.result == 'found_compiled_card_db' }}
uses: actions/github-script@v8
env:
SOURCE_PR_NUMBER: ${{ steps.read-pr-context.outputs.pr_number }}
THIS_PR_NUMBER: ${{ steps.make-pr.outputs.pull-request-number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { SOURCE_PR_NUMBER, THIS_PR_NUMBER } = process.env;
const issue_number = Number(SOURCE_PR_NUMBER);
if (!Number.isInteger(issue_number) || issue_number <= 0) {
core.setFailed(`Invalid SOURCE_PR_NUMBER in comment step: ${SOURCE_PR_NUMBER}`);
return;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body: `It seems compiling the card DB on this PR produced changes.\n` +
`Ideally, please run "uv run doit update_languages" yourself on this PR and check in the results.\n` +
`Otherwise, PR #${THIS_PR_NUMBER} has the necessary (but unreviewed) changes.\n`
});