Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 docker table builder #172

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/scripts/workflow_to_docker_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3

import argparse
import pathlib

def parse_command():
"""Function to parse the command line input
Args:
None
Return:
Namespace: returns the args as a standard Namespace object
"""
parser = argparse.ArgumentParser(description='Generate Table of Tools and Their Dockers from a CWL Workflow')
parser.add_argument('input_file')
dmiller15 marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--output_file',
default='TABLE.md',
help='Path to output file.')
args = parser.parse_args()
if not args.output_file.endswith('.md'): args.output_file = args.output_file + ".md"
return args

def parse_workflow(filepath: str, pathdict: dict | None = None) -> dict:
"""Function to recursively build dict of unique subworkflows and tools from a file.
Args:
filepath: Path to the input cwl
pathdict: Dict to store the unique subworkflows and tools
Return:
pathdict: Dict containing two lists. One of unique subworkflows; one of unique tools
"""
if not pathdict: pathdict = {}
if "workflows" not in pathdict: pathdict["workflows"] = []
if "tools" not in pathdict: pathdict["tools"] = []
inpath = pathlib.Path(filepath).resolve()
with open(inpath) as fh:
for line in fh:
if "run:" not in line: continue
relpath = inpath.parent / line.strip().split(' ')[-1]
respath = relpath.resolve()
if respath in pathdict["workflows"] or respath in pathdict["tools"]: continue
dmiller15 marked this conversation as resolved.
Show resolved Hide resolved
if not respath.match('*/tools/*'):
pathdict["workflows"].append(respath)
pathdict = parse_workflow(respath, pathdict)
else:
pathdict["tools"].append(respath)
return pathdict

def get_docker(filepath: str) -> str:
"""
Args:
filepath: Path to the input cwl
Return:
string: Name of item in dockerPull field or None
"""
inpath = pathlib.Path(filepath)
with open(inpath) as toolfile:
for line in toolfile:
if "dockerPull" in line:
return line.strip().split(' ')[-1].strip("\"'")
return "None"

def main():
args = parse_command()
appdict: dict = parse_workflow(args.input_file)
payload: list[tuple[str]] = sorted([(cwltool.name, get_docker(cwltool)) for cwltool in appdict['tools']])
with open(args.output_file, 'w') as outfile:
print(f"# Dockers of {pathlib.Path(args.input_file).name}\n", file=outfile)
print("TOOL|DOCKER\n-|-", file=outfile)
for item in payload:
print('|'.join(item), file=outfile)

if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions .github/workflows/update_docker_tables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Update Docker Tables

on: [pull_request]

permissions:
contents: write
pull-requests: write

jobs:
update-tables:
name: Update Docker Tables
runs-on: ubuntu-22.04
steps:
- id: checkout
uses: actions/checkout@v3
name: Checkout Repo
with:
ref: ${{ github.head_ref }}
- id: make-somatic-table
name: Make Docker Table for Somatic Workflow
run: |
python .github/scripts/workflow_to_docker_table.py --output_file docs/dockers_somatic.md workflow/kfdrc-somatic-variant-workflow.cwl
- id: make-consensus-table
name: Make Docker Table for Consensus Workflow
run: |
python .github/scripts/workflow_to_docker_table.py --output_file docs/dockers_consensus.md workflow/kfdrc_consensus_calling.cwl
- id: cpr
name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: update docker table
title: Update Production WF Docker Tables
body: |
Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action.

Docker tables for production workflows now have most up-to-date and complete list of Dockers.
delete-branch: true
branch: ${{ github.head_ref }}-adjust-dockers
labels: bix-dev