Skip to content

Commit da65a1a

Browse files
Merge pull request #8837 from dotty-staging/rework-website-2
Rework website publishing workflow
2 parents 2b3bfc2 + 71ac3fc commit da65a1a

File tree

2 files changed

+43
-55
lines changed

2 files changed

+43
-55
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,18 @@ jobs:
308308
key: ${{ runner.os }}-general-${{ hashFiles('**/build.sbt') }}
309309
restore-keys: ${{ runner.os }}-general-
310310

311-
- name: Nightly Documentation
311+
- name: Generate Website
312312
run: |
313313
./project/scripts/genDocs -doc-snapshot
314314
315+
- name: Deploy Website
316+
uses: peaceiris/actions-gh-pages@v3
317+
with:
318+
personal_token: ${{ secrets.BOT_TOKEN }}
319+
publish_dir: docs/_site
320+
external_repository: lampepfl/dotty-website
321+
publish_branch: gh-pages
322+
315323
publish_release:
316324
runs-on: self-hosted
317325
container: lampepfl/dotty:2020-04-24
@@ -452,10 +460,18 @@ jobs:
452460
key: ${{ runner.os }}-general-${{ hashFiles('**/build.sbt') }}
453461
restore-keys: ${{ runner.os }}-general-
454462

455-
- name: Nightly Documentation
463+
- name: Generate Website
456464
run: |
457465
./project/scripts/genDocs -doc-snapshot
458466
467+
- name: Deploy Website
468+
uses: peaceiris/actions-gh-pages@v3
469+
with:
470+
personal_token: ${{ secrets.BOT_TOKEN }}
471+
publish_dir: docs/_site
472+
external_repository: lampepfl/dotty-website
473+
publish_branch: gh-pages
474+
459475
publish_sbt_release:
460476
runs-on: self-hosted
461477
container: lampepfl/dotty:2020-04-24

project/scripts/genDocs

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,38 @@
11
#!/usr/bin/env bash
22

3-
# Usage:
4-
# BOT_TOKEN=<dotty-bot password> ./genDocs [-doc-snapshot]
5-
63
set -e
7-
GENDOC_EXTRA_ARGS=$@
8-
9-
# set extended glob, needed for rm everything but x
10-
shopt -s extglob
4+
shopt -s extglob # needed for rm everything but x
5+
echo "Working directory: $PWD"
116

12-
# make sure that BOT_TOKEN is set
13-
if [ -z "$BOT_TOKEN" ]; then
14-
echo "Error: BOT_TOKEN env unset, unable to push without password" 1>&2
15-
exit 1
7+
GENDOC_EXTRA_ARGS=$@
8+
GIT_HEAD=$(git rev-parse HEAD) # save current head for commit message in gh-pages
9+
PREVIOUS_SNAPSHOTS_DIR="$PWD/../prev_snapshots"
10+
SCRIPT_DIR="(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)"
11+
SITE_OUT_DIR="$PWD/docs/_site"
12+
13+
### Obtain the previous versions of the website ###
14+
if [ -d "$PREVIOUS_SNAPSHOTS_DIR" ]; then
15+
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"
1616
fi
1717

18-
echo "Working directory: $PWD"
18+
mkdir -pv "$PREVIOUS_SNAPSHOTS_DIR"
19+
git remote add doc-remote "https://github.com/lampepfl/dotty-website.git"
20+
git fetch doc-remote gh-pages
21+
git checkout gh-pages
22+
(cp -vr 0.*/ "$PREVIOUS_SNAPSHOTS_DIR"; true) # Don't fail if no `0.*` found to copy
23+
git checkout "$GIT_HEAD"
1924

25+
### Generate the current snapshot of the website ###
2026
# this command will generate docs in $PWD/docs/_site
21-
SBT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/sbt"
27+
SBT="$SCRIPT_DIR/sbt"
2228
"$SBT" "dotty-bootstrapped/genDocs $GENDOC_EXTRA_ARGS"
2329

2430
# make sure that the previous command actually succeeded
25-
if [ ! -d "$PWD/docs/_site" ]; then
26-
echo "Output directory did not exist: $PWD/docs/_site" 1>&2
27-
exit 1
31+
if [ ! -d "$SITE_OUT_DIR" ]; then
32+
echo "Output directory did not exist: $SITE_OUT_DIR" 1>&2
33+
exit 1
2834
fi
2935

30-
# save current head for commit message in gh-pages
31-
GIT_HEAD=$(git rev-parse HEAD)
32-
33-
34-
# set up remote and github credentials
35-
git remote add doc-remote "https://dotty-bot:$BOT_TOKEN@github.com/lampepfl/dotty-website.git"
36-
git config user.name "dotty-bot"
37-
git config user.email "dotty-bot@d-d.me"
38-
39-
# check out correct branch
40-
git fetch doc-remote gh-pages
41-
git checkout gh-pages
42-
43-
# save the old snapshots to the newly generated site
44-
# This command must never fail since failures short-circuit the script
45-
# The reason for failure is that no folder matches "0.*" pattern
46-
# because snapshots may not be generated yet
47-
(mv 0.*/ $PWD/docs/_site; true)
48-
49-
# move newly generated _site dir to $PWD
50-
mv $PWD/docs/_site .
51-
52-
# remove everything BUT _site dir
53-
rm -rf !(_site)
54-
55-
# copy new contents to $PWD
56-
mv _site/* .
57-
58-
# remove now empty _site dir
59-
rm -rf _site
60-
61-
# add all contents of $PWD to commit
62-
git add -A
63-
git commit -m "Update gh-pages site for $GIT_HEAD" || echo "nothing new to commit"
64-
65-
# push to doc-remote
66-
git push doc-remote || echo "couldn't push, since nothing was added"
36+
### Move previous versions' snapshots to _site ###
37+
mv -v "$PREVIOUS_SNAPSHOTS_DIR"/* "$SITE_OUT_DIR"
38+
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"

0 commit comments

Comments
 (0)