Skip to content

Commit a1c2c2a

Browse files
committed
refactor(): commit+push in generate script
1 parent 546b8ff commit a1c2c2a

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

bpkg.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"commands": {
88
"server": "command serve . -p ${PORT:-3000} || command budo . -p ${PORT:-3000}",
99
"generate": "./scripts/generate.sh $@",
10+
"lint": "command shellcheck scripts/*.sh",
1011

1112
"list-bpkg-tags": "curl -Lnso- https://api.github.com/repos/bpkg/bpkg/tags?nonce=$(date +%s)'&'page=$1 | bpkg json -b | grep name | awk '{ print $2 }' | tr -d '\"'",
1213
"echo-url": "echo https://api.github.com/repos/bpkg/bpkg/tags?nonce=$(date +%s)'&'page=$2"

scripts/generate.sh

+29-9
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@ if ! test -d "$BPKG_PACKAGE_ROOT"; then
1414
exit 1
1515
fi
1616

17-
declare should_force_generate=0
17+
declare should_force=0
18+
declare no_commit=0
19+
declare no_push=0
20+
1821
declare template="$BPKG_PACKAGE_ROOT/_template"
1922
declare latest=""
2023

2124
for opt in "$@"; do
2225
case "$opt" in
2326
-f|--force)
24-
should_force_generate=1
27+
should_force=1
2528
;;
2629

27-
-h|--help)
28-
echo "usage: generate.sh [-f|--force]"
29-
echo " or: bpkg run generate [-f|--force]"
30-
exit 0
30+
--no-commit)
31+
no_commit=1
3132
;;
33+
34+
-h|--help) {
35+
cli_args="[-f|--force] [--no-commit] [--no-push]"
36+
echo "usage: generate.sh $cli_args"
37+
echo " or: bpkg run generate $cli_args"
38+
exit 0
39+
} ;;
3240
esac
3341
done
3442

@@ -78,7 +86,7 @@ for tag in "${tags[@]}"; do
7886
declare dirname="$BPKG_PACKAGE_ROOT/$tag"
7987
declare output="$dirname/index.html"
8088

81-
if ! test -f "$output" || (( should_force_generate == 1 )); then
89+
if ! test -f "$output" || (( should_force == 1 )); then
8290
mkdir -p "$dirname"
8391

8492
if test -f "$output"; then
@@ -107,7 +115,7 @@ if [ -n "$latest" ]; then
107115
declare dirname="$BPKG_PACKAGE_ROOT"
108116
declare output="$dirname/index.html"
109117

110-
if ! test -f "$output" || (( should_force_generate == 1 )); then
118+
if ! test -f "$output" || (( should_force == 1 )); then
111119
if test -f "$output"; then
112120
## clean up existing
113121
bpkg_warn "Purging '$output'"
@@ -126,7 +134,7 @@ if [ -n "$latest" ]; then
126134
bpkg_info "Generated '$tag'"
127135
fi
128136

129-
if ! test -f "$BPKG_PACKAGE_ROOT/latest" || (( should_force_generate == 1 )); then
137+
if ! test -f "$BPKG_PACKAGE_ROOT/latest" || (( should_force == 1 )); then
130138
declare dirname="$BPKG_PACKAGE_ROOT/latest"
131139
declare output="$dirname/index.html"
132140

@@ -147,3 +155,15 @@ if [ -n "$latest" ]; then
147155
bpkg_info "Generated 'latest'"
148156
fi
149157
fi
158+
159+
if (( no_commit == 0 )); then
160+
git add .
161+
git commit -am"chore(): generate $latest"
162+
if (( no_push == 0 )); then
163+
if (( should_force == 1 )); then
164+
git push origin master -f
165+
else
166+
git push origin master
167+
fi
168+
fi
169+
fi

0 commit comments

Comments
 (0)