kind: Workflow
metadata:
  annotations:
    argo-connector/keywords: Lycopodium,ModGP,SDM,test,CWR
    argo-connector/license: https://spdx.org/licenses/CC-BY-SA-4.0
    argo-connector/notify: 'true'
    argo-connector/submitterId1: 0000-0001-9447-460X
    argo-connector/submitterName1: Daniel Bauer
    workflows.argoproj.io/description: Crop Wild Relatives distribution modeling workflow
      using ModGP for Lycopodium. Lycopodium is not not actually a crop species, but
      serves as a good test genus due to the limited amount of species in this genus
      (and thus the short workflow execution runtime). Lycopodium is a genus of clubmosses
      within the family Lycopodiaceae. These perennial, evergreen plants are characterized
      by their small, needle-like or scale-like leaves arranged in spirals or whorls
      along the stems. Lycopodium species reproduce via spores rather than seeds and
      often form dense mats in forests, particularly in moist, shaded environments.
    workflows.argoproj.io/pod-name-format: v2
    workflows.argoproj.io/title: Species distribution models for Lycopodium
spec:
  arguments:
    parameters:
    - description: Genus of species for distribution modeling
      name: species
      value: Lycopodium
    - description: Number of cores for SDM calculation
      name: numberOfCores
      value: '9'
    - description: URL of CWR source repository
      name: modgpSource
      value: https://github.com/BioDT/uc-CWR.git
    - description: Revision of CWR source
      name: modgpRevision
      value: main
  artifactGC:
    forceFinalizerRemoval: true
  entrypoint: workflow
  onExit: exit-handler
  podGC:
    strategy: OnWorkflowSuccess
  templates:
  - inputs: {}
    metadata: {}
    name: workflow
    outputs: {}
    steps:
    - - arguments:
          parameters:
          - name: numberOfCores
            value: '{{ workflow.parameters.numberOfCores }}'
        name: create-credentials
        template: create-credentials
    - - arguments:
          artifacts:
          - from: '{{ steps.create-credentials.outputs.artifacts.credentials-file
              }}'
            name: credentials-file
          parameters:
          - name: species
            value: '{{ workflow.parameters.species }}'
          - name: source
            value: '{{ workflow.parameters.modgpSource }}'
          - name: codeRevision
            value: '{{ workflow.parameters.modgpRevision }}'
          - name: numberOfCores
            value: '{{ workflow.parameters.numberOfCores }}'
        name: modgp
        template: modgp
  - inputs:
      parameters:
      - name: numberOfCores
    metadata: {}
    name: create-credentials
    outputs:
      artifacts:
      - artifactGC:
          strategy: OnWorkflowCompletion
        name: credentials-file
        path: SHARED-APICredentials.R
    script:
      command:
      - sh
      env:
      - name: GBIF_USER
        valueFrom:
          secretKeyRef:
            key: user
            name: gbif-api-secret
      - name: GBIF_EMAIL
        valueFrom:
          secretKeyRef:
            key: email
            name: gbif-api-secret
      - name: GBIF_PWD
        valueFrom:
          secretKeyRef:
            key: pwd
            name: gbif-api-secret
      - name: CDS_USER
        valueFrom:
          secretKeyRef:
            key: user
            name: cds-api-secret
      - name: CDS_KEY
        valueFrom:
          secretKeyRef:
            key: key
            name: cds-api-secret
      image: alpine
      name: ''
      resources: {}
      source: "cat <<EOF > SHARED-APICredentials.R\n  # CDS\n  API_User <- \"$CDS_USER\"\
        \n  API_Key <- \"$CDS_KEY\"\n\n  numberOfCores <- {{ inputs.parameters.numberOfCores\
        \ }}\n\n  options(gbif_user = \"$GBIF_USER\")\n  options(gbif_email = \"$GBIF_EMAIL\"\
        )\n  options(gbif_pwd = \"$GBIF_PWD\")\n"
  - container:
      args:
      - /src/ModGP MASTER.R
      - '{{ inputs.parameters.species }}'
      command:
      - Rscript
      env:
      - name: CWR_ON_DESTINE
        value: '1'
      image: ghcr.io/biodt/cwr:0.3.0
      name: cwr-container
      resources: {}
      workingDir: /src
    inputs:
      artifacts:
      - git:
          repo: '{{ inputs.parameters.source }}'
          revision: '{{ inputs.parameters.codeRevision }}'
        name: src
        path: /src
      - name: credentials-file
        path: /src/R Scripts/SHARED-APICredentials.R
      - name: data-cache
        path: /src/Data
        s3:
          key: cache/Data
      parameters:
      - name: species
      - name: numberOfCores
      - name: source
        value: https://github.com/BioDT/uc-CWR.git
      - name: codeRevision
        value: main
    metadata: {}
    name: modgp
    outputs:
      artifacts:
      - archive:
          none: {}
        name: data-cache-updated
        path: /src/Data
        s3:
          key: cache/Data
      - archive:
          none: {}
        name: exports
        path: /src/Exports/ModGP
  - inputs: {}
    metadata: {}
    name: exit-handler
    outputs: {}
    steps:
    - - arguments: {}
        inline:
          http:
            headers:
            - name: Authorization
              valueFrom:
                secretKeyRef:
                  key: token
                  name: argo-connector-auth-secret
            insecureSkipVerify: true
            successCondition: response.statusCode == 202
            timeoutSeconds: 10
            url: https://217.71.193.143/connector/notify/{{ workflow.namespace }}/{{workflow.name
              }}
          inputs: {}
          metadata: {}
          outputs: {}
          retryStrategy:
            backoff:
              duration: 1m
              factor: '2'
              maxDuration: 30m
            limit: '10'
        name: notify-argo-connector
        when: '{{ workflow.status }} == Succeeded && {{ workflow.annotations.argo-connector/notify
          }} == true'
