-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
207 lines (184 loc) · 7.98 KB
/
update-submodule.yml
File metadata and controls
207 lines (184 loc) · 7.98 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: Update Submodule
on:
workflow_run:
workflows: ["Detect Labels"]
types: [completed]
env:
GH_TOKEN: ${{ github.token }}
permissions:
pull-requests: write
contents: write
jobs:
read-label-data:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: "Download artifact"
uses: actions/github-script@v8
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr-data"
})[0];
let 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');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
if (!fs.existsSync(temp)){
fs.mkdirSync(temp);
}
fs.writeFileSync(path.join(temp, 'pr-data.zip'), Buffer.from(download.data));
- name: "Unzip artifact"
run: unzip "${{ runner.temp }}/artifacts/pr-data.zip" -d "${{ runner.temp }}/artifacts"
- name: "Read label data"
id: read-label-data
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
const prNumber = Number(fs.readFileSync(path.join(temp, 'NR')));
const label = fs.readFileSync(path.join(temp, 'LABEL')).toString().trim();
const ref = fs.readFileSync(path.join(temp, 'REF')).toString().trim();
const repo = fs.readFileSync(path.join(temp, 'REPO')).toString().trim();
core.setOutput('label', label);
core.setOutput('prNumber', prNumber);
core.setOutput('ref', ref);
core.setOutput('repo', repo);
outputs:
label: ${{ steps.read-label-data.outputs.label }}
prNumber: ${{ steps.read-label-data.outputs.prNumber }}
ref: ${{ steps.read-label-data.outputs.ref }}
repo: ${{ steps.read-label-data.outputs.repo }}
block-locales-pr:
needs: read-label-data
if: needs.read-label-data.outputs.label == 'Awaiting Locales'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
.nvmrc
sparse-checkout-cone-mode: false
- name: "Block PR"
run: |
gh pr review ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --request-changes --body "This pull request is blocked until the associated locales PR is merged.
To unblock and update the locales submodule, add the \`Update Locales\` label."
block-assets-pr:
needs: read-label-data
if: needs.read-label-data.outputs.label == 'Awaiting Assets'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
.nvmrc
sparse-checkout-cone-mode: false
- name: "Block PR"
run: |
gh pr review ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --request-changes --body "This pull request is blocked until the associated assets PR is merged.
To unblock and update the assets submodule, add the \`Update Assets\` label."
update-locales:
needs: read-label-data
if: needs.read-label-data.outputs.label == 'Update Locales'
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ secrets.PAGEFAULT_APP_ID }}
private-key: ${{ secrets.PAGEFAULT_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ needs.read-label-data.outputs.repo }}
ref: ${{ needs.read-label-data.outputs.ref }}
sparse-checkout: |
locales
.gitmodules
sparse-checkout-cone-mode: false
token: ${{ steps.app-token.outputs.token }}
- name: Update locales submodule
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git submodule update --progress --init --recursive --force --depth 1 --remote locales
- name: Commit and push changes
run: |
git add locales
if ! git commit -m "Update locales submodule"; then
echo "No changes to commit"
else
git push
fi
- name: Remove label
run: |
gh pr edit ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --remove-label "Update Locales"
gh pr edit ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --remove-label "Awaiting Locales"
- name: Unblock PR
run: |
REVIEW_ID=$(gh api repos/${{ github.repository }}/pulls/${{ needs.read-label-data.outputs.prNumber }}/reviews \
--jq '.[] | select(.user.login == "github-actions[bot]" and .state == "CHANGES_REQUESTED" and (.body // "" | contains("Update Locales"))) | .id' | head -n 1)
if [ -n "$REVIEW_ID" ]; then
gh api --method PUT repos/${{ github.repository }}/pulls/${{ needs.read-label-data.outputs.prNumber }}/reviews/$REVIEW_ID/dismissals \
-f message="Locales updated, unblocking PR."
fi
update-assets:
needs: read-label-data
if: needs.read-label-data.outputs.label == 'Update Assets'
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ secrets.PAGEFAULT_APP_ID }}
private-key: ${{ secrets.PAGEFAULT_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ needs.read-label-data.outputs.repo }}
ref: ${{ needs.read-label-data.outputs.ref }}
sparse-checkout: |
assets
.gitmodules
sparse-checkout-cone-mode: false
token: ${{ steps.app-token.outputs.token }}
- name: Update assets submodule
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git submodule update --progress --init --recursive --force --depth 1 --remote assets
- name: Commit and push changes
run: |
git add assets
if ! git commit -m "Update assets submodule"; then
echo "No changes to commit"
else
git push
fi
- name: Remove label
run: |
gh pr edit ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --remove-label "Update Assets"
gh pr edit ${{ needs.read-label-data.outputs.prNumber }} -R ${{ github.repository }} --remove-label "Awaiting Assets"
- name: Unblock PR
run: |
REVIEW_ID=$(gh api repos/${{ github.repository }}/pulls/${{ needs.read-label-data.outputs.prNumber }}/reviews \
--jq '.[] | select(.user.login == "github-actions[bot]" and .state == "CHANGES_REQUESTED" and (.body // "" | contains("Update Assets"))) | .id' | head -n 1)
if [ -n "$REVIEW_ID" ]; then
gh api --method PUT repos/${{ github.repository }}/pulls/${{ needs.read-label-data.outputs.prNumber }}/reviews/$REVIEW_ID/dismissals \
-f message="Assets updated, unblocking PR."
fi