Skip to content
Snippets Groups Projects
Commit 05857155 authored by gyulaid's avatar gyulaid
Browse files

Change detection via git

parent 4cdc162d
No related branches found
No related tags found
No related merge requests found
[metadata] [metadata]
name = alice-ci name = alice-ci
version = 0.0.5 version = 0.0.6
author = Daniel Gyulai author = Daniel Gyulai
description = Alice CI framework description = Alice CI framework
long_description = file: README.md long_description = file: README.md
......
...@@ -30,8 +30,8 @@ def parse_jobs(args): ...@@ -30,8 +30,8 @@ def parse_jobs(args):
print("Begin pipeline steps...") print("Begin pipeline steps...")
for step in args.steps: for step in args.steps:
if step in jobParser.jobs: if step in jobParser.jobs:
jobParser.execute_job(step) status = jobParser.execute_job(step)
print(f"[Step] {step}: SUCCESS") print(f"[Step] {step}: {status}")
else: else:
print(f"Step {step} not found in {args.input}") print(f"Step {step} not found in {args.input}")
exit(1) exit(1)
......
import os
import subprocess
import yaml import yaml
from alice.exceptions import ConfigException from alice.exceptions import ConfigException
...@@ -44,10 +46,41 @@ class ConfigParser: ...@@ -44,10 +46,41 @@ class ConfigParser:
print(f"[Alice] Parsed jobs: {', '.join(jobs.keys())}") print(f"[Alice] Parsed jobs: {', '.join(jobs.keys())}")
return jobs return jobs
else: else:
raise ConfigException("[Alice] No jobs defined in config") raise ConfigException("No jobs defined in config")
def __is_changed(self, changes):
try:
target = changes["branch"]
paths = []
for path in changes["paths"]:
paths.append(os.path.abspath(path))
print(paths)
# TODO: Error handling
command = ["git", "diff", "--name-only", target]
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
p.wait()
for line in p.stdout:
change_path = os.path.abspath(line.decode("UTF-8").strip())
for path in paths:
spec_path = os.path.abspath(path)
if change_path.startswith(spec_path):
print(f"Modified file: {change_path}")
print(f"Path match: {path}")
return True
except KeyError:
raise ConfigException(f"Invalid 'changes' config: {changes}")
return False
def execute_job(self, job_name): def execute_job(self, job_name):
if job_name in self.jobs: if job_name in self.jobs:
# Pass the job_spec to a runner job_spec = self.jobs[job_name]
runner = self.factory.get_runner(self.jobs[job_name]["type"]) should_run = True
runner.run(self.jobs[job_name]) if "changes" in job_spec:
should_run = self.__is_changed(job_spec["changes"])
if should_run:
runner = self.factory.get_runner(job_spec["type"])
runner.run(job_spec)
return "SUCCESS"
else:
print("SKIP, no change detected")
...@@ -18,6 +18,10 @@ runners: ...@@ -18,6 +18,10 @@ runners:
jobs: jobs:
- name: env - name: env
type: python type: python
changes:
branch: origin/master
paths:
- "docs"
env: env:
- name: B - name: B
value: E value: E
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment