-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (72 loc) · 2.74 KB
/
check_metadata.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
name: Image metadata check CI
on:
push:
branches: [master]
pull_request:
paths:
- '**.webp'
- '**.png'
- '**.jpg'
jobs:
build:
name: Ubuntu - Image Metadata
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: exiftool installation
run: |
sudo apt-get install --assume-yes exiftool
- uses: actions/checkout@v4
with:
fetch-depth: 0
# this makes the HEAD be the last commit on the PR, not the merge commit, so wrong older commits would get buried
# ref: ${{ github.event.pull_request.head.sha }}
- name: PR env setup
if: ${{ github.event_name == 'pull_request' }}
env:
# figured this out from here: https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=edited#pull_request
SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: echo SHA is $SHA
- name: push env setup
if: ${{ github.event_name == 'push' }}
env:
SHA: ${{ github.event.push.after }}
BASE_SHA: ${{ github.event.push.before }}
run: echo SHA is $SHA
- name: read/export image metadata
# -id: image_check
run: |
mapfile -t image_files < <(git diff --name-only ${BASE_SHA} ${SHA} | grep '\.webp$')
git status
# array of accepted copyright strings
accepted_cr=("GNU GPL v2+|CC BY-SA 4.0|CC0")
# cycle through the changed image files, make sure they have the right fields
for file in "${image_files[@]}"; do
# check -Artist tag, fail if missing
artist="$(exiftool -Artist $file)"
artist="${artist#*: }"
if [ -z "$artist" ] ; then
echo "no Artist EXIF tag in $file"
exit 1
else
echo "Artist tag in $file is $artist"
fi
# check -Copyright tag, fail if missing or wrong type
copyright="$(exiftool -Copyright $file)"
copyright="${copyright#*: }"
if [ -z "$copyright" ] ; then
echo "no Copyright EXIF tag in $file"
exit 1
# elif [[ ( "$copyright" != ${accepted_cr[0]} ) && ( "$copyright" != ${accepted_cr[1]}) ]] ; then
elif [[ ! "|${accepted_cr[*]}|" =~ "|${copyright}|" ]]; then
echo "$copyright is not an accepted license"
exit 1
else
echo "Copyright tag in $file is $copyright"
fi
done
# - name: The image_check step has failed
# if: ${{ failure() && steps.image_check.conclusion == 'failure' }}