2023-12-17 08:52:35 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from os import getenv
|
|
|
|
from os.path import dirname
|
|
|
|
from re import match
|
|
|
|
from shlex import quote
|
|
|
|
from subprocess import run
|
|
|
|
|
2024-03-14 06:16:50 +01:00
|
|
|
commit_before_sha = getenv("CI_COMMIT_BEFORE_SHA")
|
|
|
|
commit_sha = getenv("CI_COMMIT_SHA")
|
|
|
|
commit_ref_name = getenv("CI_COMMIT_REF_NAME")
|
2023-12-17 08:52:35 +01:00
|
|
|
directories = set()
|
2024-03-20 23:10:42 +01:00
|
|
|
dockerfile_updated = False
|
2023-12-17 08:52:35 +01:00
|
|
|
|
2024-03-14 06:16:50 +01:00
|
|
|
cmd = "git clone https://code.ryuslash.org/ryuslash/git-lfs-test.git ."
|
2023-12-17 08:52:35 +01:00
|
|
|
print(cmd)
|
|
|
|
run(cmd, shell=True)
|
|
|
|
|
2024-03-20 23:10:42 +01:00
|
|
|
cmd = "docker images ryuslash.org/freeloadio"
|
|
|
|
print(cmd)
|
|
|
|
process = run(cmd, shell=True, capture_output=True)
|
|
|
|
process_output = process.stdout.decode()
|
|
|
|
|
|
|
|
if len(process_output.strip().split("\n")) == 1:
|
|
|
|
# We don't have any docker file at all yet.
|
|
|
|
dockerfile_updated = True
|
|
|
|
|
2023-12-17 08:52:35 +01:00
|
|
|
if not match(r"^0+$", commit_before_sha):
|
2024-03-14 06:16:50 +01:00
|
|
|
cmd = f"git diff --name-only {quote(commit_before_sha)} {quote(commit_sha)}"
|
|
|
|
print(cmd)
|
|
|
|
process = run(cmd, shell=True, capture_output=True)
|
|
|
|
process_output = process.stdout.decode()
|
|
|
|
print(process_output)
|
|
|
|
for filename in process_output.strip().split("\n"):
|
2024-03-20 23:10:42 +01:00
|
|
|
if filename == "Dockerfile":
|
|
|
|
dockerfile_updated = True
|
2024-03-14 06:16:50 +01:00
|
|
|
directories.add(dirname(filename))
|
2023-12-17 08:52:35 +01:00
|
|
|
|
2024-03-20 23:10:42 +01:00
|
|
|
if dockerfile_updated:
|
|
|
|
cmd = "docker build -t ryuslash.org/freeloadio:latest ."
|
|
|
|
print(cmd)
|
|
|
|
run(cmd, shell=True)
|
|
|
|
|
2024-03-14 06:16:50 +01:00
|
|
|
unix_directory_list = str.join(":", directories)
|
|
|
|
print(f"python tasks.py probe --directories={quote(unix_directory_list)}")
|