-
Notifications
You must be signed in to change notification settings - Fork 0
326 lines (291 loc) · 12.9 KB
/
nextjs.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
name: "Update, Build & Deployment"
on:
workflow_dispatch:
push:
branches: ["main"]
paths-ignore:
- ".github/**"
schedule: # times in in UTC
- cron: 30 2 * * TUE,THU # At 02:30 on Tuesday and Thursday
- cron: 15,45 09-21 * JAN-APR,OCT-DEC 0,6 # At minute 15 & 45 past every hour, from 9 AM to 9 PM on Sunday & Saturday, from October through April
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
env:
GITHUB_SUMMARY_FILE: "github_summary.md"
SAMS_FOLDER: "data/sams"
SAMS_MATCHSERIES_JSON: "data/sams/matchSeries.json"
SAMS_CLUB_JSON: "data/sams/club.json"
SAMS_CLUBS_CACHE: "data/sams/allClubs.json"
SAMS_PLAYERS_CACHE: "data/sams/team"
IMAGES_FOLDER: "public/images"
BLOG_FOLDER: "data/posts"
INBOX_FOLDER: "inbox"
SOCIAL_CACHE_MATCHES: "data/social/matchResults.json"
jobs:
# Build jobs
build:
name: "🏗️ SAMS & Build"
runs-on: ubuntu-latest
env:
TZ: Europe/Berlin
outputs:
sams_status: ${{ steps.sams_git.outputs.status }}
sams_social: ${{ steps.sams_git.outputs.social }}
build_status: ${{ steps.next_build.outputs.status }}
blog_check: ${{ steps.blog_check.outputs.status }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # latest commit, default is the commit that triggered the workflow
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: bun install
- name: Perform SAMS Update
id: sams_update
if: ${{ github.event_name != 'push' }}
continue-on-error: true
run: bun run sams-update
env:
SAMS_API: ${{ secrets.SAMS_API }}
- name: Commit SAMS Files
id: sams_git
if: steps.sams_update.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.SAMS_MATCHSERIES_JSON }} --dry-run)" ]
then
echo "✅ Match Series up to date."
echo "✅ Match Series up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Match Series changes detected and staged."
git add ${{ env.SAMS_MATCHSERIES_JSON }} --force || true
git commit -m "automated deployment update" || true
echo "🏐 Match Series changes detected and staged." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_CLUB_JSON }} --dry-run)" ]
then
echo "✅ Our club data is up to date."
echo "✅ Our club data is up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Our club data has changed! Pushing to repository."
git add ${{ env.SAMS_CLUB_JSON }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Our club data has changed. Pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_CLUBS_CACHE }} --dry-run)" ]
then
echo "✅ All club data up to date."
echo "✅ All club data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Some new club data detected! Pushing to repository."
git add ${{ env.SAMS_CLUBS_CACHE }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Some new club data detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_PLAYERS_CACHE }} --dry-run)" ]
then
echo "✅ All player data up to date."
echo "✅ All player data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Some new player data detected! Pushing to repository."
git add ${{ env.SAMS_PLAYERS_CACHE }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Some new player data detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_FOLDER }} --dry-run)" ]
then
echo "✅ SAMS data up to date."
echo "✅ SAMS data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 SAMS changes detected! Pushing to repository."
git add ${{ env.SAMS_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 SAMS changes detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY || true
if grep -q '"mastodon": "queued"' ${{ env.SOCIAL_CACHE_MATCHES }} || grep -q '"mastodon": "new"' ${{ env.SOCIAL_CACHE_MATCHES }};
then
echo "social=new" >> $GITHUB_OUTPUT
echo "🕵️ Unpublished Match Result for social detected! Queueing job."
echo "🕵️ Unpublished Match Result for social detected! Queueing job." >> $GITHUB_STEP_SUMMARY
if [ -z "$(git stage ${{ env.SOCIAL_CACHE_MATCHES }} --dry-run)" ]
then
echo "✅ No social cache file changes. Nothing to commit."
echo "✅ No social cache file changes. Nothing to commit." >> $GITHUB_STEP_SUMMARY
else
git add ${{ env.SOCIAL_CACHE_MATCHES }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "🏐 Changes in social cache detected! Pushing to repository."
echo "🏐 Changes in social cache detected! Pushing to repository." >> $GITHUB_STEP_SUMMARY
fi
else
echo "✅ No unpublished Match Result found."
echo "✅ No unpublished Match Result found." >> $GITHUB_STEP_SUMMARY
fi
- name: Process Inbox
id: process_inbox
if: ${{ github.event_name != 'schedule' }}
run: bun run inbox
- name: New Blog Post Check
id: blog_check
if: steps.process_inbox.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.BLOG_FOLDER }} --dry-run)" ]
then
echo "✅ No new blog post found."
echo "✅ No new blog post found." >> $GITHUB_STEP_SUMMARY
else
echo "📑 New Blog post detected! Pushing to repository and cleaning the inbox folder."
git add ${{ env.BLOG_FOLDER }}
git add ${{ env.IMAGES_FOLDER }}
git add ${{ env.INBOX_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=new" >> $GITHUB_OUTPUT
echo "📑 New Blog post detected. Sharing on social initiated." >> $GITHUB_STEP_SUMMARY
cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY
fi
- name: Build with Next.js
id: next_build
if: ${{ github.event.schedule != '15,45 09-21 * JAN-APR,OCT-DEC 0,6' || steps.sams_git.outputs.status == 'updated' }}
run: |
echo "status=started" >> $GITHUB_OUTPUT
bun run build
echo "👷 Build complete:" >> $GITHUB_STEP_SUMMARY
du -hsc out | grep -e "total" >> $GITHUB_STEP_SUMMARY
- name: Commit Optimized Images
if: steps.next_build.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.IMAGES_FOLDER }} --force --dry-run)" ]
then
echo "✅ Image optimizations are up to date."
echo "✅ Image optimizations are up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🖼️ New image optimizations! Pushing to repository."
git stage ${{ env.IMAGES_FOLDER }} --force
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "🖼️ New image optimizations changes detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
- name: Upload artifact
if: steps.next_build.conclusion == 'success'
uses: actions/upload-pages-artifact@v3
with:
path: ./out
# Deployment job
deploy:
name: "🚚 Deployment"
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: ${{ needs.build.outputs.build_status == 'started' }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Social sharing job
mastodon:
name: "💬 Share to Mastodon"
runs-on: ubuntu-latest
needs: [build, deploy]
if: ${{ needs.build.outputs.build_status == 'started' && (needs.build.outputs.sams_social == 'new' || needs.build.outputs.blog_check == 'new' || github.event_name == 'workflow_dispatch' ) }}
env:
MASTODON_CLIENT_ID: ${{ secrets.MASTODON_CLIENT_ID }}
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # latest commit, default is the commit that triggered the workflow
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: bun install
- name: Match Results
id: match_results
if: ${{ needs.build.outputs.sams_social == 'new' || github.event_name == 'workflow_dispatch' }}
run: bun run sams-new-results
- name: Blog Posts
id: blog_posts
if: ${{ needs.build.outputs.blog_check == 'new' || github.event_name == 'workflow_dispatch' }}
run: bun run blog-new-posts
- name: Commit Changes
id: commit_changes
if: steps.match_results.conclusion == 'success' || steps.blog_posts.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.SOCIAL_CACHE_MATCHES }} --dry-run)" ]
then
echo "✅ Match Results Cache file up to date."
echo "✅ Match Results Cache file up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Match Results Cache file modified! Pushing to repository."
echo "🏐 Match Results Cache file modified and pushed to repository." >> $GITHUB_STEP_SUMMARY
git add ${{ env.SOCIAL_CACHE_MATCHES }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
fi
if [ -z "$(git stage ${{ env.BLOG_FOLDER }} --dry-run)" ]
then
echo "✅ Blogs posts are up to date."
echo "✅ Blogs posts are up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Blog posts have been modified! Pushing to repository."
echo "🏐 Blog posts have been modified! Pushing to repository." >> $GITHUB_STEP_SUMMARY
git add ${{ env.BLOG_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
fi
- name: Github Summary
if: steps.commit_changes.conclusion == 'success'
continue-on-error: true
run: cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY | true