diff --git a/.github/msgs_checker.py b/.github/msgs_checker.py index b67f2b22a2d..cb2d78a9d4b 100644 --- a/.github/msgs_checker.py +++ b/.github/msgs_checker.py @@ -9,6 +9,9 @@ from subprocess import check_output from pathlib import Path from itertools import chain +from json import dumps +import requests +import os @dataclass @@ -65,6 +68,8 @@ def main(): if len(unknown_packages) > 0: print(f"Unknown packages: {unknown_packages}") + updated_patches = [] + for path, pkg in pkgs.items(): if pkg.name not in used_packages: continue @@ -91,22 +96,52 @@ def main(): continue # Call `git log` for 7 days history - log = check_output( - [ - "git", - "log", - "--since", - "365.days", - "-p", - "--minimal", - "--pretty=oneline", - "--", - *existing_files, - ], - cwd=base_path, - ).strip() - - print(log.decode("utf-8")) + log = ( + check_output( + [ + "git", + "log", + "--since", + "7.days", + "-p", + "--minimal", + "--pretty=oneline", + "--", + *existing_files, + ], + cwd=base_path, + ) + .strip() + .decode("utf-8") + ) + + if len(log) == 0: + print(f"Package {pkg.name} has no recent changes") + continue + + updated_patches.append(log) + + if len(updated_patches) == 0: + print("No patches to notify") + return + + patches = "\n".join(updated_patches) + + # Post to GitHub issues comment + + body = dumps( + { + "body": f"```diff\n{patches}\n```", + } + ) + requests.post( + f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/issues/{os.environ['ISSUE_NUMBER']}/comments", + headers={ + "Authorization": f"token {os.environ['GITHUB_TOKEN']}", + "Content-Type": "application/json", + }, + data=body, + ) if __name__ == "__main__": diff --git a/.github/workflows/CheckMessageDepsUpdate.yaml b/.github/workflows/CheckMessageDepsUpdate.yaml new file mode 100644 index 00000000000..8a17ccc668d --- /dev/null +++ b/.github/workflows/CheckMessageDepsUpdate.yaml @@ -0,0 +1,35 @@ +name: Check msgs / srvs update +on: + schedule: + - cron: "0 0 * * 1" + workflow_dispatch: + +jobs: + check_message_updates: + name: Check message updates + runs-on: ubuntu-22.04 + container: ros:humble + steps: + - name: Prepare workspace + run: mkdir -p ~/ros2_ws/src/scenario_simulator_v2 + + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: ~/ros2_ws/src/scenario_simulator_v2 + + - name: Install dependencies + run: | + cd ~/ros2_ws + vcs import src/scenario_simulator_v2/external < src/scenario_simulator_v2/dependency_humble.repos + + - name: Check updates + shell: bash + run: | + cd ~/ros2_ws/src/scenario_simulator_v2 + python3 .github/msgs_checker.py + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + ISSUE_NUMBER: 1203