Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/bpan
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Project Commands:
bump Prepare next version
publish Publish the project to $APP index
register Register a new $APP package
hook Run a project hook

Information Commands:
help Get help for a '$app' command
Expand Down
66 changes: 66 additions & 0 deletions lib/hook.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
hook:options() (cat <<...
dryrun Don't run, just show what would run
keepgoing Ignore hook failures
...
)

hook:main() (
git:in-repo ||
error "Not in a git repo directory"

failed=0

for hook in "$@"; do
hook:run "$hook" $option_dryrun $option_keepgoing || {
failed=$((failed+1))

$option_keepgoing || exit 1
}
done

[[ $failed = 0 ]] || exit 1
)

hook:run() (
hook=$1
dryrun=$2
keepgoing=$3
failed=0

while read -r script; do
script=${script#*=}

if $dryrun; then
say -y "Running $hook hook: $script (not really, dryrun is enabled)"
else
say -y "Running $hook hook: $script"

[[ -x "$script" ]] || {
warn "Skipping non-executable $hook hook: $script"
continue
}

# TODO - sanitize $script?
"./$script" || {
code=$?
failed=$((failed+1))

msg="$hook hook $script failed ($code)"
if $keepgoing; then
warn "$msg"
else
error "$msg"
fi
}
fi

done < <(
script=".bpan/hooks/$hook"
[[ -x "$script" ]] && echo "$script"

ini:list --file=.bpan/config |
grep "^hook\.$hook"
)

return $failed
)
3 changes: 3 additions & 0 deletions lib/publish.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ publish:main() (

$option_check && return

source-once hook
hook:run pre-publish
publish:trigger-publish
hook:run post-publish
)

publish:get-env() {
Expand Down