Skip to content

Commit ee77602

Browse files
Add workflow for auto committee images
1 parent 5352661 commit ee77602

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "Generate committee mini images"
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- 'assets/committee/*/full/**'
8+
9+
concurrency:
10+
group: committee-images-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
minify:
15+
# GITHUB_TOKEN can't push to forks, so only run for branches in this repo
16+
if: github.repository == github.event.pull_request.head.repo.full_name
17+
permissions:
18+
contents: write
19+
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v7
23+
with:
24+
ref: ${{ github.event.pull_request.head.ref }}
25+
# Full history is needed to diff against the base, but not old images
26+
fetch-depth: 0
27+
filter: blob:none
28+
29+
- name: Install ImageMagick
30+
run: sudo apt-get update && sudo apt-get install -y imagemagick
31+
32+
- name: Run committee.sh on each changed committee folder
33+
env:
34+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
35+
run: |
36+
git -c core.quotePath=false diff --name-only --no-renames --diff-filter=d "$BASE_SHA"...HEAD -- 'assets/committee/*/full/*' \
37+
| cut -d/ -f1-3 | sort -u \
38+
| while read -r dir; do
39+
# Skip if the minis were already committed after the last full image change,
40+
# as PNGs get a new timestamp each time and would be committed again
41+
last_full=$(git log -1 --format=%H "$BASE_SHA"..HEAD -- "$dir/full")
42+
last_mini=$(git log -1 --format=%H "$BASE_SHA"..HEAD -- "$dir/mini")
43+
if [ -n "$last_mini" ] && git merge-base --is-ancestor "$last_full" "$last_mini"; then
44+
echo "Mini images for $dir are already up to date"
45+
continue
46+
fi
47+
48+
echo "Generating mini images for $dir"
49+
_scripts/committee.sh "$dir"
50+
51+
# committee.sh doesn't report convert failures, so check each full image has a mini
52+
for full in "$dir"/full/*; do
53+
if [ ! -f "$dir/mini/$(basename "$full")" ]; then
54+
echo "::error file=$full::No mini image was made for $full"
55+
exit 1
56+
fi
57+
done
58+
done
59+
60+
- name: Commit mini images to the PR
61+
env:
62+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
63+
run: |
64+
git add -A assets/committee
65+
if git diff --cached --quiet; then
66+
echo "Mini images are already up to date"
67+
exit 0
68+
fi
69+
git config user.name "github-actions[bot]"
70+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
71+
git commit -m "Generate committee mini images"
72+
git push origin "HEAD:refs/heads/$HEAD_REF"

0 commit comments

Comments
 (0)