-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden shell scripts with improved robustness & verbosity (#233)
Merges manubot/rootstock#233 Hat tip to Michael Hoffman (https://hoffmanlab.org/) for feedback. * Apply shell best practices References: https://kvz.io/blog/2013/11/21/bash-best-practices/ https://www.davidpashley.com/articles/writing-robust-shell-scripts/ manubot/rootstock#233 (comment) * Specify bash (not just sh). Other shellcheck suggestions Properly use command substitution and parameter expansion in the appropriate places. * echo diagnostic messages to stderr Previously echo defaulted to stdout https://stackoverflow.com/a/41766832/4651668 Placement of stderr redirect to: "echo >&2" * Update bash options: xtrace specified by calling command * Quote variable names * deploy.sh: use Travis env vars for CI build URLs These environment variables were added to Travis in late 2018 travis-ci/travis-ci#8935 (comment)
- Loading branch information
Showing
6 changed files
with
61 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Automatically rebuild mansucript outputs and the webpage when content changes | ||
# Depends on watchdog https://github.com/gorakhargosh/watchdog | ||
#!/usr/bin/env bash | ||
|
||
## autobuild.sh: automatically rebuild mansucript outputs and the webpage when content changes | ||
## Depends on watchdog https://github.com/gorakhargosh/watchdog | ||
|
||
watchmedo shell-command \ | ||
--wait \ | ||
--command='sh build/build.sh && python build/webpage.py' \ | ||
--command='bash build/build.sh && python build/webpage.py' \ | ||
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
# Exit on errors | ||
set -o errexit | ||
#!/usr/bin/env bash | ||
|
||
## deploy.sh: run during a Travis CI build to deploy manuscript outputs to the output and gh-pages branches on GitHub. | ||
|
||
# Set options for extra caution & debugging | ||
set -o errexit \ | ||
-o nounset \ | ||
-o pipefail | ||
|
||
# Add commit hash to the README | ||
export OWNER_NAME=`dirname $TRAVIS_REPO_SLUG` | ||
export REPO_NAME=`basename $TRAVIS_REPO_SLUG` | ||
OWNER_NAME="$(dirname "$TRAVIS_REPO_SLUG")" | ||
REPO_NAME="$(basename "$TRAVIS_REPO_SLUG")" | ||
export OWNER_NAME REPO_NAME | ||
envsubst < webpage/README.md > webpage/README-complete.md | ||
mv webpage/README-complete.md webpage/README.md | ||
|
||
# Configure git | ||
git config --global push.default simple | ||
git config --global user.email `git log --max-count=1 --format='%ae'` | ||
git config --global user.name "`git log --max-count=1 --format='%an'`" | ||
git checkout $TRAVIS_BRANCH | ||
git remote set-url origin [email protected]:$TRAVIS_REPO_SLUG.git | ||
git config --global user.email "$(git log --max-count=1 --format='%ae')" | ||
git config --global user.name "$(git log --max-count=1 --format='%an')" | ||
git checkout "$TRAVIS_BRANCH" | ||
git remote set-url origin "[email protected]:$TRAVIS_REPO_SLUG.git" | ||
|
||
# Decrypt and add SSH key | ||
openssl aes-256-cbc \ | ||
-K $encrypted_9befd6eddffe_key \ | ||
-iv $encrypted_9befd6eddffe_iv \ | ||
-in ci/deploy.key.enc \ | ||
-out ci/deploy.key -d | ||
eval `ssh-agent -s` | ||
eval "$(ssh-agent -s)" | ||
chmod 600 ci/deploy.key | ||
ssh-add ci/deploy.key | ||
|
||
|
@@ -33,24 +40,24 @@ git fetch origin gh-pages:gh-pages output:output | |
python build/webpage.py \ | ||
--no-ots-cache \ | ||
--checkout=gh-pages \ | ||
--version=$TRAVIS_COMMIT | ||
--version="$TRAVIS_COMMIT" | ||
|
||
# Generate OpenTimestamps | ||
ots stamp webpage/v/$TRAVIS_COMMIT/index.html | ||
if [ "$BUILD_PDF" != "false" ]; then | ||
ots stamp webpage/v/$TRAVIS_COMMIT/manuscript.pdf | ||
ots stamp "webpage/v/$TRAVIS_COMMIT/index.html" | ||
if [ "${BUILD_PDF:-}" != "false" ]; then | ||
ots stamp "webpage/v/$TRAVIS_COMMIT/manuscript.pdf" | ||
fi | ||
|
||
# Commit message | ||
MESSAGE="\ | ||
`git log --max-count=1 --format='%s'` | ||
$(git log --max-count=1 --format='%s') | ||
This build is based on | ||
https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT. | ||
This commit was created by the following Travis CI build and job: | ||
https://travis-ci.com/$TRAVIS_REPO_SLUG/builds/$TRAVIS_BUILD_ID | ||
https://travis-ci.com/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID | ||
$TRAVIS_BUILD_WEB_URL | ||
$TRAVIS_JOB_WEB_URL | ||
[ci skip] | ||
|