diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 05f77f3..299224e 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -16,17 +16,63 @@ jobs: - uses: actions/checkout@v4 - id: filter - uses: dorny/paths-filter@v3 - with: - filters: | - backend: - - 'back001/**' - - '.forgejo/workflows/**' - - 'ci/**' - frontend: - - 'front001/**' - - '.forgejo/workflows/**' - - 'ci/**' + name: Detect changes + run: | + python - <<'PY' + import json + import os + import subprocess + import sys + + 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") + + if not head: + head = os.environ.get("GITHUB_SHA") + + 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 + + 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 outputs: backend: ${{ steps.filter.outputs.backend }} frontend: ${{ steps.filter.outputs.frontend }}