Skip to content

Commit d41c37e

Browse files
committed
update template
1 parent 50d495c commit d41c37e

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the things that don't have output files or run every time
22
.PHONY: help all install test dev coverage clean \
3-
pre-commit update-pre-commit docs dist
3+
pre-commit update-pre-commit docs dist update-template
44

55

66
PROJECT_NAME := example_package
@@ -29,6 +29,9 @@ pre-commit: .git/hooks/pre-commit ## install pre-commit into the git repo
2929
update-pre-commit: scripts/update-pre-commit.sh ## autoupdate pre-commit
3030
scripts/update-pre-commit.sh
3131

32+
update-template: scripts/update-template.sh ## pull Makefile, scripts and workflows from the template repo
33+
scripts/update-template.sh
34+
3235
dist: scripts/dist.sh ## build the distributable files
3336
scripts/dist.sh $(PROJECT_NAME)
3437

‎scripts/update-template.sh‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
# Pull Makefile, scripts/ and .github/ from the template repo into the
4+
# current repo, so it can be reviewed with `git diff` and committed by hand.
5+
#
6+
# The repo's PROJECT_NAME line in the Makefile is preserved. Files that only
7+
# exist in this repo (extra scripts, extra workflows) are left alone.
8+
#
9+
# Override the source with TEMPLATE_REPO=<url-or-path> (default: github master).
10+
11+
set -e
12+
13+
TEMPLATE_REPO="${TEMPLATE_REPO:-https://github.com/bitplane/example-python-project.git}"
14+
15+
if [ ! -f Makefile ] || [ ! -d .git ]; then
16+
echo "Run this from the root of a git repo with a Makefile" >&2
17+
exit 1
18+
fi
19+
20+
if ! git diff --quiet Makefile scripts .github 2>/dev/null; then
21+
echo "warning: Makefile/scripts/.github have uncommitted changes; the diff will mix them" >&2
22+
fi
23+
24+
# Remember this repo's identity
25+
project_name=$(sed -n 's/^PROJECT_NAME := //p' Makefile)
26+
27+
# Fetch the template
28+
TMP_DIR=$(mktemp -d)
29+
cleanup() {
30+
rm -rf "$TMP_DIR"
31+
}
32+
trap cleanup EXIT
33+
34+
echo "Fetching template from $TEMPLATE_REPO..."
35+
git clone --quiet --depth=1 "$TEMPLATE_REPO" "$TMP_DIR"
36+
37+
# Copy template-owned files over ours, leaving repo-specific extras in place
38+
cp "$TMP_DIR/Makefile" Makefile
39+
mkdir -p scripts .github
40+
cp -r "$TMP_DIR/scripts/." scripts/
41+
cp -r "$TMP_DIR/.github/." .github/
42+
43+
# Restore this repo's identity
44+
if [ -n "$project_name" ]; then
45+
sed -i "s/^PROJECT_NAME := .*/PROJECT_NAME := $project_name/" Makefile
46+
fi
47+
48+
echo "Template applied. Review with: git diff Makefile scripts .github"

0 commit comments

Comments
 (0)