Compare commits
6
Commits
test
...
7218004f2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7218004f2f | ||
|
|
75fd57391d | ||
|
|
a82e0a8f10 | ||
|
|
d1864c7030 | ||
|
|
43e4b9788a | ||
|
|
84b409356b |
+26
-8
@@ -39,18 +39,18 @@ async def test(request: Request):
|
||||
@app.post('/event')
|
||||
def handle_event(request: GiteaRequest):
|
||||
""" Handle event from webhook. """
|
||||
# stop early if asked
|
||||
# extract information
|
||||
commit_msg = request.head_commit['message']
|
||||
repo_url = request.repository['clone_url']
|
||||
branch_name = request.ref.split('/')[-1]
|
||||
# stop early if asked
|
||||
if commit_msg.lower().startswith('[skip ci]'):
|
||||
raise HTTPException(
|
||||
status_code=200,
|
||||
detail='skipping ci'
|
||||
)
|
||||
# clone repository
|
||||
repo_url = request.repository['clone_url']
|
||||
logging.info('cloning repository: {repo_url}')
|
||||
local_repo_dir = clone_repository(repo_url)
|
||||
logging.info(f'local_repo_dir: {local_repo_dir}')
|
||||
# locate runner script
|
||||
runner_script_path = local_repo_dir / 'runner_script.yml'
|
||||
if not runner_script_path.exists():
|
||||
@@ -58,17 +58,35 @@ def handle_event(request: GiteaRequest):
|
||||
status_code=200,
|
||||
detail="no runner_script.yml in repository root"
|
||||
)
|
||||
# load runner commands
|
||||
# load runner script
|
||||
runner_script = load_runner_script(path=runner_script_path)
|
||||
for pipeline_name, pipeline_step in runner_script.pipelines.items():
|
||||
print(pipeline_name)
|
||||
print(pipeline_step)
|
||||
# determine pipeline to run
|
||||
if branch_name not in runner_script.pipelines.keys():
|
||||
# get default pipeline
|
||||
if 'default' not in runner_script.pipelines.keys():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail='no pipelines defined in runner_script.yml'
|
||||
)
|
||||
pipeline = runner_script.pipelines['default']
|
||||
else:
|
||||
# get custom pipeline
|
||||
pipeline = runner_script.pipelines[branch_name]
|
||||
logging.info(f'running pipeline {pipeline.name}')
|
||||
# TODO: create virtualenv?
|
||||
# install requirements
|
||||
assert pipeline.requirements is not None
|
||||
requirements_path = local_repo_dir / pipeline.requirements
|
||||
os.system(f'pip install -r {requirements_path}')
|
||||
for cmd in pipeline.script:
|
||||
print(cmd)
|
||||
|
||||
# send response
|
||||
raise HTTPException(
|
||||
status_code=202,
|
||||
detail='received task'
|
||||
)
|
||||
# consider to include link to page that show progress
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_dotenv('dev.env')
|
||||
|
||||
@@ -28,5 +28,6 @@ def load_runner_script(path: Path) -> RunnerScript:
|
||||
with open(path, 'r') as fh:
|
||||
script = yaml.safe_load(fh)
|
||||
runner_script = RunnerScript.parse_obj(script)
|
||||
logging.debug('finished')
|
||||
return runner_script
|
||||
|
||||
+1
-2
@@ -4,8 +4,7 @@ definitions:
|
||||
name: test
|
||||
requirements: req-prod.txt
|
||||
script:
|
||||
- command arg1 arg2
|
||||
- command2 arg1 arg2
|
||||
- echo nvidia-smi
|
||||
|
||||
pipelines:
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user