Skip to content

Commit

Permalink
Add github posts workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
f0reachARR committed Feb 29, 2024
1 parent ce55d07 commit 218d15a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 16 deletions.
67 changes: 51 additions & 16 deletions .github/msgs_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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",

Check warning on line 108 in .github/msgs_checker.py

View workflow job for this annotation

GitHub Actions / spell-check

Unknown word (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__":
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/CheckMessageDepsUpdate.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 218d15a

Please sign in to comment.