Skip to content

Commit 9b12cb2

Browse files
authored
Merge pull request #13 from nipreps/codex/refactor-script-to-clone-repo-afresh
Clone nipreps.github.io in temp dir when updating plots
2 parents 669da9d + 7a6e972 commit 9b12cb2

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ The backup script will source this file if present.
6868
## Weekly plot update script
6969

7070
`scripts/update_plots.sh` generates plots with `src/run.py plot` and pushes them
71-
to a clone of the `nipreps.github.io` website. The path to that clone can be
72-
given as an argument and defaults to `$HOME/workspace/nipreps.github.io`.
73-
The script may be run from any directory and validates that the target is a Git
74-
repository.
71+
to the `nipreps.github.io` website. The script clones the repository to a
72+
temporary directory (by default using `[email protected]:nipreps/nipreps.github.io.git`),
73+
writes the plots there, commits and pushes the changes, and removes the
74+
temporary clone. You may pass an alternative repository URL as an argument.
75+
The script may be run from any directory.
7576

7677
Make the script executable:
7778

scripts/update_plots.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44

55
set -euo pipefail
66

7-
REPO_DIR="${1:-$HOME/workspace/nipreps.github.io}"
8-
ASSETS_DIR="$REPO_DIR/docs/assets"
7+
REPO_URL="${1:-git@github.com:nipreps/nipreps.github.io.git}"
8+
TMP_REPO="$(mktemp -d)"
99

10-
if [ ! -d "$REPO_DIR/.git" ]; then
11-
echo "Error: $REPO_DIR is not a git repository" >&2
12-
exit 1
13-
fi
10+
cleanup() {
11+
rm -rf "$TMP_REPO"
12+
}
13+
trap cleanup EXIT
14+
15+
git clone "$REPO_URL" "$TMP_REPO"
1416

17+
ASSETS_DIR="$TMP_REPO/docs/assets"
1518
mkdir -p "$ASSETS_DIR"
1619

1720
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1821
cd "$SCRIPT_DIR/.."
1922

2023
python src/run.py plot -o "$ASSETS_DIR"
2124

22-
cd "$REPO_DIR"
25+
cd "$TMP_REPO"
2326
git pull --ff-only
2427
git add docs/assets
2528
if ! git diff --cached --quiet; then

0 commit comments

Comments
 (0)