Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
marjo-luc committed Feb 11, 2025
1 parent 5e60e8b commit bf3d97d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 5 deletions.
14 changes: 9 additions & 5 deletions .github/actions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ runs:
username: ${{ github.repository_owner }}
password: ${{ github.token }}

# - name: Generate OGC application package process CWL
# run: python3 ${{ github.action_path }}/generate_app_pack.py ${{ inputs.algorithm-config-path }} ${{ env.REPO_NAME }}:${{ env.BRANCH }}
# shell: bash
# env:
# GITHUB_ACTION_PATH: ${{ github.action_path }}
- name: Generate OGC application package process CWL
run: python3 ${{ github.action_path }}/generate_app_pack.py nasa/algorithm_config.yml process.cwl ${{ github.action_path }}/templates/process.cwl
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}

- name: List
run: ls -la
shell: bash

# - name: Extract metadata (tags, labels) for Docker
# id: meta
Expand Down
54 changes: 54 additions & 0 deletions .github/actions/generate_app_pack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import yaml
import json
import argparse

def yaml_to_cwl(yaml_file, cwl_file, template_file):
with open(yaml_file, 'r') as f:
config = yaml.safe_load(f)

with open(template_file, 'r') as f:
workflow = yaml.safe_load(f)

workflow["$graph"][0]["label"] = config["algorithm_name"]
workflow["$graph"][0]["doc"] = config["algorithm_description"]
workflow["$graph"][0]["id"] = config["algorithm_name"]
workflow["$graph"][1]["requirements"]["DockerRequirement"]["dockerPull"] = config["algorithm_name"]
workflow["$graph"][1]["baseCommand"] = "/app/" + config["algorithm_name"] + "/" + config["run_command"]

workflow_inputs = workflow["$graph"][0]["inputs"]
process_inputs = workflow["$graph"][1]["inputs"]
step_inputs = workflow["$graph"][0]["steps"]["process"]["in"]

for param in config.get("inputs", {}).get("positional", []):
input_name = param["name"]
input_type = "Directory" if param.get("type", True) else "string"

workflow_inputs[input_name] = {
"doc": param["description"],
"label": param["description"],
"type": input_type
}

process_inputs[input_name] = {
"type": input_type,
"inputBinding": {
"position": len(process_inputs) + 1,
"prefix": f"--{input_name}"
}
}

step_inputs[input_name] = input_name

with open(cwl_file, 'w') as f:
yaml.dump(workflow, f, default_flow_style=False, sort_keys=False)

print(f"CWL workflow saved to {cwl_file}")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert YAML config to CWL workflow.")
parser.add_argument("yaml_file", help="Path to the input algorithm YAML configuration file.")
parser.add_argument("cwl_file", help="Path to the output CWL workflow file.")
parser.add_argument("template_file", help="Path to the CWL template file.")

args = parser.parse_args()
yaml_to_cwl(args.yaml_file, args.cwl_file, args.template_file)
42 changes: 42 additions & 0 deletions .github/actions/templates/process.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cwlVersion: v1.2
$graph:
- class: Workflow
label: ""
doc: ""
id: ""
inputs: {}
outputs:
out:
type: Directory
outputSource: process/outputs_result
steps:
process:
run: "#process"
in: {}
out:
- outputs_result

- class: CommandLineTool
id: process
requirements:
DockerRequirement:
dockerPull: ""
NetworkAccess:
networkAccess: true
EnvVarRequirement:
envDef:
PATH: "/opt/conda/bin:/opt/conda/condabin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
baseCommand: ""
arguments: []
inputs: {}
outputs:
outputs_result:
outputBinding:
glob: ./output*
type: Directory

$namespaces:
s: https://schema.org/
s:softwareVersion: 1.0.0
schemas:
- http://schema.org/version/9.0/schemaorg-current-http.rdf

0 comments on commit bf3d97d

Please sign in to comment.