-
-
Notifications
You must be signed in to change notification settings - Fork 44
416 lines (377 loc) · 14.6 KB
/
build.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
name: Build
on:
pull_request: {}
push:
branches:
- main
schedule:
- cron: '0 0 * * *'
workflow_dispatch: {}
jobs:
build:
name: Build (${{ matrix.channel }})
runs-on: ubuntu-latest
env:
CI: 'true'
strategy:
fail-fast: false
matrix:
channel:
- release
- beta
steps:
- name: Set up Git
run: |
git config --global user.name "Tomster"
git config --global user.email "tomster@emberjs.com"
- name: Set up Volta
uses: volta-cli/action@v4
- name: Set up build cache (yarn)
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies (apt-get)
run: |
sudo apt-get update -y
sudo apt-get install -y tree
- name: Install dependencies (yarn)
run: |
if [[ "$EMBER_RELEASE_CHANNEL" == "beta" ]]; then
yarn upgrade ember-cli@beta
else
yarn upgrade ember-cli
fi
yarn install
env:
EMBER_RELEASE_CHANNEL: ${{ matrix.channel }}
- name: Lint (markdown source)
run: yarn lint:md:src
- name: Lint (typescript)
run: yarn lint:ts
- name: Compile (typescript)
run: yarn tsc
- name: Generate
run: yarn generate
env:
# This is needed for external PRs to build, since secrets are not
# available there. Get your own Mapbox token for local development
# at: https://account.mapbox.com/access-tokens
MAPBOX_ACCESS_TOKEN: 'pk.eyJ1IjoiZW1iZXJqcyIsImEiOiJjazBydnZjb2wwYXA5M2Rwc3IydGF2eXM0In0.EQiBFsRi9Jm70XFPiXnoHg'
- name: Lint (markdown output)
run: yarn lint:md:dist
- name: Prune artifacts
if: always()
working-directory: dist/code/super-rentals
run: git clean -dfX
- name: Upload artifacts (assets)
uses: actions/upload-artifact@v3
if: always()
with:
name: assets (${{ matrix.channel }})
path: dist/assets
- name: Upload artifacts (markdown)
uses: actions/upload-artifact@v3
if: always()
with:
name: markdown (${{ matrix.channel }})
path: dist/markdown
- name: Upload artifacts (code)
uses: actions/upload-artifact@v3
if: always()
with:
name: code (${{ matrix.channel }})
path: dist/code/super-rentals
deploy-guides:
# This job deploys the markdown output to the super-rentals-tutorial branch
# of the ember-learn/guides-source repository, along with the necessary
# assets (downloads and screenshots).
#
# For the markdown, we can simply copy over the output into the appropriate
# folder in guides-source. We start by emptying out the folder to account
# for any deleted or renamed chapters.
#
# For the downloads, it is also mostly a matter of copying them into the
# right location. As with the markdown content, we empty out the folder
# beforehand to account for deleted and renamed files.
#
# The JSON data used in the tutorial (for mocking an API server) is stored
# as loose files in this repository, to make them easier to change and
# review. However, we ultimately want to provide it for download as a zip
# file, so we need to zip up the contents.
#
# However, even if the JSON content didn't actually change, the raw bytes
# of the zip file may be different from the current version committed to
# git, due to differences in compression settings, etc. To ensure we don't
# churn the git blobs for no reason, we use the zipcmp utility to compare
# the contents before adding the zip file. We also run it through advzip to
# improve the compression ratio.
#
# Finally, screenshots also have the same problems as the zip file. Even
# if the screenshot didn't visually change, the raw bytes are likely to be
# different due to micro differences in pixel colors, etc. To account for
# this, we use the perceptualdiff utility to compare them against what is
# in git before adding them. We also run them through optipng and advpng to
# improve the compression ratio. This can be quite slow, so only do it if
# we detected visual changes in the screenshots.
#
# Once all the necessary parts are added, we simply commit and push to the
# super-rentals-tutorial branch of the ember-learn/guides-source repository
# if there are any changes in its content.
#
name: Deploy to ember-learn/guides-source (super-rentals-tutorial branch)
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Set up Git
run: |
git config --global user.name "Tomster"
git config --global user.email "tomster@emberjs.com"
- name: Set up SSH
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.GUIDES_SOURCE_DEPLOY_KEY }}
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y zipcmp advancecomp optipng perceptualdiff
- name: Download artifacts (assets)
uses: actions/download-artifact@v3
with:
name: assets (release)
path: assets
- name: Download artifacts (markdown)
uses: actions/download-artifact@v3
with:
name: markdown (release)
path: markdown
- name: Clone
run: |
set -euo pipefail
IFS=$'\n\t'
if ! git clone git@github.com:ember-learn/guides-source --depth 1 -b super-rentals-tutorial; then
git clone git@github.com:ember-learn/guides-source --depth 1 -b master
cd guides-source
git checkout -b super-rentals-tutorial
fi
- name: Add markdown
working-directory: guides-source
run: |
mkdir -p guides/release/tutorial/
rm -rf guides/release/tutorial/*
cp -r ../markdown/* guides/release/
git add guides/release
- name: Add downloads
working-directory: guides-source
run: |
set -euo pipefail
IFS=$'\n\t'
mkdir -p public/downloads/
rm -rf public/downloads/*
cp -r ../assets/downloads/* public/downloads/
pushd public/downloads/data/
zip -r current.zip .
popd
if ! (git checkout -- public/downloads/data.zip 2>&1 && zipcmp public/downloads/data.zip public/downloads/data/current.zip); then
mv public/downloads/data/current.zip public/downloads/data.zip
advzip -z -q -4 public/downloads/data.zip
fi
rm -rf public/downloads/data
git add public/downloads
- name: Add screenshots
working-directory: guides-source
run: |
set -euo pipefail
IFS=$'\n\t'
mkdir -p tmp/prev
git checkout-index -f -a --prefix=tmp/prev/
mkdir -p public/images/tutorial
rm -rf public/images/tutorial/*
function add_screenshot {
local src="$1";
local prev=$(echo -n "$1" | sed "s|../assets/|tmp/prev/public/|");
local dest=$(echo -n "$1" | sed "s|../assets/|public/|");
local diff=$(echo -n "$1" | sed "s|../assets/|tmp/perceptualdiff/|" | sed "s|@2x.png|.ppm|");
mkdir -p "$(dirname "$dest")"
mkdir -p "$(dirname "$diff")"
if [[ -f "$prev" ]]; then
if git diff --no-index -- "$prev" "$src" > /dev/null 2>&1; then
echo "$dest (unchanged)"
cp "$prev" "$dest"
return 0
elif perceptualdiff --output "$diff" --downsample 2 --colorfactor 0.5 "$prev" "$src" > /dev/null; then
echo "$dest (unchanged)"
cp "$prev" "$dest"
return 0
fi
fi
cp "$src" "$dest"
optipng -q -o5 "$dest"
advpng -z -q -4 "$dest"
local before=$(wc -c < "$src")
local after=$(wc -c < "$dest")
local percentage=$(( $after * 100 / $before ))
echo "$dest ($percentage%)"
return 0
}
export -f add_screenshot
find ../assets/images -type f -name "*.png" | xargs -n 1 -P 2 -I {} bash -c 'add_screenshot "$@"' _ {}
git add public/images
- name: Upload artifacts (perceptualdiff)
uses: actions/upload-artifact@v3
if: always()
with:
name: perceptualdiff (release)
path: guides-source/tmp/perceptualdiff
- name: Commit
working-directory: guides-source
run: |
set -euo pipefail
IFS=$'\n\t'
if [[ "$GITHUB_EVENT_NAME" == "schedule" ]]; then
COMMIT_TITLE="[CRON] $(date +"%A %b %d, %Y")"
else
COMMIT_TITLE="$(
echo -n "$ORIGINAL_COMMIT_MESSAGE" | \
sed -E "s|^Merge pull request #(.+) from .+$|Merge $GITHUB_REPOSITORY#\1|"
)"
fi
COMMIT_MESSAGE="$COMMIT_TITLE
---
Commit: $GITHUB_REPOSITORY@$GITHUB_SHA
Script: https://github.com/$GITHUB_REPOSITORY/blob/$GITHUB_SHA/.github/workflows/build.yml
Logs: https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA/checks"
git commit --allow-empty -m "$COMMIT_MESSAGE"
env:
ORIGINAL_COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
- name: Push
working-directory: guides-source
run: |
set -euo pipefail
IFS=$'\n\t'
if git diff --exit-code HEAD~; then
echo "Nothing to push"
else
git push -u origin super-rentals-tutorial
fi
deploy-code-preserving-history:
# This job deploys the built app to the super-rentals-tutorial-output
# branch of the ember-learn/super-rentals repository. This branch preserves
# the commit history of the tutorial flow (i.e. one git commit per chapter),
# and is force-pushed on every build. We add an empty commit on top as sort
# of a "cover page" to preserve the metadata (links to the commit, build
# logs, etc).
#
name: Deploy to ember-learn/super-rentals (super-rentals-tutorial-output branch)
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Set up Git
run: |
git config --global user.name "Tomster"
git config --global user.email "tomster@emberjs.com"
- name: Set up SSH
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.SUPER_RENTALS_DEPLOY_KEY }}
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: code (release)
path: .
- name: Commit
run: |
set -euo pipefail
IFS=$'\n\t'
if [[ "$GITHUB_EVENT_NAME" == "schedule" ]]; then
COMMIT_TITLE="[CRON] $(date +"%A %b %d, %Y")"
else
COMMIT_TITLE="$(
echo -n "$ORIGINAL_COMMIT_MESSAGE" | \
sed -E "s|^Merge pull request #(.+) from .+$|Merge $GITHUB_REPOSITORY#\1|"
)"
fi
COMMIT_MESSAGE="$COMMIT_TITLE
---
Commit: $GITHUB_REPOSITORY@$GITHUB_SHA
Script: https://github.com/$GITHUB_REPOSITORY/blob/$GITHUB_SHA/.github/workflows/build.yml
Logs: https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA/checks"
git commit --allow-empty -m "$COMMIT_MESSAGE"
env:
ORIGINAL_COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
- name: Push
run: |
git remote add super-rentals git@github.com:ember-learn/super-rentals.git
git push -f super-rentals master:super-rentals-tutorial-output
deploy-code-flattened:
# This job deploys the built app to the main branch of the
# ember-learn/super-rentals repository. This branch does not preserve
# the commit history of the tutorial flow. Instead, it squashes the changes
# into a single commit on the main branch. This preserves
# a linear history of changes to the built app over time, either due to
# changes to the generator blueprints, or changes to the tutorial content
# itself (e.g. refactoring to use new ember features). A lot of times, the
# built app's source code remains stable and so there may be no changes to
# push here.
#
name: Deploy to ember-learn/super-rentals (main branch)
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Set up Git
run: |
git config --global user.name "Tomster"
git config --global user.email "tomster@emberjs.com"
- name: Set up SSH
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.SUPER_RENTALS_DEPLOY_KEY }}
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: code (release)
path: output
- name: Clone
run: git clone git@github.com:ember-learn/super-rentals --depth 1
- name: Commit
working-directory: super-rentals
run: |
set -euo pipefail
IFS=$'\n\t'
git rm -rf '*'
if [[ "$GITHUB_EVENT_NAME" == "schedule" ]]; then
COMMIT_TITLE="[CRON] $(date +"%A %b %d, %Y")"
else
COMMIT_TITLE="$(
echo -n "$ORIGINAL_COMMIT_MESSAGE" | \
sed -E "s|^Merge pull request #(.+) from .+$|Merge $GITHUB_REPOSITORY#\1|"
)"
fi
COMMIT_MESSAGE="$COMMIT_TITLE
---
Commit: $GITHUB_REPOSITORY@$GITHUB_SHA
Script: https://github.com/$GITHUB_REPOSITORY/blob/$GITHUB_SHA/.github/workflows/build.yml
Logs: https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA/checks"
git commit --allow-empty -m "$COMMIT_MESSAGE"
git remote add output ../output
git fetch output
git merge --squash --no-commit --allow-unrelated-histories output/master
git reset HEAD~ -- README.md app.json
git commit --allow-empty --amend --no-edit
env:
ORIGINAL_COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
- name: Push
working-directory: super-rentals
run: |
set -euo pipefail
IFS=$'\n\t'
if git diff --exit-code origin/main; then
echo "Nothing to push"
else
git push
fi