feat(ci,doctor,export): add Gitea CI/CD, verification scripts, doctor and export commands
This commit is contained in:
1 parent
d1475e7141
commit
db2cdc03ef
15 files changed
+1406
-168
No files matched your search
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Ativa os Git hooks do repositório (.githooks/pre-push e .githooks/commit-msg).
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
git config core.hooksPath .githooks
|
||||
echo "hooks ativados: git commit valida Conventional Commits e git push executa scripts/verificar.sh (desative com: git config --unset core.hooksPath)"
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Prints release notes for a given tag: extracts the matching CHANGELOG.md
|
||||
# section, or falls back to the commit log since the previous tag.
|
||||
#
|
||||
# scripts/release-notes.sh v1.2.3
|
||||
set -euo pipefail
|
||||
|
||||
tag=${1:?usage: release-notes.sh <tag>}
|
||||
version=${tag#v}
|
||||
|
||||
section=""
|
||||
if [ -f CHANGELOG.md ]; then
|
||||
section=$(awk -v head="## [$version]" '
|
||||
index($0, head) == 1 { found = 1; next }
|
||||
found && /^## \[/ { exit }
|
||||
found && /^\[[^]]+\]: / { next }
|
||||
found { print }
|
||||
' CHANGELOG.md)
|
||||
fi
|
||||
|
||||
if [ -n "$(printf '%s' "$section" | tr -d '[:space:]')" ]; then
|
||||
printf '%s\n' "$section"
|
||||
else
|
||||
previous=$(git describe --tags --abbrev=0 "$tag^" 2>/dev/null || true)
|
||||
echo "## Changes${previous:+ since $previous}"
|
||||
echo
|
||||
git log --no-merges --format='- %s (%h)' "${previous:+$previous..}$tag"
|
||||
fi
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Smoke-tests a Xexéu image: the API and the dashboard answer,
|
||||
# xexeu doctor reports ok, a HEALTHCHECK is declared and SIGTERM stops the daemon cleanly.
|
||||
# Everything runs through `docker exec`, so no port has to be reachable from
|
||||
# the CI job container. The container is always removed.
|
||||
#
|
||||
# scripts/smoke-image.sh <image-ref>
|
||||
set -euo pipefail
|
||||
|
||||
image=${1:?usage: smoke-image.sh <image-ref>}
|
||||
name="xexeu-smoke-$$-$RANDOM"
|
||||
trap 'docker rm -f "$name" >/dev/null 2>&1 || true' EXIT
|
||||
fail() { echo "smoke: $*" >&2; docker logs "$name" >&2 2>&1 || true; exit 1; }
|
||||
|
||||
docker run -d --name "$name" "$image" >/dev/null
|
||||
for _ in $(seq 1 30); do
|
||||
docker exec "$name" curl -fsS http://127.0.0.1:8788/api/health >/dev/null 2>&1 && break
|
||||
sleep 1
|
||||
done
|
||||
docker exec "$name" curl -fsS http://127.0.0.1:8788/api/health | grep -q '"status":"ok"' || fail "/api/health did not answer"
|
||||
docker exec "$name" curl -fsS http://127.0.0.1:8788/ | grep -qi '<!doctype html' || fail "dashboard is not served"
|
||||
docker exec "$name" xexeu doctor --json | grep -q '"version"' || fail "xexeu doctor --json failed"
|
||||
[ "$(docker inspect -f '{{if .Config.Healthcheck}}yes{{end}}' "$name")" = yes ] || fail "image has no HEALTHCHECK"
|
||||
[ "$(docker exec "$name" id -u)" != 0 ] || fail "daemon runs as root"
|
||||
docker stop -t 10 "$name" >/dev/null
|
||||
code=$(docker inspect -f '{{.State.ExitCode}}' "$name")
|
||||
[ "$code" = 0 ] || fail "exit code $code after SIGTERM (expected 0: SIGTERM must stop serve)"
|
||||
echo "smoke: $image ok"
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# Verificação local: executa as mesmas checagens do CI antes do push.
|
||||
#
|
||||
# scripts/verificar.sh completo: fmt, clippy, scripts, workflows, semver, compose, testes
|
||||
# scripts/verificar.sh --rapido pula a suíte de testes do workspace
|
||||
#
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
rapido=0
|
||||
[ "${1:-}" = "--rapido" ] || [ "${1:-}" = "--fast" ] && rapido=1
|
||||
failures=()
|
||||
step() { # step "name" command...
|
||||
local name="$1"; shift
|
||||
printf '\n\033[1m== %s\033[0m\n' "$name"
|
||||
if "$@"; then printf '\033[32mok\033[0m %s\n' "$name"; else printf '\033[31mFAILED\033[0m %s\n' "$name"; failures+=("$name"); fi
|
||||
}
|
||||
|
||||
step "formatting (cargo fmt)" cargo fmt --all -- --check
|
||||
step "clippy (workspace, all targets)" env RUSTFLAGS="-D warnings" cargo clippy --workspace --all-targets
|
||||
|
||||
step "bash script syntax" bash -c 'for f in scripts/*.sh .githooks/*; do [ -f "$f" ] || continue; bash -n "$f" || exit 1; done'
|
||||
|
||||
step "workflows and templates (valid YAML)" python3 -c "
|
||||
import glob, yaml
|
||||
for f in glob.glob('.gitea/**/*.yml', recursive=True):
|
||||
yaml.safe_load(open(f))
|
||||
"
|
||||
|
||||
step "brand assets" test -s logo.png
|
||||
|
||||
step "consistent Semantic Versioning 2.0.0" python3 -c "
|
||||
import re, sys
|
||||
from pathlib import Path
|
||||
|
||||
semver_re = re.compile(
|
||||
r'^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)'
|
||||
r'(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?'
|
||||
r'(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
|
||||
)
|
||||
|
||||
def cargo_version(path):
|
||||
m = re.search(r'^version\s*=\s*\"([^\"]+)\"', Path(path).read_text(), re.M)
|
||||
if not m:
|
||||
sys.exit(f'version not found in {path}')
|
||||
return m.group(1)
|
||||
|
||||
version = cargo_version('Cargo.toml')
|
||||
if not semver_re.match(version):
|
||||
sys.exit(f'invalid SemVer 2.0.0 version: {version}')
|
||||
print(version)
|
||||
"
|
||||
|
||||
if command -v docker >/dev/null && docker compose version >/dev/null 2>&1; then
|
||||
step "docker compose config" docker compose config --quiet
|
||||
else
|
||||
printf '\n(docker compose config: skipped, docker compose not available)\n'
|
||||
fi
|
||||
|
||||
if [ "$rapido" = 0 ]; then
|
||||
step "tests (cargo test --workspace)" cargo test --workspace
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
if [ ${#failures[@]} -eq 0 ]; then
|
||||
printf '\033[32mall checks passed\033[0m: ready to push.\n'
|
||||
else
|
||||
printf '\033[31mfailed:\033[0m %s\n' "${failures[*]}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user