initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
||||||
@@ -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]
|
||||||
@@ -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]
|
||||||
|
```
|
||||||
Executable
+24
@@ -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}"
|
||||||
Executable
+29
@@ -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}"
|
||||||
Reference in New Issue
Block a user