Skip to content

Commit

Permalink
feat: Export staged files as file ⚓ (#150)
Browse files Browse the repository at this point in the history
- feat: Export staged files as file with path in env. variable `STAGED_FILES_FILE`.
- feat: Include documentation. Also for `.envs.yaml` in `yaml-specs.md`.

- np: Refactor constructing container manager.
  No more copy to volume for the workspace.
- np: Cleanup containerized tests.

- ci: Mount container manager volume to `/tmp` to use as replacement for `/mnt/workspace`.
- ci: Test also `.envs.yaml` for hooks in containers.
  • Loading branch information
gabyx authored Mar 30, 2024
1 parent 688ac3c commit e65758f
Show file tree
Hide file tree
Showing 222 changed files with 1,731 additions and 1,168 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ workflows:
"test-alpine-user",
"test-corehookspath",
"test-whitespace",
"test-testsuite",
"test-testsuite-podman",
"test-rules",
"test-unittests",
"test-unittests-podman",
"test-lint",
]
filters: &filters
branches:
Expand Down
2 changes: 1 addition & 1 deletion .githooks/.ignore.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
patterns:
- "**/*.md"
- "**/*export-staged"
- "**/*export-staged"
55 changes: 47 additions & 8 deletions .githooks/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
# Githooks

This project uses [Githooks](https://github.com/gabyx/githooks), that allows running [Git hooks](https://git-scm.com/docs/cli/githooks) checked into this repository. This folder contains hooks that should be executed by everyone who interacts with this source repository. For a documentation on how this works and how to get it [installed](https://github.com/gabyx/githooks#installation), check the project [README](https://github.com/gabyx/githooks/blob/main/README.md) in the [gabyx/githooks](https://github.com/gabyx/githooks) GitHub repository.
This project uses [Githooks](https://github.com/gabyx/githooks), that allows
running [Git hooks](https://git-scm.com/docs/cli/githooks) checked into this
repository. This folder contains hooks that should be executed by everyone who
interacts with this source repository. For a documentation on how this works and
how to get it [installed](https://github.com/gabyx/githooks#installation), check
the project [README](https://github.com/gabyx/githooks/blob/main/README.md) in
the [gabyx/githooks](https://github.com/gabyx/githooks) GitHub repository.

## Brief summary

The [directories or files](https://github.com/gabyx/githooks#layout-and-options) in this folder tell Git to execute certain scripts on various [trigger events](https://github.com/gabyx/githooks#supported-hooks), before or after a commit, on every checkout, before a push for example - assuming [Githooks](https://github.com/gabyx/githooks) is already [installed](https://github.com/gabyx/githooks#installation) and [run-wrappers are installed](https://github.com/gabyx/githooks#installing-or-removing-run-wrappers) for the repository. The directory or file names refer to these events, like `pre-commit`, `post-commit`, `post-checkout`, `pre-push`, etc. If they are folders, each file inside them is treated as a hook script and will be executed when Git runs the hooks as part of the command issued by the user. [Githooks](https://github.com/gabyx/githooks) comes with a [command line tool](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md) tool, that allows you to manage its configuration and state with a `git hooks <cmd>` command. See the [documentation](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md) or run `git hooks --help` for more information and available options.
The [directories or files](https://github.com/gabyx/githooks#layout-and-options)
in this folder tell Git to execute certain scripts on various
[trigger events](https://github.com/gabyx/githooks#supported-hooks), before or
after a commit, on every checkout, before a push for example - assuming
[Githooks](https://github.com/gabyx/githooks) is already
[installed](https://github.com/gabyx/githooks#installation) and
[run-wrappers are installed](https://github.com/gabyx/githooks#installing-or-removing-run-wrappers)
for the repository. The directory or file names refer to these events, like
`pre-commit`, `post-commit`, `post-checkout`, `pre-push`, etc. If they are
folders, each file inside them is treated as a hook script and will be executed
when Git runs the hooks as part of the command issued by the user.
[Githooks](https://github.com/gabyx/githooks) comes with a
[command line tool](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md)
tool, that allows you to manage its configuration and state with a
`git hooks <cmd>` command. See the
[documentation](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md)
or run `git hooks --help` for more information and available options.

### Is this safe?

[Githooks](https://github.com/gabyx/githooks) uses an [opt-in model](https://github.com/gabyx/githooks#trusting-hooks), where it will ask for confirmation whether new or changed hooks should be run or not (or disabled).
[Githooks](https://github.com/gabyx/githooks) uses an
[opt-in model](https://github.com/gabyx/githooks#trusting-hooks), where it will
ask for confirmation whether new or changed hooks should be run or not (or
disabled).

### How do I add a new hook script?

Either create a file with the [Git hook](https://github.com/gabyx/githooks#supported-hooks) name, or a directory (recommended) inside the `.githooks` folder, and place files with the individual steps that should be executed for that event inside. If the file is executable, it will be invoked directly, otherwise it is assumed to be a Shell script - unless this file matches one of the [ignore patterns](https://github.com/gabyx/githooks#ignoring-hooks-and-files) in the `.githooks` area.
Either create a file with the
[Git hook](https://github.com/gabyx/githooks#supported-hooks) name, or a
directory (recommended) inside the `.githooks` folder, and place files with the
individual steps that should be executed for that event inside. If the file is
executable, it will be invoked directly, otherwise it is assumed to be a Shell
script - unless this file matches one of the
[ignore patterns](https://github.com/gabyx/githooks#ignoring-hooks-and-files) in
the `.githooks` area.

### How can I see what hooks are active?

You can look at the `.githooks` folder to see the local hooks in the repository, though if you have shared hook repositories defined, those will live under the `~/.githooks/shared` folder.
The [command line tool](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md) can list out all of them for you with `git hooks list`, and you can use it to trust or ingoring hooks.
You can look at the `.githooks` folder to see the local hooks in the repository,
though if you have shared hook repositories defined, those will live under the
`~/.githooks/shared` folder. The
[command line tool](https://github.com/gabyx/githooks/blob/main/docs/cli/git_hooks.md)
can list out all of them for you with `git hooks list`, and you can use it to
trust or ingoring hooks.

## More information

You can find more information about how this all works in the [README](https://github.com/gabyx/githooks/blob/main/README.md) of the [Githooks](https://github.com/gabyx/githooks) project repository.
You can find more information about how this all works in the
[README](https://github.com/gabyx/githooks/blob/main/README.md) of the
[Githooks](https://github.com/gabyx/githooks) project repository.

If you find it useful, please show your support by starring the project in GitHub!
If you find it useful, please show your support by starring the project in
GitHub!
16 changes: 10 additions & 6 deletions .githooks/pre-commit/list-staged-files
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
set -e
set -u

if [ -n "${STAGED_FILES}" ]; then
echo "* Staged files:" >&2

for file in $STAGED_FILES; do
echo " - $file" >&2
done
if [ -n "${STAGED_FILES:-}" ]; then
echo "* Staged files:" >&2
for file in $STAGED_FILES; do
echo " - $file" >&2
done
elif [ -n "${STAGED_FILES_FILE:-}" ]; then
echo "* Staged files:" >&2
while read -rd $'\\0' file; do
echo " - $file" >&2
done <"$STAGED_FILES_FILE"
fi
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- if: type = pull_request
os: linux
env: TEST_INSTANCE=test-rules
env: TEST_INSTANCE=test-lint

script:
- echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin
Expand Down
116 changes: 56 additions & 60 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,58 @@
{
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"go.useLanguageServer": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/.go": false
},
"go.lintFlags": [
"-E",
"godot",
"-E",
"gomnd",
"-E",
"goconst",
"-E",
"gochecknoinits",
"-E",
"nlreturn",
"-E",
"misspell",
"-E",
"lll",
"-E",
"exportloopref",
"-E",
"gocritic",
"--max-same-issues",
"0"
],
"go.lintTool": "golangci-lint",
"go.buildFlags": ["-tags", "debug"],
"go.trace.server": "messages",
"cSpell.words": [
"gomnd",
"nolint",
"threadpool"
]
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"go.useLanguageServer": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/.go": false
},
"go.lintFlags": [
"-E",
"godot",
"-E",
"gomnd",
"-E",
"goconst",
"-E",
"gochecknoinits",
"-E",
"nlreturn",
"-E",
"misspell",
"-E",
"lll",
"-E",
"exportloopref",
"-E",
"gocritic",
"--max-same-issues",
"0"
],
"go.lintTool": "golangci-lint",
"go.buildFlags": ["-tags", "debug"],
"go.trace.server": "messages",
"cSpell.words": ["gomnd", "nolint", "threadpool"]
}
17 changes: 7 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@
"presentation": {
"reveal": "always",
"panel": "shared"
},
}
},
{
"label": "[Dev Container] go-build-temp",
"type": "shell",
"command": "${workspaceFolder}/githooks/scripts/build.sh",
"args": [
"--bin-dir",
"/tmp/githooks"
],
"args": ["--bin-dir", "/tmp/githooks"],
"options": {
"shell": {
"executable": "/bin/bash",
Expand Down Expand Up @@ -78,7 +75,7 @@
},
"env": {
"CGO_ENABLED": "0",
"GOBIN": "${workspaceFolder}/githooks/bin",
"GOBIN": "${workspaceFolder}/githooks/bin"
}
},
"presentation": {
Expand All @@ -103,7 +100,7 @@
"--api-version=2",
"./apps/cli",
"--",
"uninstaller",
"uninstaller"
],
"options": {
"cwd": "${workspaceFolder}/githooks",
Expand All @@ -113,7 +110,7 @@
},
"env": {
"CGO_ENABLED": "0",
"GOBIN": "${workspaceFolder}/githooks/bin",
"GOBIN": "${workspaceFolder}/githooks/bin"
}
},
"presentation": {
Expand Down Expand Up @@ -149,7 +146,7 @@
},
"env": {
"CGO_ENABLED": "0",
"GOBIN": "${workspaceFolder}/githooks/bin",
"GOBIN": "${workspaceFolder}/githooks/bin"
}
},
"presentation": {
Expand Down Expand Up @@ -183,7 +180,7 @@
},
"env": {
"CGO_ENABLED": "0",
"GOBIN": "${workspaceFolder}/githooks/bin",
"GOBIN": "${workspaceFolder}/githooks/bin"
}
},
"presentation": {
Expand Down
Loading

0 comments on commit e65758f

Please sign in to comment.