ci: avoid python in change detection
Some checks failed
ci / changes (push) Successful in 3s
ci / backend (push) Successful in 2m1s
ci / flutter (push) Has been cancelled

This commit is contained in:
Oskar Kapala 2026-01-16 15:49:40 +01:00
parent b94705e1c0
commit a477e1ff54

View file

@ -18,61 +18,44 @@ jobs:
- id: filter - id: filter
name: Detect changes name: Detect changes
run: | run: |
python - <<'PY' set -euo pipefail
import json git fetch --quiet --depth=1 origin "${GITHUB_BASE_REF:-}" || true
import os
import subprocess
import sys
event_path = os.environ.get("GITHUB_EVENT_PATH") diff_range=""
base = None if [ -n "${GITHUB_BASE_REF:-}" ]; then
head = None base_ref="origin/${GITHUB_BASE_REF}"
if event_path and os.path.exists(event_path): if git rev-parse --verify "$base_ref" >/dev/null 2>&1; then
with open(event_path, "r", encoding="utf-8") as handle: diff_range="$(git merge-base "$base_ref" HEAD)..HEAD"
data = json.load(handle) fi
if "pull_request" in data: else
base = data["pull_request"]["base"]["sha"] if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
head = data["pull_request"]["head"]["sha"] diff_range="HEAD^..HEAD"
else: fi
base = data.get("before") fi
head = data.get("after") or data.get("checkout_sha")
if not head: if [ -n "$diff_range" ]; then
head = os.environ.get("GITHUB_SHA") files="$(git diff --name-only "$diff_range")"
else
files="$(git ls-files)"
fi
if not base or base == "0000000000000000000000000000000000000000": backend=false
try: frontend=false
subprocess.check_call( while IFS= read -r path; do
["git", "rev-parse", f"{head}^"], case "$path" in
stdout=subprocess.DEVNULL, back001/*|.forgejo/workflows/*|ci/*) backend=true ;;
stderr=subprocess.DEVNULL, esac
) case "$path" in
base = f"{head}^" front001/*|.forgejo/workflows/*|ci/*) frontend=true ;;
except Exception: esac
base = None done <<EOF
$files
EOF
if base: {
diff_cmd = ["git", "diff", "--name-only", base, head] echo "backend=$backend"
else: echo "frontend=$frontend"
diff_cmd = ["git", "ls-files"] } >> "$GITHUB_OUTPUT"
files = subprocess.check_output(diff_cmd, text=True).splitlines()
backend = False
frontend = False
for path in files:
if path.startswith("back001/") or path.startswith(".forgejo/workflows/") or path.startswith("ci/"):
backend = True
if path.startswith("front001/") or path.startswith(".forgejo/workflows/") or path.startswith("ci/"):
frontend = True
out_path = os.environ.get("GITHUB_OUTPUT")
if not out_path:
print("GITHUB_OUTPUT not set", file=sys.stderr)
sys.exit(1)
with open(out_path, "a", encoding="utf-8") as handle:
handle.write(f"backend={'true' if backend else 'false'}\n")
handle.write(f"frontend={'true' if frontend else 'false'}\n")
PY
outputs: outputs:
backend: ${{ steps.filter.outputs.backend }} backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }} frontend: ${{ steps.filter.outputs.frontend }}