-
Notifications
You must be signed in to change notification settings - Fork 58
93 lines (78 loc) · 3.97 KB
/
snapshotCommit.yml
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
name: Commit Snapshots
on:
workflow_run:
workflows: ['Update Snapshots']
types:
- completed
jobs:
commit:
name: Commit Snapshots
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
repository: ${{ github.event.workflow_run.head_repository.full_name }}
- name: Download Artifacts
uses: actions/[email protected]
with:
script: |
const fs = require('fs');
const { execSync } = require('child_process');
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id
});
await Promise.all(
artifacts.data.artifacts.map(async (artifact) => {
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip'
});
const tmpDir = `/tmp/${artifact.name.replace(/[^a-zA-Z0-9-_]/g, '')}`;
execSync(`mkdir -p ${tmpDir}`);
fs.writeFileSync(`${tmpDir}.zip`, Buffer.from(download.data));
console.log(`Checking artifact: ${artifact.name}`)
execSync(`unzip -o ${tmpDir}.zip -d ${tmpDir}`);
if (artifact.name === 'metadata') {
execSync(`rsync -zavpmr --no-links --include='pull_number.txt' --exclude='*' ${tmpDir}/ ${{ github.workspace }}`);
} else {
const snapshotsDir = artifact.name.includes('v2') ? 'tests/functional/v2/snapshots' : 'tests/functional/snapshots';
execSync(`rsync -zavpmr --no-links --include='*.png' --include='*/' --exclude='*' ${tmpDir}/ ${{ github.workspace }}/${snapshotsDir}`);
}
})
);
- name: List Snapshots
run: |
git status --porcelain
- name: Reset Label
if: github.event.workflow_run.event == 'pull_request'
uses: actions/[email protected]
with:
# The workflow_run that comes along with the event drops the PR number for some reason
# so we have to pass the PR number from the original workflow as an artifact
script: |
const fs = require('fs');
const pullNumber = Number(fs.readFileSync('./pull_number.txt', 'utf8')).toString();
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
name: 'snapshots'
}).catch(() => {
console.log('snapshots label has already been removed');
});
- name: Commit Updated Snapshots
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore(snapshots): ${{ github.event.workflow.name }} [skip ci]'
commit_options: '--no-verify --quiet'
file_pattern: tests/functional/snapshots tests/functional/v2/snapshots
push_options: '-v'