Repository navigation
158 lines (147 loc) · 5.57 KB
/
Copy pathupdate-snapshots.yml
File metadata and controls
158 lines (147 loc) · 5.57 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
name: update-snapshots
on:
workflow_run:
workflows: [vrt]
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
permissions: {}
jobs:
pull-request:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
number: ${{ steps.pr.outputs.number }}
steps:
- name: 'Get Pull Request'
uses: actions/github-script@5c56fde4671bc2d3592fb0f2c5b5bab9ddae03b1
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const artifact = artifacts.data.artifacts.find((artifact) => {
return artifact.name == 'pull-request'
});
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/PR.zip', Buffer.from(download.data));
- run: |
mkdir PR
unzip PR.zip -d PR
- uses: actions/github-script@5c56fde4671bc2d3592fb0f2c5b5bab9ddae03b1
id: pr
with:
script: |
const fs = require('fs');
const number = parseInt(fs.readFileSync('./PR/number', 'utf8'), 10);
if (isNaN(number)) {
core.setFailed('Unable to parse Pull Request number from artifact');
} else {
core.setOutput('number', number);
}
commit-and-push:
needs: pull-request
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
# Warning: we are checking out an untrusted source at this point in order
# to push to the head pull request. Code from this checkout must not be
# used in any of the following steps.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
token: ${{ steps.generate_token.outputs.token }}
- name: 'Download artifact'
uses: actions/github-script@5c56fde4671bc2d3592fb0f2c5b5bab9ddae03b1
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const SNAPSHOT_NAME_REGEX = /snapshots-[\d]+/g;
const snapshotArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name.match(SNAPSHOT_NAME_REGEX)
});
core.info(`Found: ${snapshotArtifacts.length} snapshot artifacts`);
for (let i = 0; i < snapshotArtifacts.length; i++) {
const artifact = snapshotArtifacts[i];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.writeFileSync(`${{github.workspace}}/snapshots-${i}.zip`, Buffer.from(download.data));
}
- run: |
for filepath in snapshots-*.zip
do
unzip -o $filepath
unzip -o snapshots.zip
rm snapshots.zip
rm $filepath
done
- uses: stefanzweifel/git-auto-commit-action@4a55954c782fc1ea30b9056cd3e7a2b40ca8887d
with:
commit_message: 'test(vrt): update snapshots'
remove-labels:
needs: [commit-and-push, pull-request]
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Remove label
uses: actions/github-script@5c56fde4671bc2d3592fb0f2c5b5bab9ddae03b1
with:
script: |
const fs = require('fs');
const { ISSUE_NUMBER, LABEL_NAME, OWNER, REPO } = process.env;
// This job may be run after pull-request is skipped above.
// If so, this job will not have an issue number and can safely
// return early
if (ISSUE_NUMBER === '' || isNaN(ISSUE_NUMBER)) {
return;
}
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: OWNER,
repo: REPO,
issue_number: ISSUE_NUMBER,
});
const label = labels.find((label) => {
return label.name === LABEL_NAME;
});
if (label) {
await github.rest.issues.removeLabel({
owner: OWNER,
repo: REPO,
name: LABEL_NAME,
issue_number: ISSUE_NUMBER,
});
}
env:
OWNER: 'primer'
REPO: 'react'
ISSUE_NUMBER: ${{ needs.pull-request.outputs.number }}
LABEL_NAME: 'update snapshots'