-
Notifications
You must be signed in to change notification settings - Fork 80
96 lines (88 loc) · 3.53 KB
/
pr-visual-snapshot-update-bot.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
94
95
96
name: PR Visual Snapshot Update Bot
on:
workflow_run:
workflows: [PR Build]
jobs:
pr-visual-snapshot-update-bot:
if: ${{github.event.workflow_run.conclusion == 'success'}}
runs-on: ubuntu-latest
steps:
- uses: haya14busa/action-workflow_run-status@v1
- name: Checkout
uses: actions/checkout@v3
with:
repo: ${{github.event.workflow_run.head_repository.full_name}}
ref: ${{github.event.workflow_run.head_sha}}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Install Dependencies
run: npm ci
- name: Get PR Event
id: get-pr-event
uses: potiuk/get-workflow-origin@v1_5
with:
token: ${{secrets.GITHUB_TOKEN}}
sourceRunId: ${{github.event.workflow_run.id}}
- name: Download Changes
uses: dawidd6/action-download-artifact@v2
with:
name: visual-snapshot-changes-.+\.diff
name_is_regexp: true
path: .
workflow: ${{github.event.workflow_run.workflow_id}}
run_id: ${{github.event.workflow_run.id}}
if_no_artifact_found: ignore
- name: Apply Changes
id: apply-changes
run: |
# apply changes
git apply visual-snapshot-changes-*.diff/visual-snapshot-changes-*.diff
rm visual-snapshot-changes-*.diff/visual-snapshot-changes-*.diff
# delete unused screenshots
npm run ts-node -- ./scripts/delete-unused-screenshots.ts
- name: Check for Changes
id: diff
run: |
git add .
if git diff-index --quiet HEAD
then
echo "status=clean" >> $GITHUB_OUTPUT
else
echo "status=dirty" >> $GITHUB_OUTPUT
fi
- name: Push Changes
if: ${{steps.diff.outputs.status == 'dirty'}}
id: push-changes
run: |
repositoryUrl=${{github.server_url}}/${{github.repository}}.git
updateBranchName=visual-snapshot-update/pr-${{steps.get-pr-event.outputs.pullRequestNumber}}
# configure git
git config user.name "GitHub"
git config user.email "[email protected]"
# commit changes
git commit --message 'chore: update visual snapshots for `${{steps.get-pr-event.outputs.sourceHeadBranch}}`'
# push changes
git push $repositoryUrl HEAD:refs/heads/$updateBranchName --force
# delete branch (it's not needed, only the commit needs to be in the repo)
git push $repositoryUrl -d $updateBranchName
# set commit-sha for next step
echo "commit-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Comment
if: ${{steps.diff.outputs.status == 'dirty'}}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
body: |
This PR introduces visual changes: ${{steps.push-changes.outputs.commit-sha}}
If these changes are intended and correct, please cherry-pick the above commit to this PR.
```
git checkout ${{steps.get-pr-event.outputs.sourceHeadBranch}}
git fetch ${{github.server_url}}/${{github.repository}}.git ${{steps.push-changes.outputs.commit-sha}}
git cherry-pick ${{steps.push-changes.outputs.commit-sha}}
git push
```
- name: Fail if Visual Snapshots Changed
if: ${{steps.diff.outputs.status == 'dirty'}}
run: exit 1