Skip to content

Commit

Permalink
Add more ci scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Feb 16, 2024
1 parent dec3ad9 commit 9b45187
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ci/fetch-feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

import sys
from pathlib import Path
import subprocess

if len(sys.argv) < 2:
print("Argument run-reason is missing.")
print("Must be one of timer, merge-request")
sys.exit(1)

run_reason = sys.argv[1]
feed_dir = Path("feeds/")

match run_reason:
case "timer":
for feed in feed_dir.glob("*.json"):
subprocess.check_call(["./src/fetch.py", str(feed.absolute())])
case "merge-request":
changed_files = subprocess.check_output(
["git", "diff", "--name-only", "-r", "HEAD^1", "HEAD"]) \
.decode().splitlines()

changed_feeds = [f for f in changed_files if
f.startswith("feeds/") and f.endswith(".json")]

for feed in changed_feeds:
subprocess.check_call(["./src/fetch.py", feed])
31 changes: 31 additions & 0 deletions ci/motis-import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

import subprocess
import time
import sys


def run_motis_import() -> bool:
p = subprocess.Popen(["motis", "--import.require_successful", "1"],
stderr=subprocess.PIPE)

for line in iter(p.stderr.readline, ""):
if p.poll():
return False

sys.stdout.buffer.write(line)
if b"system boot finished" in line:
p.terminate()
return True
else:
time.sleep(1)


if __name__ == "__main__":
if run_motis_import():
sys.exit(0)
else:
sys.exit(1)
1 change: 1 addition & 0 deletions src/fetch.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2023 Jonah Brüchert <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down

0 comments on commit 9b45187

Please sign in to comment.