Skip to content

Commit 0de0957

Browse files
committed
newer build process
1 parent e3354b1 commit 0de0957

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

.githook.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
set -e
1111
# constants
1212

13-
GITHOOK_VERSION="0.1.9"
13+
GITHOOK_VERSION="0.1.12"
1414
GITHOOK_API_URL="https://githook.sh"
1515
GITHOOK_DIR=".githook"
1616
GITHOOK_INTERNAL_DIR=".githook/_"
@@ -127,6 +127,7 @@ githook_cmd_install() {
127127
# create shared hook runner
128128
cat > "$_git_root/$GITHOOK_INTERNAL_DIR/h" << 'HOOK'
129129
#!/bin/sh
130+
[ -f "$HOME/.config/githook/init.sh" ] && . "$HOME/.config/githook/init.sh"
130131
[ "$GITHOOK" = "2" ] && set -x
131132
[ "$GITHOOK" = "0" ] && exit 0
132133
n=$(basename "$0")
@@ -135,7 +136,7 @@ h=$(dirname "$(dirname "$0")")/$n
135136
sh -e "$h" "$@"
136137
c=$?
137138
[ $c != 0 ] && echo "githook - $n failed (code $c)"
138-
[ $c = 127 ] && echo "githook - command not found in PATH=$PATH"
139+
[ $c = 127 ] && echo "githook - command not found"
139140
exit $c
140141
HOOK
141142

@@ -176,10 +177,17 @@ githook_cmd_update() {
176177
_git_root="$(githook_check_git_repository)"
177178
_path="$_git_root/.githook.sh"
178179
[ ! -f "$_path" ] && githook_error ".githook.sh not found in repo root"
179-
githook_info "updating .githook.sh..."
180-
githook_download_file "$GITHOOK_API_URL" "$_path" || githook_error "failed to download update"
180+
githook_info "checking for updates..."
181+
_remote="$(githook_download_file "$GITHOOK_API_URL" - 2>/dev/null)" || githook_error "failed to fetch latest version"
182+
_latest="$(echo "$_remote" | grep '^GITHOOK_VERSION=' | cut -d'"' -f2)"
183+
case "$_latest" in [0-9]*.[0-9]*.[0-9]*) ;; *) githook_error "invalid remote version: $_latest" ;; esac
184+
githook_version_compare "$GITHOOK_VERSION" "$_latest"
185+
case $? in 0|1) githook_info "already up to date ($GITHOOK_VERSION)"; return ;; esac
186+
githook_info "updating $GITHOOK_VERSION -> $_latest..."
187+
echo "$_remote" > "$_path"
181188
chmod +x "$_path"
182-
githook_info "updated successfully"
189+
githook_info "updated to $_latest"
190+
githook_info "run ./.githook.sh install to update hooks"
183191
}
184192

185193
githook_cmd_version() {

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN make build
1313
FROM caddy:2-alpine
1414

1515
COPY site/ /srv/site/
16-
COPY --from=builder /build/githook.sh /srv/site/githook.sh
16+
COPY --from=builder /build/.githook.sh /srv/site/githook.sh
1717
COPY Caddyfile /etc/caddy/Caddyfile
1818

1919
EXPOSE 80

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SRC := src/header.sh \
77
src/main.sh \
88
src/footer.sh
99

10-
OUT := githook.sh
10+
OUT ?= .githook.sh
1111

1212
build: $(OUT)
1313

githook.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
set -e
1111
# constants
1212

13-
GITHOOK_VERSION="0.1.11"
13+
GITHOOK_VERSION="0.1.12"
1414
GITHOOK_API_URL="https://githook.sh"
1515
GITHOOK_DIR=".githook"
1616
GITHOOK_INTERNAL_DIR=".githook/_"
@@ -177,10 +177,17 @@ githook_cmd_update() {
177177
_git_root="$(githook_check_git_repository)"
178178
_path="$_git_root/.githook.sh"
179179
[ ! -f "$_path" ] && githook_error ".githook.sh not found in repo root"
180-
githook_info "updating .githook.sh..."
181-
githook_download_file "$GITHOOK_API_URL" "$_path" || githook_error "failed to download update"
180+
githook_info "checking for updates..."
181+
_remote="$(githook_download_file "$GITHOOK_API_URL" - 2>/dev/null)" || githook_error "failed to fetch latest version"
182+
_latest="$(echo "$_remote" | grep '^GITHOOK_VERSION=' | cut -d'"' -f2)"
183+
case "$_latest" in [0-9]*.[0-9]*.[0-9]*) ;; *) githook_error "invalid remote version: $_latest" ;; esac
184+
githook_version_compare "$GITHOOK_VERSION" "$_latest"
185+
case $? in 0|1) githook_info "already up to date ($GITHOOK_VERSION)"; return ;; esac
186+
githook_info "updating $GITHOOK_VERSION -> $_latest..."
187+
echo "$_remote" > "$_path"
182188
chmod +x "$_path"
183-
githook_info "updated successfully"
189+
githook_info "updated to $_latest"
190+
githook_info "run ./.githook.sh install to update hooks"
184191
}
185192

186193
githook_cmd_version() {

src/commands.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,17 @@ githook_cmd_update() {
108108
_git_root="$(githook_check_git_repository)"
109109
_path="$_git_root/.githook.sh"
110110
[ ! -f "$_path" ] && githook_error ".githook.sh not found in repo root"
111-
githook_info "updating .githook.sh..."
112-
githook_download_file "$GITHOOK_API_URL" "$_path" || githook_error "failed to download update"
111+
githook_info "checking for updates..."
112+
_remote="$(githook_download_file "$GITHOOK_API_URL" - 2>/dev/null)" || githook_error "failed to fetch latest version"
113+
_latest="$(echo "$_remote" | grep '^GITHOOK_VERSION=' | cut -d'"' -f2)"
114+
case "$_latest" in [0-9]*.[0-9]*.[0-9]*) ;; *) githook_error "invalid remote version: $_latest" ;; esac
115+
githook_version_compare "$GITHOOK_VERSION" "$_latest"
116+
case $? in 0|1) githook_info "already up to date ($GITHOOK_VERSION)"; return ;; esac
117+
githook_info "updating $GITHOOK_VERSION -> $_latest..."
118+
echo "$_remote" > "$_path"
113119
chmod +x "$_path"
114-
githook_info "updated successfully"
120+
githook_info "updated to $_latest"
121+
githook_info "run ./.githook.sh install to update hooks"
115122
}
116123

117124
githook_cmd_version() {

test/hooks/functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setup() {
2525
}
2626

2727
install() {
28-
cp "$PROJECT_DIR/githook.sh" .githook.sh
28+
cp "$PROJECT_DIR/.githook.sh" .githook.sh
2929
chmod +x .githook.sh
3030
./.githook.sh install
3131
}

0 commit comments

Comments
 (0)