Repository navigation
Expand file tree
/
Copy pathstamp.sh
More file actions
executable file
·44 lines (40 loc) · 1.69 KB
/
Copy pathstamp.sh
File metadata and controls
executable file
·44 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/usr/bin/env bash
{
if [[ "$1" == "-h" || "$1" == "--help" ]] ; then
cat <<-'EOF'
stamp.sh -- beman exemplar template library creation tool
This script is intended to be run on a fork of exemplar.
It sets up cookiecutter, runs it on the cookiecutter template, replaces the
repository's current contents with the result, runs pre-commit,
switches to a new branch 'stamp', and creates a git commit.
All parameters are passed through to the cookiecutter invocation.
EOF
fi
set -eu
if ! type -P python3 >/dev/null ; then
echo "Couldn't find python3 in PATH" >&2
exit 1
fi
declare repo_dir=$(realpath $(dirname "$BASH_SOURCE"))
cd "$repo_dir"
declare cookiecutter_venv_path
cookiecutter_venv_path=$(mktemp --directory --dry-run)
python3 -m venv "$cookiecutter_venv_path"
source "$cookiecutter_venv_path/bin/activate"
python3 -m pip install cookiecutter pre-commit >& /dev/null
declare cookiecutter_out_path
cookiecutter_out_path=$(mktemp --directory)
python3 -m cookiecutter "$repo_dir/cookiecutter" -o "$cookiecutter_out_path" "$@"
git rm -rf . &>/dev/null
cp -r "$cookiecutter_out_path"/*/. .
git add . &>/dev/null
pre-commit run --all-files &>/dev/null || true
git add . &>/dev/null
git checkout -b stamp
git commit -q -m "Stamp out exemplar template"
echo "Successfully stamped out exemplar template to the new branch 'stamp'."
echo "Try 'git push origin stamp' to push the branch upstream,"
echo "then create a pull request."
rm -r "$cookiecutter_venv_path" "$cookiecutter_out_path"
}; exit