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