mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
github_action: Fix "notify-if-api-docs-changed" tool.
Fix `notify-if-api-docs-changed` tool to send the notification only when "changelog.md" is changed in the PR.
This commit is contained in:
5
.github/workflows/api-docs-update-check.yml
vendored
5
.github/workflows/api-docs-update-check.yml
vendored
@@ -54,14 +54,15 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.x"
|
python-version: "3.x"
|
||||||
|
|
||||||
- name: Add required permissions
|
- name: Run tools/github-changes-contain-file
|
||||||
run: chmod +x ./tools/notify-if-api-docs-changed
|
run: ./tools/github-changes-contain-file api_docs/changelog.md
|
||||||
|
|
||||||
- name: Run tools/notify-if-api-docs-changed
|
- name: Run tools/notify-if-api-docs-changed
|
||||||
id: run_check
|
id: run_check
|
||||||
|
|||||||
45
tools/github-changes-contain-file
Executable file
45
tools/github-changes-contain-file
Executable 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)
|
||||||
Reference in New Issue
Block a user