ci: replace paths filter action
This commit is contained in:
parent
ec3f19420c
commit
b94705e1c0
|
|
@ -16,17 +16,63 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- id: filter
|
- id: filter
|
||||||
uses: dorny/paths-filter@v3
|
name: Detect changes
|
||||||
with:
|
run: |
|
||||||
filters: |
|
python - <<'PY'
|
||||||
backend:
|
import json
|
||||||
- 'back001/**'
|
import os
|
||||||
- '.forgejo/workflows/**'
|
import subprocess
|
||||||
- 'ci/**'
|
import sys
|
||||||
frontend:
|
|
||||||
- 'front001/**'
|
event_path = os.environ.get("GITHUB_EVENT_PATH")
|
||||||
- '.forgejo/workflows/**'
|
base = None
|
||||||
- 'ci/**'
|
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:
|
outputs:
|
||||||
backend: ${{ steps.filter.outputs.backend }}
|
backend: ${{ steps.filter.outputs.backend }}
|
||||||
frontend: ${{ steps.filter.outputs.frontend }}
|
frontend: ${{ steps.filter.outputs.frontend }}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue