-
Notifications
You must be signed in to change notification settings - Fork 5
/
publish.sh
63 lines (50 loc) · 1.67 KB
/
publish.sh
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
#! /bin/bash
# Based on @zporter's publish script.
# See https://zachporter.dev/posts/publishing-hugo-with-github-actions/
# abort on nonzero exitstatus
set -o errexit
# abort on unbound variable
set -o nounset
# Output directory
output_dir=gh-pages
# Usage: update_changed_on_message FILE
# Function that updates the message at the bottom of a page with the time
# stamp of the last change.
update_changed_on_message() {
local file="${1}"
local prompt="Laatste wijziging: "
local timestamp
timestamp=$(LC_TIME=nl_BE date)
sed -i "s/^${prompt}/${prompt}${timestamp}/" "${file}"
}
# Exit if there are local changes
if [ "$(git status -s)" ]; then
printf 'Changes detected in working directory. Commit them before proceeding.\n'
exit 1
fi
printf 'Deleting old publication\n'
rm -rf "${output_dir}"
mkdir "${output_dir}"
git worktree prune
rm -rf ".git/worktrees/${output_dir}"
printf 'Fetch gh-pages branch\n'
git fetch origin gh-pages
printf 'Checking out gh-pages branch\n'
git worktree add -B gh-pages ${output_dir} origin/gh-pages
printf 'Deleting generated files\n'
make clean
printf 'Running make to generate new version\n'
make all # Generate slides
# Copy tables of content
cp datalinux.md "${output_dir}"
cp opslinux.md "${output_dir}"
cp index.md "${output_dir}"/README.md
update_changed_on_message "${output_dir}/datalinux.md"
update_changed_on_message "${output_dir}/opslinux.md"
update_changed_on_message "${output_dir}/README.md"
printf 'Updating gh-pages branch\n'
cd "${output_dir}" \
&& git add --all \
&& git commit -m "Publishing to gh-pages (${0}) at $(date --utc --iso-8601=seconds)"
printf 'Pushing to Github\n'
git push "${REPOSITORY:-origin}" gh-pages