-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (173 loc) · 5.03 KB
/
render.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
name: Render templates
on:
push:
branches:
- main
pull_request:
jobs:
build:
name: Generate content
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version-file: '.python-version'
- name: Install dependencies
run: bash ./scripts/setup.sh
- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Install
run: yarn install
- name: Build newsletters
run: bash ./scripts/render-all.sh
- name: Upload output for deployment
uses: actions/upload-pages-artifact@v2
with:
path: out/html
changes:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
outputs:
build-system: ${{ steps.filter.outputs.build-system }}
steps:
- name: Check if build system changed
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build-system:
- .github/**/*
- package.json
- yarn.lock
- requirements.txt
- scripts/render*
- scripts/setup.sh
build-main:
needs:
- changes
if: needs.changes.outputs.build-system == 'true'
env:
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path.
# See https://github.com/ruby/setup-ruby/issues/291
GLOBAL_GEMS: 1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version-file: '.python-version'
- name: Install dependencies
run: bash ./scripts/setup.sh
- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Install
run: yarn install
- name: Build newsletters
run: bash ./scripts/render-all.sh
- name: Upload baseline
uses: actions/upload-pages-artifact@v2
with:
name: build-from-main
path: out/html
diff:
runs-on: ubuntu-latest
needs:
- build
- build-main
permissions:
pull-requests: write
steps:
- name: Download artifact from this branch's build
uses: actions/download-artifact@v3
with:
name: github-pages
- name: Unpack local build
run: |
mkdir local
pushd local
tar --extract --file ../artifact.tar
popd
mv artifact.tar local.tar
- name: Download artifact from main branch build
uses: actions/download-artifact@v3
with:
name: build-from-main
path: main
- name: Replace build timestamps
run: sed -i -r '1 s_<updated>[^/]+</updated>_<updated>NOW</updated>_' {main,local}/feed.xml
- name: Diff
id: diff
run: |
set +e
diff -ru main local > ./result.diff
result=$?
set -euo pipefail
delimiter="gha-delim-$RANDOM-$RANDOM-gha-delim"
{
echo "diff<<${delimiter}"
cat ./result.diff
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
cat ./result.diff
if [[ $result -ne 0 ]]
then
echo has-changes=true >> "$GITHUB_OUTPUT"
else
echo has-changes=false >> "$GITHUB_OUTPUT"
fi
- name: Build comment
id: build-comment
if: always()
run: |
{
if [[ "${{ steps.diff.outputs.has-changes }}" = "true" ]]
then
echo "🔀 Build diff:"
echo '```diff'
cat ./result.diff
echo '```'
else
echo "Build has no changes."
fi
} > ./comment.md
- name: Post diff to PR
uses: thollander/actions-comment-pull-request@v2
if: always()
with:
comment_tag: build-diff
filePath: ./comment.md
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: build
if: ${{ github.ref == 'refs/heads/main' }}
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
# Tell GitHub where we deployed to
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2