-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (77 loc) · 2.86 KB
/
deploy.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
name: Deploy
concurrency: deploy
on:
workflow_dispatch:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Git checkout with complete history
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Git checkout with limited history
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Download Inkscape
run: sudo apt update && sudo apt install inkscape -y
- name: Clear removed images
run: |
if [ -n ${LOG_SOURCE} ]
then
DELETED=$(git log --all --name-only --pretty="" --diff-filter=D ${LOG_SOURCE})
else
DELETED=$(comm -23 <(git log --all --name-only --pretty="" --diff-filter=D | sort | uniq) <(git ls-files | sort))
fi
for item in $DELETED
do
if ! [ -n "${item%%src/*}" ]
then
itemPath="${item%.svg}"
itemFilename=$(basename "${itemPath}")
for quality in ${{ vars.QUALITIES }}
do
aws s3api delete-object --bucket "${{ vars.AWS_BUCKET }}" --key "${{ vars.PREFIX }}/${quality}/${itemFilename}.png"
done
fi
done
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: ${{ vars.AWS_ENDPOINT_URL }}
AWS_PAGER:
AWS_EC2_METADATA_DISABLED: true
LOG_SOURCE: ${{ github.event_name == 'push' && 'HEAD~1..HEAD' || '' }}
- name: Convert and push changed images
run: |
if [ -n ${LOG_SOURCE} ]
then
MODIFIED=$(git log --all --name-only --pretty="" --diff-filter=AM ${LOG_SOURCE})
else
MODIFIED=$(git ls-files "src/*.svg")
fi
for item in $MODIFIED
do
if ! [ -n "${item%%src/*}" ]
then
itemPath="${item%.svg}"
itemFilename=$(basename "${itemPath}")
for quality in ${{ vars.QUALITIES }}
do
inkscape -w ${quality} -h ${quality} "${itemPath}.svg" -o "${itemPath}.png"
aws s3api put-object --bucket "${{ vars.AWS_BUCKET }}" --key "${{ vars.PREFIX }}/${quality}/${itemFilename}.png" --content-type "image/png" --body "${itemPath}.png"
done
fi
done
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: ${{ vars.AWS_ENDPOINT_URL }}
AWS_PAGER:
AWS_EC2_METADATA_DISABLED: true
LOG_SOURCE: ${{ github.event_name == 'push' && 'HEAD~1..HEAD' || '' }}