-
Notifications
You must be signed in to change notification settings - Fork 1
214 lines (186 loc) · 6.44 KB
/
build-site.yaml
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
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
name: Update website
jobs:
checks:
name: Set-up build params
runs-on: ubuntu-latest
outputs:
POST: ${{ steps.check-post.outputs.POST }}
POST_DATE: ${{ steps.check-date.outputs.POST_DATE }}
ANNOUNCE: ${{ steps.check-date.outputs.ANNOUNCE }}
DOI: ${{ steps.check-doi.outputs.DOI }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: 📝 Get latest blog post 📝
id: check-post
env:
BLOG_PATH: "content/blog"
run: |
# Find the latest blog post
latest_post=$(find "${BLOG_PATH}" | grep /index.md$ | grep -v "XX-XX" | sort | tail -n1)
echo "POST=${latest_post}" >> $GITHUB_OUTPUT
- name: Check post date
id: check-date
run: |
post_date=$(grep "^date:" "${{ steps.check-post.outputs.POST }}" | sed 's/^date: //' | sed 's/["'\'']//g')
echo "POST_DATE=${post_date}" >> $GITHUB_OUTPUT
one_day_ago=$(date -d "-1 days" +%Y%m%d)
post_date=$(date -d "${post_date}" +%Y%m%d)
echo "ANNOUNCE=false" >> $GITHUB_OUTPUT
if [ "${post_date}" -gt "${one_day_ago}" ]; then
echo "ANNOUNCE=true" >> $GITHUB_OUTPUT
fi
- name: Check if needs DOI
id: check-doi
run: |
# Does the post need a DOI?
echo "DOI=true" >> $GITHUB_OUTPUT
if head -n 10 "${{ steps.check-post.outputs.POST }}" | grep -q "doi:"; then
echo "DOI=false" >> $GITHUB_OUTPUT
fi
check-output:
name: check github output
runs-on: ubuntu-latest
needs: checks
steps:
- name: Debug Outputs
run: |
echo "ANNOUNCE: ${{ needs.checks.outputs.ANNOUNCE }}"
echo "DOI: ${{ needs.checks.outputs.DOI }}"
echo "POST: ${{ needs.checks.outputs.POST }}"
echo "POST_DATE: ${{ needs.checks.outputs.POST_DATE }}"
build:
name: Build site
runs-on: ubuntu-latest
needs: checks
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PROFILE: zenodo
RUN_DOI: ${{ github.ref == 'refs/heads/main' && needs.checks.outputs.DOI == 'true' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: true
- name: Setup variables
id: version
run: |
ver=$(cat .Rprofile | grep hugo.version | cut -d'"' -f2 )
echo "hugo_v=${ver}" >> $GITHUB_ENV
nalias=$(echo ${{ github.head_ref }} | sed 's/_/-/g')
echo "nalias=${nalias}" >> $GITHUB_ENV
echo ${{ env.RUN_DOI }}
- name: Install cURL Headers
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- name: Install pdf svg handler
if: ${{ env.RUN_DOI == 'true' }}
run: sudo apt-get install librsvg2-dev
- name: Setup R
if: ${{ env.RUN_DOI == 'true' }}
uses: r-lib/actions/setup-r@v2
with:
r-version: 'renv'
- name: Setup renv
if: ${{ env.RUN_DOI == 'true' }}
uses: r-lib/actions/setup-renv@v2
- name: Setuo Quarto
if: ${{ env.RUN_DOI == 'true' }}
uses: quarto-dev/quarto-actions/setup@v2
- name: Setup Tinytex
if: ${{ env.RUN_DOI == 'true' }}
uses: r-lib/actions/setup-tinytex@v2
- name: Add doi
if: ${{ env.RUN_DOI == 'true' }}
env:
ZENODO_API_TOKEN: ${{ secrets.ZENODO_API_TOKEN }}
run: |
Rscript -e 'renv::restore()'
Rscript .github/scripts/add_doi.R
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ env.hugo_v }}
extended: true
- name: Build
run: |
if [[ '${{github.ref}}' == 'refs/heads/main' ]]; then
hugo -e production
else
hugo \
--buildDrafts \
--buildFuture \
-b https://${{ env.nalias }}--drmowinckels.netlify.app/
fi
- name: Deploy production 🚀
if: github.ref == 'refs/heads/main'
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: public
- name: Deploy to Netlify
id: netlify
if: github.event_name == 'pull_request'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
npm install netlify-cli -g
netlify deploy --alias ${{ env.nalias }}
shell: sh
- uses: actions/github-script@v7
if: steps.netlify.outcome == 'success'
name: "Notify about build preview"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.createComment({
issue_number: ${{ github.event.pull_request.number }},
owner: 'drmowinckels',
repo: 'drmowinckels.github.io',
body: ':tada: The preview is built! [Check it out :eyes:](https://${{ env.nalias }}--drmowinckels.netlify.app/)'
})
- name: Commit content with doi
if: github.ref == 'refs/heads/main'
run: |
git commit content/blog -m 'Add doi' || echo "No changes to commit"
git push origin || echo "No changes to commit"
announce:
name: Announce new blog post
runs-on: ubuntu-latest
needs: [build, checks]
if: needs.checks.outputs.ANNOUNCE == 'true' && github.ref == 'refs/heads/main'
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PROFILE: social_media
steps:
- uses: actions/checkout@v4
- name: Install cURL Headers
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: 'renv'
- name: Setup renv
uses: r-lib/actions/setup-renv@v2
- name: Announce the post
env:
BLUESKY_APP_PASS: ${{ secrets.BLUESKY_PWD }}
BLUESKY_APP_USER: "drmowinckels.io"
run: |
echo RTOOT_DEFAULT_TOKEN="${{ secrets.RTOOT_TOKEN }}" >> .Renviron
echo KIT_SECRET="${{ secrets.KIT_KEY }}" >> .Renviron
Rscript .github/scripts/announce.R ${{ needs.checks.outputs.POST }}