-
Notifications
You must be signed in to change notification settings - Fork 27
/
build
executable file
·146 lines (126 loc) · 4.9 KB
/
build
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
#!/bin/bash
# Process environment variables
if [[ "$TRAVIS_PULL_REQUEST" =~ ^[0-9]+$ ]]; then
echo "Building pull request #$TRAVIS_PULL_REQUEST, will skip deploy" >&2
NO_DEPLOY=true
unset GITHUB_TOKEN GH_TOKEN TRAVIS_GITHUB_TOKEN
fi
unset DEPLOY # should not appear in environment
while [ $# -ne 0 ]; do
case $1 in
--deploy)
[ -z "$NO_DEPLOY" ] && DEPLOY=true
;;
*)
# unknown option
;;
esac
shift
done
function force-fetch {
if [[ -d "$1/.git" ]]; then
echo "Force-fetching $1..."
bash -c "cd '$1' && git checkout -q master && git fetch -q && git reset --hard -q origin/master"
else
rm -rf "$1"
git clone --depth 1 -q -b master "$2" "$1"
fi
}
: "${GITHUB_REPOSITORY:=${TRAVIS_REPO_SLUG:-Charcoal-SE/charcoal-se.github.io}}"
if [ -z "$DEPLOY" ]; then
echo "Not in deploy mode, not pushing changes."
force-fetch _site "https://github.com/${GITHUB_REPOSITORY}" &
else
if [ -n "$GITHUB_ACTOR" -a -n "$GITHUB_TOKEN" ]; then
echo "GitHub Actions environment detected."
force-fetch _site "https://$GITHUB_ACTOR:[email protected]/${GITHUB_REPOSITORY}" &
elif [ -n "$GH_TOKEN" ]; then
echo "\$GH_TOKEN found, use as personal access token."
force-fetch _site "https://[email protected]/${GITHUB_REPOSITORY}" &
else
echo "No token provided. Cannot push changes."
force-fetch _site "https://github.com/${GITHUB_REPOSITORY}" &
fi
fi
force-fetch ms "https://github.com/Charcoal-SE/metasmoke.wiki" &
force-fetch smokey "https://github.com/Charcoal-SE/SmokeDetector.wiki" &
wait
for file in **/Home.md; do
mv "$file" "$(dirname "$file")/index.md"
done
script/add-front-matter.rb ms/** smokey/** &
script/create-data-files.rb &
wait
# yes I know this space padding is strange, but it looks tidy, no?
self_time="$( date -d "$(git log -1 --pretty=%cI)" +%s)"
ms_wiki_time="$( date -d "$(git -C ./ms log -1 --pretty=%cI)" +%s)"
smokey_wiki_time="$(date -d "$(git -C ./smokey log -1 --pretty=%cI)" +%s)"
self_info="$( git log -1 --pretty="Website commit: [%h] %s")"
ms_wiki_info="$( git -C ./ms log -1 --pretty="MS wiki commit: [%h] %s")"
smokey_wiki_info="$(git -C ./smokey log -1 --pretty="Smokey wiki commit: [%h] %s")"
# Find out which one is last changed, highlight it in log output
# and use it in the commit message of the built website
if [ $self_time -ge $ms_wiki_time -a $self_time -ge $smokey_wiki_time ]; then
COMMIT_INFO="$( git log -1 --pretty="[%h] %an: %B")"
self_info="$( git log -1 --color --pretty="%C(green bold)Website commit: [%h] %s%Creset")"
elif [ $ms_wiki_time -ge $self_time -a $ms_wiki_time -ge $smokey_wiki_time ]; then
COMMIT_INFO="$( git -C ./ms log -1 --pretty="[%h] MS wiki: %B")"
ms_wiki_info="$( git -C ./ms log -1 --color --pretty="%C(green bold)MS wiki commit: [%h] %s%Creset")"
elif [ $smokey_wiki_time -ge $self_time -a $smokey_wiki_time -ge $ms_wiki_time ]; then
COMMIT_INFO="$( git -C ./smokey log -1 --pretty="[%h] Smokey wiki: %B")"
smokey_wiki_info="$(git -C ./smokey log -1 --color --pretty="%C(green bold)Smokey wiki commit: [%h] %s%Creset")"
else # nonsense condition
COMMIT_INFO="Something wrong???"
fi
echo
echo "$self_info"
echo "$ms_wiki_info"
echo "$smokey_wiki_info"
echo
export PAGES_ENV=dotcom PAGES_REPO_NWO="$GITHUB_REPOSITORY"
if [ -n "$DEPLOY" ]; then
export JEKYLL_ENV=production
if [ -n "$ALGOLIA_API_KEY" ]; then
bundle exec jekyll algolia push --trace &
fi
bundle exec jekyll build --incremental --profile --trace &
wait
else
bundle exec jekyll build --incremental --profile --trace
fi
pushd _site &>/dev/null # _site
pushd assets &>/dev/null # _site/assets
mkdir -p css images
for file in branding*.css; do
cp "$file" css/branding.css
done
for file in charcoal*.png; do
cp "$file" images/charcoal.png
done
popd &>/dev/null # OLDPWD=_site/assets/; PWD=_site/
if [ -n "$DEPLOY" ]; then
:> .nojekyll
git add --all
git config push.default tracking
if [ -n "$TRAVIS_COMMIT" ]; then
git -c user.name=SmokeDetector -c [email protected] \
commit --allow-empty -q \
-m "Auto deploy from Travis CI build ${TRAVIS_BUILD_NUMBER:-<unknown>}" \
-m "Changed: ${COMMIT_INFO}"
git push -q
elif [ -n "$GITHUB_ACTIONS" ]; then
git -c user.name=SmokeDetector -c [email protected] \
commit --allow-empty -q \
-m "Auto deploy from GitHub Actions build ${GITHUB_RUN_NUMBER:-<unknown>}" \
-m "Changed: ${COMMIT_INFO}"
git push -q
else
git -c user.name=SmokeDetector -c [email protected] \
commit --allow-empty -q \
-m "Website built from $(git -C .. log -1 --pretty="%h")" \
-m "Changed: ${COMMIT_INFO}"
echo -e "Not on Travis CI, skipped push to GitHub Pages."
fi
fi
popd &>/dev/null # OLDPWD=_site/; PWD=(git root)
# vim: set et sts=2 sw=2: