initial commit

This commit is contained in:
2026-04-25 21:55:07 +01:00
commit 4bf033ff65
5 changed files with 104 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
.DS_Store
+8
View File
@@ -0,0 +1,8 @@
- id: write-argocd-repo
name: Write Argo CD repo metadata
description: Creates or overwrites .argocd/repo with origin URL, current branch, and Gitea workflow filenames, then stages it.
entry: scripts/base.sh write-argocd-repo
language: script
always_run: true
pass_filenames: false
stages: [pre-commit]
+42
View File
@@ -0,0 +1,42 @@
# pre-commit Argo CD hooks
A small pre-commit hook repository with a base runner and discrete hook scripts under `scripts/<hook-id>/run.sh`.
## Hooks
### `write-argocd-repo`
Creates or overwrites `.argocd/repo` in the repository where the hook is being run, then stages it into the current commit.
The generated file contains:
- `remote_origin_url=<origin-url>`
- `branch=<current-branch-or-short-commit>`
- one `workflow=<filename>` entry for each file directly under `.gitea/workflows`
## Usage
Add this to the consuming repository's `.pre-commit-config.yaml`:
```yaml
repos:
- repo: https://example.com/your-org/pre-commit-argocd-hooks.git
rev: v0.1.0
hooks:
- id: write-argocd-repo
```
For local development:
```yaml
repos:
- repo: local
hooks:
- id: write-argocd-repo
name: Write Argo CD repo metadata
entry: /absolute/path/to/pre-commit-argocd-hooks/scripts/base.sh write-argocd-repo
language: script
always_run: true
pass_filenames: false
stages: [pre-commit]
```
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_NAME="${1:-}"
if [[ -z "${SCRIPT_NAME}" ]]; then
echo "Usage: $0 <script-subdirectory>" >&2
exit 2
fi
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUNNER="${HOOK_DIR}/${SCRIPT_NAME}/run.sh"
if [[ ! -f "${RUNNER}" ]]; then
echo "Hook script not found: ${RUNNER}" >&2
exit 2
fi
if [[ ! -x "${RUNNER}" ]]; then
echo "Hook script is not executable: ${RUNNER}" >&2
exit 2
fi
exec "${RUNNER}"
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(git rev-parse --show-toplevel)"
cd "${repo_root}"
output_dir="${repo_root}/.argocd"
output_file="${output_dir}/repo"
workflow_dir="${repo_root}/.gitea/workflows"
mkdir -p "${output_dir}"
origin_url="$(git remote get-url origin 2>/dev/null || true)"
branch="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD)"
{
printf 'remote_origin_url=%s\n' "${origin_url}"
printf 'branch=%s\n' "${branch}"
if [[ -d "${workflow_dir}" ]]; then
find "${workflow_dir}" -maxdepth 1 -type f -printf '%f\n' \
| sort \
| while IFS= read -r workflow_file; do
printf 'workflow=%s\n' "${workflow_file}"
done
fi
} > "${output_file}"
git add "${output_file}"