Skip to content

Commit

Permalink
feat: Adjust run wrapper (#156)
Browse files Browse the repository at this point in the history
- Adjust run wrapper to look for `githooks-runner` first.
- Name all executables with `githooks-` prefix.
- Fix Coverage generation.
- Remove old binaries during install if still there.
  • Loading branch information
gabyx committed Apr 21, 2024
1 parent 9002369 commit ee2ec60
Show file tree
Hide file tree
Showing 192 changed files with 849 additions and 767 deletions.
4 changes: 3 additions & 1 deletion .githooks/pre-commit/update-templates
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ hook_names=$($SED -E '1,/ManagedHookNames.*\{/d;/\}/,$d ; s/\s+"(.*)",/\1/' gith

for hook_name in $hook_names; do
# shellcheck disable=SC2015
$SED -e "s|GITHOOKS_RUNNER=.*|GITHOOKS_RUNNER=\"\$(cd \"\$(dirname \"\$0\")/../\" \&\& pwd)/githooks/bin/runner\"|" \
$SED -e "s|GITHOOKS_RUNNER=.*|GITHOOKS_RUNNER=\"\$(cd \"\$(dirname \"\$0\")/../\" \&\& pwd)/githooks/bin/githooks-runner\"|" \
-e "/echo \" .*/d" \
-e "s|echo \"! .*|echo \"! The runner '\$GITHOOKS_RUNNER' is not existing\" \>\&2\n|g" \
-e "s|\(various Git triggers.*\)|\1\n#\n# This file is auto-generated, do not edit!|" \
<githooks/build/embedded/run-wrapper.sh >"hooks/$hook_name" &&
chmod u+x "hooks/$hook_name" &&
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"--listen=127.0.0.1:2345",
"--log",
"--api-version=2",
"./apps/cli",
"./apps/githooks-cli",
"--",
"installer",
"--config",
Expand Down Expand Up @@ -98,7 +98,7 @@
"--listen=127.0.0.1:2345",
"--log",
"--api-version=2",
"./apps/cli",
"./apps/githooks-cli",
"--",
"uninstaller"
],
Expand Down Expand Up @@ -133,7 +133,7 @@
"--listen=127.0.0.1:2345",
"--log",
"--api-version=2",
"./apps/cli",
"./apps/githooks-cli",
"--",
"install",
"--non-interactive"
Expand Down
33 changes: 0 additions & 33 deletions docs/dialog/dialog.md

This file was deleted.

36 changes: 36 additions & 0 deletions docs/dialog/githooks-dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## githooks-dialog

Githooks dialog application similar to `zenity`.

### Synopsis

See further information at https://github.com/gabyx/githooks/blob/main/README.md

```
githooks-dialog
```

### Options

```
--json Report the result as a JSON object on stdout.
Exit code:
- `0` for success, and
- '> 0' if creating the dialog failed.
-h, --help help for githooks-dialog
```

### SEE ALSO

- [githooks-dialog entry](githooks-dialog_entry.md) - Shows a entry dialog.
- [githooks-dialog file-save](githooks-dialog_file-save.md) - Shows a file save
dialog.
- [githooks-dialog file-selection](githooks-dialog_file-selection.md) - Shows a
file selection dialog.
- [githooks-dialog message](githooks-dialog_message.md) - Shows a message
dialog.
- [githooks-dialog notify](githooks-dialog_notify.md) - Shows a notification.
- [githooks-dialog options](githooks-dialog_options.md) - Shows a options
selection dialog.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog entry
## githooks-dialog entry

Shows a entry dialog.

Expand All @@ -16,7 +16,7 @@ does not.
button.

```
dialog entry
githooks-dialog entry
```

### Options
Expand Down Expand Up @@ -54,6 +54,7 @@ dialog entry

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog file-save
## githooks-dialog file-save

Shows a file save dialog.

Expand All @@ -14,7 +14,7 @@ Shows a file save dialog similar to `zenity`.
- `5` : The dialog was closed due to timeout.

```
dialog file-save
githooks-dialog file-save
```

### Options
Expand Down Expand Up @@ -48,6 +48,7 @@ dialog file-save

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog file-selection
## githooks-dialog file-selection

Shows a file selection dialog.

Expand All @@ -14,7 +14,7 @@ Shows a file selection dialog similar to `zenity`.
- `5` : The dialog was closed due to timeout.

```
dialog file-selection
githooks-dialog file-selection
```

### Options
Expand Down Expand Up @@ -47,6 +47,7 @@ dialog file-selection

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog message
## githooks-dialog message

Shows a message dialog.

Expand All @@ -17,7 +17,7 @@ supports multiple extra buttons. Use `options` to have more choices.
button.

```
dialog message
githooks-dialog message
```

### Options
Expand Down Expand Up @@ -54,6 +54,7 @@ dialog message

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog notify
## githooks-dialog notify

Shows a notification.

Expand All @@ -12,7 +12,7 @@ Shows a notification similar to `zenity`.
- > `0` : An error occurred.
```
dialog notify
githooks-dialog notify
```

### Options
Expand All @@ -38,6 +38,7 @@ dialog notify

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## dialog options
## githooks-dialog options

Shows a options selection dialog.

Expand All @@ -20,7 +20,7 @@ instead of a listbox.
- `5` : The dialog was closed due to timeout.

```
dialog options
githooks-dialog options
```

### Options
Expand Down Expand Up @@ -61,6 +61,7 @@ dialog options

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
- [githooks-dialog](githooks-dialog.md) - Githooks dialog application similar to
`zenity`.

###### Auto generated by spf13/cobra
2 changes: 1 addition & 1 deletion githooks/apps/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestCoverage(t *testing.T) {
if coverage.Setup("cli") {
if coverage.Setup("githooks-cli") {
// Careful if you print to much stuff, certain tests might fail
// fmt.Printf("Forward args: %q\n", os.Args)

Expand Down
2 changes: 1 addition & 1 deletion githooks/apps/dialog/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func MakeDialogCtl(ctx *dcm.CmdContext) (rootCmd *cobra.Command) {
ccm.InitTemplates(title, firstPrefix, ctx.Log.GetIndent())

rootCmd = &cobra.Command{
Use: "dialog",
Use: "githooks-dialog",
Short: "Githooks dialog application similar to 'zenity'.",
Long: "See further information at https://github.com/gabyx/githooks/blob/main/README.md"}

Expand Down
2 changes: 1 addition & 1 deletion githooks/apps/dialog/dialog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestCoverage(t *testing.T) {
if coverage.Setup("dialog") {
if coverage.Setup("githooks-dialog") {
// Careful if you print to much stuff, certain tests might fail
// fmt.Printf("Forward args: %q\n", os.Args)

Expand Down
2 changes: 1 addition & 1 deletion githooks/apps/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestCoverage(t *testing.T) {
if coverage.Setup("runner") {
if coverage.Setup("githooks-runner") {
// Careful if you print to much stuff, certain tests might fail
// fmt.Printf("Forward args: %q\n", os.Args)

Expand Down
17 changes: 10 additions & 7 deletions githooks/build/embedded/run-wrapper-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# its hooks to execute on various Git triggers.

# Read the runner script from the local/global or system config
GITHOOKS_RUNNER=$(git config githooks.runner)
GITHOOKS_RUNNER=$(command -v "githooks-runner" 2>/dev/null || git config githooks.runner)

# shellcheck disable=SC2181
if [ ! -x "$GITHOOKS_RUNNER" ]; then
echo "! Githooks runner points to a non existing location" >&2
echo " \`$GITHOOKS_RUNNER\`" >&2
echo " or it is not executable!" >&2
echo " Please run the Githooks install script again to fix it." >&2
echo "! Either 'githooks-runner' must be in your path or" >&2
echo " Git config value in 'githooks.runner' must point to an " >&2
echo " executable. The value:" >&2
echo " '$GITHOOKS_RUNNER" >&2
echo " is not existing or is not executable!" >&2
echo " Please run the Githooks install script again to fix it." >&2
exit 1
fi

Expand All @@ -20,8 +23,8 @@ fi
exit 1
}

COV_DATA="$GH_COVERAGE_DIR/runner.yaml"
COUNTER=$(head -1 "$COV_DATA" | sed -E 's@counter: ([0-9]+)@\1@')
COV_DATA="$GH_COVERAGE_DIR/githooks-runner.yaml"
COUNTER=$(head -1 "$COV_DATA" 2>&1 | sed -E 's@counter: ([0-9]+)@\1@')
[ -z "$COUNTER" ] && COUNTER="0"
COV_FILE="$GH_COVERAGE_DIR/runner-$COUNTER.cov"
[ -f "$COV_FILE" ] && {
Expand Down
14 changes: 8 additions & 6 deletions githooks/build/embedded/run-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
# It allows you to have a .githooks folder per-project that contains
# its hooks to execute on various Git triggers.

# Read the runner script from the local/global or system config
GITHOOKS_RUNNER=$(git config githooks.runner)
GITHOOKS_RUNNER=$(command -v "githooks-runner" 2>/dev/null || git config githooks.runner)

# shellcheck disable=SC2181
if [ ! -x "$GITHOOKS_RUNNER" ]; then
echo "! Githooks runner points to a non existing location" >&2
echo " \`$GITHOOKS_RUNNER\`" >&2
echo " or it is not executable!" >&2
echo " Please run the Githooks install script again to fix it." >&2
echo "! Either 'githooks-runner' must be in your path or" >&2
echo " Git config value in 'githooks.runner' must point to an " >&2
echo " executable. The value:" >&2
echo " '$GITHOOKS_RUNNER" >&2
echo " is not existing or is not executable!" >&2
echo " Please run the Githooks install script again to fix it." >&2
exit 1
fi

Expand Down
12 changes: 12 additions & 0 deletions githooks/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ func Build(gitx *git.Context, buildTags []string, cleanUpX *cm.InterruptContext)
// Compile everything.
cmd := []string{"install", "-mod=vendor"}

ext := ""
if runtime.GOOS == cm.WindowsOsName {
buildTags = append(buildTags, cm.WindowsOsName)
ext = ".exe"
}

if len(buildTags) != 0 {
Expand All @@ -158,6 +160,16 @@ func Build(gitx *git.Context, buildTags []string, cleanUpX *cm.InterruptContext)
cmd = append(cmd, "./...")
out, err = gox.GetCombined(cmd...)

for _, name := range []string{"cli", "runner", "dialog"} {
src := path.Join(goBinPath, name+ext)
dest := path.Join(goBinPath, "githooks-"+name+ext)

err = os.Rename(src, dest)
if err != nil {
return "", cm.ErrorF("Could not rename executable '%s'.", name)
}
}

if err != nil {
return goBinPath,
cm.ErrorF("Compile command failed:\n'%s %q'\nOutput:\n%s",
Expand Down
6 changes: 3 additions & 3 deletions githooks/cmd/installer/download-binaries-mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func downloadBinaries(
}

all := []string{
path.Join(tempDir, "cli"+ext),
path.Join(tempDir, "runner"+ext),
path.Join(tempDir, "dialog"+ext)}
path.Join(tempDir, "githooks-cli"+ext),
path.Join(tempDir, "githooks-runner"+ext),
path.Join(tempDir, "githooks-dialog"+ext)}

for _, exe := range all {
src := path.Join(bin, path.Base(exe))
Expand Down
Loading

0 comments on commit ee2ec60

Please sign in to comment.