-
Notifications
You must be signed in to change notification settings - Fork 3
/
nist-pages-deploy.sh
executable file
·48 lines (40 loc) · 1.58 KB
/
nist-pages-deploy.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
#!/bin/bash
# https://gitlab.nist.gov/gitlab/eldst/eerc/-/blob/master/publish-on-nist-pages
TEMP_BRANCH=temp-split
PAGES_BRANCH=nist-pages
MASTER_REMOTE=nist-origin
PAGES_REMOTE=nist-origin
BUILD_DIR="$MKDOCS_SITE_DIR"
opt_force=""
if [ "$1" = "-f" ]; then
opt_force="-f"
fi
die() {
echo "$@" >> /dev/stderr
exit 1
}
cleanup() {
git branch -D "$TEMP_BRANCH" >/dev/null 2>&1 # Ignore errors; branch probably doesn't exist anyway
git branch -D "$PAGES_BRANCH" >/dev/null 2>&1 # Ignore errors; branch probably doesn't exist anyway
rm -rf build
}
if [ ! -d .git ]; then
die "You must run this from the root of the master repo"
fi
cleanup
status=$(git status --porcelain -b)
echo $status | egrep -q '^##\smaster\.\.\.' || die "Must be run while master is checked out"
changes=$(echo "$status" | egrep -v '^(##|\?\?)' | wc -l)
if [ "$changes" -ne 0 -a -z "$opt_force" ]; then
die "You have uncommited changes - run with '-f' to force but CAUTION: CHANGES WILL BE LOST!"
fi
# npm run build || die "'npm run build' failed"
poetry run task deploy
git checkout $opt_force -b $TEMP_BRANCH || die "Could not create branch $TEMP_BRANCH" # should bring over build directory
git add -f $BUILD_DIR || die "Could not add $BUILD_DIR to $TEMP_BRANCH"
git commit -m "irrelevant commit for $PAGES_BRANCH generation" || die "Could not commit to $TEMP_BRANCH"
git subtree split --prefix build -b "$PAGES_BRANCH" || die "'git subtree split' failed"
git checkout master || die "'git checkout master' failed"
git push -f "${PAGES_REMOTE}" "${PAGES_BRANCH}:${PAGES_BRANCH}" || die "'git push' failed"
cleanup
exit 0