-
Notifications
You must be signed in to change notification settings - Fork 75
160 lines (141 loc) · 4.54 KB
/
images.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Optimize Images
on:
workflow_dispatch:
push:
branches: [master]
paths:
- "content/images/**"
jobs:
cancel-running-jobs:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
theses:
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.auto-commit-action.outputs.changes_detected }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install dependencies
run: pip install imageio==2.16.2
- name: Crop thesis covers
run: python ./crop_thesis_covers.py
- name: Pull in intermediate changes
run: git pull
- id: auto-commit-action
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Crop thesis covers
file_pattern: content/images/theses/*
images:
needs: theses
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Pull in cropped thesis covers
if: needs.theses.outputs.changes == 'true'
run: git pull && git checkout HEAD
- uses: actions/setup-node@v1
with:
node-version: "18.0.0"
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup npm
run: npm install --prefix imgoptim --no-save
- name: Optimize Images
run: |
cd imgoptim
node optimize.js
cd ..
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
yarn config set prefix $(yarn cache dir)
echo $(yarn global bin) >> $GITHUB_PATH
yarn config set global-folder $(yarn cache dir)
- name: Cache Yarn
uses: actions/cache@v2
env:
cache-version: v1
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
**/node_modules
key: ${{ runner.os }}-yarn-${{ env.cache-version }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.cache-version }}-
${{ runner.os }}-yarn-
${{ runner.os }}-
- name: Install Netlify
# if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn global add netlify-cli@v16.9.2
- name: Deploy images to Netlify
run: |
cp -r --no-clobber ./content/images/. assets/images
"$(yarn global bin)/netlify" deploy --dir=assets --prod
shell: bash
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_DEV_AUTH }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITEID_MEDIA }}
- name: Pull in intermediate changes
run: git pull
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update optimized images
file_pattern: imgoptim/image-cache.json assets/images/*
notify:
needs: images
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-20.04
steps:
- name: Send message to Teams channel
run: |
cat << EOF > message.json
{
"@type":"MessageCard",
"@context":"https://schema.org/extensions",
"summary":"Image optimization failed!",
"themeColor":"FF8E16",
"title":"$GITHUB_REPOSITORY image optimization failed",
"sections":[
{
"facts":[
{
"name":"Branch:",
"value":"$GITHUB_REF_NAME"
},
{
"name":"Commit:",
"value":"$GITHUB_SHA"
}
]
}
],
"potentialAction":[
{
"@type":"OpenUri",
"name":"View on GitHub",
"targets":[
{
"os":"default",
"uri":"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
}
]
}
]
}
EOF
curl -X POST ${{ secrets.TEAMS_WEBHOOK_URL }} --header 'Content-Type: application/json' -f -S -d @message.json