kind: Workflow
metadata:
  annotations:
    argo-connector/keywords: ModGP,SDM,CWR
    argo-connector/license: https://spdx.org/licenses/MIT
    argo-connector/notify: 'true'
    argo-connector/submitterId1: 0000-0003-0351-6523
    argo-connector/submitterName1: Claus Weiland
    workflows.argoproj.io/description: Running with Lathyrus.
    workflows.argoproj.io/pod-name-format: v2
    workflows.argoproj.io/title: Lycopodium at Living Planet 2025 03
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: 17492b4
  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.5.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: 17492b4
    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://workflow.earth/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'
