Repository navigation
128 lines (115 loc) · 4.76 KB
/
Copy pathupdate-screenshots.yml
File metadata and controls
128 lines (115 loc) · 4.76 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
name: Update component screenshots
on:
workflow_dispatch:
issue_comment:
types: [created]
jobs:
update-screenshots:
runs-on: ubuntu-24.04
if: >-
(github.event_name == 'workflow_dispatch' && github.ref_name != github.event.repository.default_branch) ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/update-screenshots' &&
(github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'))
concurrency:
group: update-screenshots@${{ github.event.issue.number || github.ref_name }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: read
steps:
- name: Check commenter permission
if: github.event_name == 'issue_comment'
id: authorization
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
with:
script: |
const username = context.payload.comment.user.login;
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username,
});
if (!['admin', 'maintain', 'write'].includes(data.permission)) {
core.setFailed(`@${username} needs write access to run this command.`);
}
- name: Get PR head ref
if: github.event_name == 'issue_comment'
id: pr
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const headRepo = pr.head.repo?.full_name;
const baseRepo = pr.base.repo.full_name;
if (!headRepo || headRepo !== baseRepo) {
core.setFailed(`Fork PRs are not supported (head: ${headRepo}, base: ${baseRepo})`);
return;
}
core.setOutput('ref', pr.head.ref);
- name: Checkout selected branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ steps.pr.outputs.ref || github.ref_name }}
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093
- name: Use Node.js 24
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24.15.0
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Install browsers
run: pnpm run --dir packages/tree-widget install-browsers
- name: Build component tests
run: pnpm exec lage build --to @itwin/tree-widget-react
- name: Update component screenshots
env:
CI: true
run: pnpm run --dir packages/tree-widget test:components:update
- name: Commit updated screenshots
id: commit
shell: bash
run: |
git add -- packages/tree-widget/src/test/components
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No screenshot updates were needed."
exit 0
fi
unexpected_files=$(git diff --cached --name-only | grep -vE '\.png$' || true)
if [[ -n "$unexpected_files" ]]; then
echo "Unexpected non-screenshot changes detected:"
echo "$unexpected_files"
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "test: update component screenshots"
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Push updated screenshots
if: steps.commit.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
TARGET_REF: ${{ steps.pr.outputs.ref || github.ref_name }}
run: |
auth_header=$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')
git -c "http.extraheader=AUTHORIZATION: basic $auth_header" push origin "HEAD:$TARGET_REF"
- name: Summary
env:
TARGET_REF: ${{ steps.pr.outputs.ref || github.ref_name }}
run: |
if [[ "${{ steps.commit.outputs.changed }}" == "true" ]]; then
printf 'Updated component screenshots were pushed to `%s`.\n' "$TARGET_REF" >> "$GITHUB_STEP_SUMMARY"
else
echo "No component screenshots needed updating." >> "$GITHUB_STEP_SUMMARY"
fi