Skip to content

Commit

Permalink
Refactor scripts to support branch switching and flattening of `gh-pa…
Browse files Browse the repository at this point in the history
…ges`.
  • Loading branch information
olson-sean-k committed May 31, 2019
1 parent 73b39d4 commit d8cc3ae
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 57 deletions.
23 changes: 3 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@ set -e
cd $(dirname "$BASH_SOURCE")
repo_dir=`pwd`

src_dir="$repo_dir"/src
out_dir="$repo_dir"/out
mkdocs_out_dir="$out_dir"/doc
rustdoc_out_dir="$out_dir"/lib/target/doc
src_hash=`cat "$out_dir"/hash`

which cargo > /dev/null
which git > /dev/null
which peru > /dev/null
cp -r "$repo_dir"/script "$out_dir"

mkdir -p "$out_dir"
git rev-parse --short HEAD > "$out_dir"/hash

peru reup

echo "Building website documentation."
mkdocs build > /dev/null

echo "Building API documentation."
"$out_dir"/lib/rustdoc.sh -p decorum -p theon --all-features --manifest-path="$out_dir"/lib/Cargo.toml > /dev/null
rm -rf "$mkdocs_out_dir"/rustdoc
cp -r "$rustdoc_out_dir" "$mkdocs_out_dir"/rustdoc

echo "Done."
"$out_dir"/script/build.sh
18 changes: 0 additions & 18 deletions checkout.sh

This file was deleted.

18 changes: 0 additions & 18 deletions patch.sh

This file was deleted.

2 changes: 1 addition & 1 deletion peru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ imports:

git module plexus:
url: https://github.com/olson-sean-k/plexus.git
rev: 2734e88377ff1895e161ed42cbea1c8e3da3c136
rev: 34232ed83210c74661d8bfb11204f00e576c6943
13 changes: 13 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/env bash

set -e

cd $(dirname "$BASH_SOURCE")
repo_dir=`pwd`

out_dir="$repo_dir"/out
src_hash=`cat "$out_dir"/hash`

cp -r "$repo_dir"/script "$out_dir"

"$out_dir"/script/publish.sh
34 changes: 34 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env bash

# Fetch and build the API documentation via `rustdoc` and the website
# documentation via `mkdocs` and write the outputs to the `out` directory.

set -e

cd $(dirname "$BASH_SOURCE")
script_dir=`pwd`

repo_dir="$script_dir"/../..
src_dir="$repo_dir"/src
out_dir="$repo_dir"/out
mkdocs_out_dir="$out_dir"/doc
rustdoc_out_dir="$out_dir"/lib/target/doc

cd "$repo_dir"

which cargo > /dev/null
which git > /dev/null
#which peru > /dev/null

git checkout master

mkdir -p "$out_dir"
git rev-parse --short HEAD > "$out_dir"/hash

#peru reup

mkdocs build > /dev/null

"$out_dir"/lib/rustdoc.sh --all-features --manifest-path="$out_dir"/lib/Cargo.toml > /dev/null
rm -rf "$mkdocs_out_dir"/rustdoc
cp -r "$rustdoc_out_dir" "$mkdocs_out_dir"/rustdoc
33 changes: 33 additions & 0 deletions script/checkout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env bash

# Ensure the master branch is clean, perform a build, and copy the output to the
# gh-pages branch.

set -e

cd $(dirname "$BASH_SOURCE")
script_dir=`pwd`

repo_dir="$script_dir"/../..
out_dir="$repo_dir"/out

cd "$repo_dir"

which git > /dev/null

git checkout master

if [ -n "$(git status --porcelain)" ] ; then
git status
exit 1
fi
git fetch
if [ "$(git rev-parse @)" != "$(git rev-parse @{u})" ] ; then
git status
exit 1
fi

"$script_dir"/build.sh

git checkout gh-pages
cp -r "$out_dir"/doc/* "$repo_dir"/.
27 changes: 27 additions & 0 deletions script/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env bash

# Commit any changes to gh-pages and reset the initial commit. This flattens the
# history on the gh-pages branch.

set -e

cd $(dirname "$BASH_SOURCE")
script_dir=`pwd`

repo_dir="$script_dir"/../..
out_dir="$repo_dir"/out
src_hash=`cat "$out_dir"/hash`

cd "$repo_dir"

which git > /dev/null

git checkout gh-pages

if [ -z "$(git status --porcelain)" ] ; then
exit 1
fi

git add .
git commit -m "Build from $src_hash."
git reset $(git commit-tree HEAD^{tree} -m "Build from $src_hash.")
17 changes: 17 additions & 0 deletions script/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env bash

# Forces a push to the gh-pages branch on the origin remote. Checks out the
# master branch when done.

set -e

cd $(dirname "$BASH_SOURCE")
script_dir=`pwd`

repo_dir="$script_dir"/../..

cd "$repo_dir"

"$script_dir"/checkout.sh
"$script_dir"/commit.sh
"$script_dir"/push.sh
22 changes: 22 additions & 0 deletions script/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env bash

# Forces a push to the gh-pages branch on the origin remote. Checks out the
# master branch when done.

set -e

cd $(dirname "$BASH_SOURCE")
script_dir=`pwd`

repo_dir="$script_dir"/../..
out_dir="$repo_dir"/out
src_hash=`cat "$out_dir"/hash`

cd "$repo_dir"

which git > /dev/null

git checkout gh-pages

git push origin gh-pages --force
git checkout master

0 comments on commit d8cc3ae

Please sign in to comment.