Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

github_action: Fix "notify-if-api-docs-changed" tool.

Vector732dca184fd3f6
diff --git a/.github/workflows/api-docs-update-check.yml b/.github/workflows/api-docs-update-check.yml
index 4fa0d6241b3..e31dc57a3ce 100644
--- a/.github/workflows/api-docs-update-check.yml
+++ b/.github/workflows/api-docs-update-check.yml
@@ -54,14 +54,15 @@ jobs:
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
+ fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- - name: Add required permissions
- run: chmod +x ./tools/notify-if-api-docs-changed
+ - name: Run tools/github-changes-contain-file
+ run: ./tools/github-changes-contain-file api_docs/changelog.md
- name: Run tools/notify-if-api-docs-changed
id: run_check
diff --git a/tools/github-changes-contain-file b/tools/github-changes-contain-file
new file mode 100755
index 00000000000..b5046feaff3
--- /dev/null
+++ b/tools/github-changes-contain-file
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import os
+import subprocess
+import sys
+from pathlib import Path
+
+
+def is_file_changed(file_path: str) -> bool:
+ event_path = os.environ.get("GITHUB_EVENT_PATH", "")
+ if not event_path:
+ sys.exit("GITHUB_EVENT_PATH environment variable not set")
+
+ with open(Path(event_path)) as f:
+ event = json.load(f)
+
+ before = event.get("before")
+ after = event.get("after")
+ if not before or not after:
+ sys.exit("Missing 'before' or 'after' commit SHAs in event data")
+
+ try:
+ result = subprocess.run(
+ ["git", "diff", "--quiet", before, after, "--", file_path],
+ check=False,
+ capture_output=True,
+ )
+ return result.returncode == 1
+ except subprocess.CalledProcessError:
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "file",
+ type=str,
+ )
+ args = parser.parse_args()
+
+ if is_file_changed(args.file):
+ sys.exit(0)
+ else:
+ sys.exit(1)