diff --git a/README.md b/README.md index 9d8626b..a5bb5ed 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,11 @@ The backup script will source this file if present. ## Weekly plot update script `scripts/update_plots.sh` generates plots with `src/run.py plot` and pushes them -to a clone of the `nipreps.github.io` website. The path to that clone can be -given as an argument and defaults to `$HOME/workspace/nipreps.github.io`. -The script may be run from any directory and validates that the target is a Git -repository. +to the `nipreps.github.io` website. The script clones the repository to a +temporary directory (by default using `git@github.com:nipreps/nipreps.github.io.git`), +writes the plots there, commits and pushes the changes, and removes the +temporary clone. You may pass an alternative repository URL as an argument. +The script may be run from any directory. Make the script executable: diff --git a/scripts/update_plots.sh b/scripts/update_plots.sh index 78b3254..c8c83fe 100755 --- a/scripts/update_plots.sh +++ b/scripts/update_plots.sh @@ -4,14 +4,17 @@ set -euo pipefail -REPO_DIR="${1:-$HOME/workspace/nipreps.github.io}" -ASSETS_DIR="$REPO_DIR/docs/assets" +REPO_URL="${1:-git@github.com:nipreps/nipreps.github.io.git}" +TMP_REPO="$(mktemp -d)" -if [ ! -d "$REPO_DIR/.git" ]; then - echo "Error: $REPO_DIR is not a git repository" >&2 - exit 1 -fi +cleanup() { + rm -rf "$TMP_REPO" +} +trap cleanup EXIT + +git clone "$REPO_URL" "$TMP_REPO" +ASSETS_DIR="$TMP_REPO/docs/assets" mkdir -p "$ASSETS_DIR" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -19,7 +22,7 @@ cd "$SCRIPT_DIR/.." python src/run.py plot -o "$ASSETS_DIR" -cd "$REPO_DIR" +cd "$TMP_REPO" git pull --ff-only git add docs/assets if ! git diff --cached --quiet; then