-
-
Notifications
You must be signed in to change notification settings - Fork 1
321 lines (310 loc) · 10.4 KB
/
ci.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
name: ci
concurrency:
cancel-in-progress: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
group: ci-${{ github.ref_name }}-${{ github.event_name }}
on:
pull_request:
branches:
- main
push:
branches:
- main
delete:
schedule:
- cron: "0 3 * * *" # Everyday, 10 WIB: building the site
permissions:
contents: write
env:
NETLIFY_SITE_ID: developer-friendly
NETLIFY_DEPLOY_TO_PROD: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
PYTHON_VERSION: 3.x
ADSENSE_PROPERTY: ${{ vars.ADSENSE_PROPERTY }}
GA_PROPERTY: ${{ vars.GA_PROPERTY }}
LOGROCKET_PROPERTY: ${{ vars.LOGROCKET_PROPERTY }}
jobs:
preview:
if: github.event_name == 'pull_request' && github.repository == 'developer-friendly/blog'
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
name: Install dependencies
run: |
pip install -U pip -r requirements.txt
sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant
- env:
DRAFT: ${{ github.event_name == 'pull_request' }}
GA_REPORTS_DSN: ${{ secrets.GA_REPORTS_DSN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # git-committers plugin
name: Build the site
run: mkdocs build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
name: build-pr${{ github.event.pull_request.number }}
path: site
- id: netlify
name: Deploy to Netlify
uses: jsmrcaga/action-netlify-deploy@v2.3.0
with:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_DEPLOY_TO_PROD: ${{ env.NETLIFY_DEPLOY_TO_PROD }}
NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }}
build_command: echo Skipping building the web files
build_directory: site
install_command: echo Skipping installing the dependencies
- name: Comment PR
uses: meysam81/comment-pr@main
with:
title: "# Live preview"
content: |
The live preview of the changes are available at the following URL:
<${{ env.NETLIFY_PREVIEW_URL }}>
token: ${{ secrets.GITHUB_TOKEN }}
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: |
github.repository == 'developer-friendly/blog' &&
(
(
github.event_name == 'push' &&
github.ref == 'refs/heads/main'
) || (
github.event_name == 'schedule' &&
github.event.schedule == '0 3 * * *'
)
)
permissions:
attestations: write
contents: read
id-token: write
pages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Calculate cache id
run: echo "cache_id=$(date --utc '+%j')" >> $GITHUB_ENV
- name: Cache mkdocs-material
uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
name: Install dependencies
run: |
pip install -U pip -r requirements.txt
sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant
- name: Set up google service account
run: |
cat << 'EOF' > /tmp/credentials.json
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_FILE }}
EOF
echo GOOGLE_APPLICATION_CREDENTIALS=/tmp/credentials.json >> $GITHUB_ENV
- env:
GA_REPORTS_DSN: ${{ secrets.GA_REPORTS_DSN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Build the site
run: mkdocs build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
name: build-${{ github.ref_name }}-${{ github.run_id }}
path: site
- id: deployment
name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
with:
artifact_name: build-${{ github.ref_name }}-${{ github.run_id }}
- if: ${{ github.repository == 'developer-friendly/blog' }}
id: netlify
name: Deploy to Netlify
uses: jsmrcaga/action-netlify-deploy@v2.3.0
with:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_DEPLOY_TO_PROD: ${{ env.NETLIFY_DEPLOY_TO_PROD }}
NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }}
build_command: echo Skipping building the web files
build_directory: site
install_command: echo Skipping installing the dependencies
lychee:
if: |
github.repository == 'developer-friendly/blog' &&
contains(fromJson('["schedule", "pull_request", "push"]'), github.event_name)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Calculate cache id
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- name: Cache lychee
uses: actions/cache@v4
with:
key: lychee-${{ env.cache_id }}
path: .lycheecache
restore-keys: |
lychee-
- id: lychee
name: Link Checker
uses: lycheeverse/lychee-action@v2
with:
fail: ${{ github.ref == 'refs/heads/main' }}
trivy:
if: |
github.repository == 'developer-friendly/blog' &&
contains(fromJson('["schedule", "pull_request", "push"]'), github.event_name)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scan-type:
- fs
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Trivy ${{ matrix.scan-type }}
uses: aquasecurity/trivy-action@master
with:
exit-code: "1"
scan-ref: .
scan-type: ${{ matrix.scan-type }}
trivy-config: trivy.yaml
sponsors:
runs-on: ubuntu-latest
if: |
github.repository == 'developer-friendly/blog' &&
github.ref == 'refs/heads/main' &&
contains(fromJson('["schedule", "pull_request", "push"]'), github.event_name)
permissions:
contents: write
pull-requests: write
env:
FALLBACK_MESSAGE: |
No sponsors yet. Become the first sponsor! 💝
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate Sponsors - readme
uses: JamesIves/github-sponsors-readme-action@v1
with:
token: ${{ secrets.PAT_SPONSORS }}
file: README.md
fallback: ${{ env.FALLBACK_MESSAGE }}
# - name: Generate Sponsors - sponsors
# uses: JamesIves/github-sponsors-readme-action@v1
# with:
# token: ${{ secrets.PAT_SPONSORS }}
# file: docs/sponsors.md
# fallback: ${{ env.FALLBACK_MESSAGE }}
- name: Verify changed
id: changed
run: |
changed=$(git status --porcelain)
if [ -n "$changed" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Configure git
if: steps.changed.outputs.changed == 'true'
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
- name: Commit changes
if: steps.changed.outputs.changed == 'true'
run: |
git add .
git checkout -b ${{ github.actor }}/chore/update-sponsors/${{ github.run_id }}
git commit -m "chore: update sponsors"
git push origin $(git branch --show-current)
- name: Create PR
if: steps.changed.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --fill -H $(git branch --show-current)
ga-reports:
runs-on: ubuntu-latest
if: |
(
github.event_name == 'schedule' &&
github.repository == 'developer-friendly/blog'
)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install requirements
run: pip install -U pip -r ./internal/ga/requirements.txt
- name: Set the GA report starting date to last month
run: |
GA4_START_DATE=$(date -d "$(date +%Y-%m-01) -1 month" +%Y-%m-01)
echo GA4_START_DATE=$GA4_START_DATE >> $GITHUB_ENV
- name: Set up google service account
run: |
cat << 'EOF' > /tmp/credentials.json
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_FILE }}
EOF
echo GOOGLE_APPLICATION_CREDENTIALS=/tmp/credentials.json >> $GITHUB_ENV
- env:
GA_REPORTS_DSN: ${{ secrets.GA_REPORTS_DSN }}
GA4_PROPERTY: ${{ vars.GA4_PROPERTY }}
LOG_LEVEL: DEBUG
name: Fetch GA reports into PostgreSQL
run: ./internal/ga/main.py update
stale:
if: |
(
github.event_name == 'schedule' &&
github.repository == 'developer-friendly/blog'
)
runs-on: ubuntu-latest
permissions:
contents: write # only for delete-branch option
issues: write
pull-requests: write
steps:
- uses: actions/stale@v9
mirror:
if: |
github.repository == 'developer-friendly/blog' &&
contains(fromJson('["delete", "push"]'), github.event_name)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Mirror GitLab
uses: pixta-dev/repository-mirroring-action@v1
with:
target_repo_url: git@gitlab.com:developer-friendly/blog.git
ssh_private_key: ${{ secrets.GITLAB_DEPLOY_KEY }}
- if: always()
name: Mirror Insiders
uses: pixta-dev/repository-mirroring-action@v1
with:
target_repo_url: git@github.com:developer-friendly/blog-insiders.git
ssh_private_key: ${{ secrets.INSIDERS_DEPLOY_KEY }}