apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: publish-artifact
  labels:
    dagweave.io/catalog-item: publish-artifact
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.1"
    dagweave.io/catalog-category: "CI/CD"
spec:
  entrypoint: publish
  templates:
    - name: publish
      inputs:
        parameters:
          # Path to the file to upload (in the run's filesystem / mounted volume).
          - name: file-path
          # Destination URL to PUT the artifact to.
          - name: registry-url
          # Name of the Kubernetes Secret holding the registry credentials, formatted
          # as "user:password" for HTTP basic auth. Defaults let a user leave them
          # blank in the Inspector.
          - name: credentials-secret-name
            default: artifact-registry-credentials
          - name: credentials-secret-key
            default: credentials
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # curlimages/curl:8.23.0
        image: curlimages/curl@sha256:3fb7e13e5d179a845c97d78204f3f1064d1907037f26a3ebf91710571151fd93
        command: [sh, -c]
        # The file path, URL and credentials are passed as env vars (below), never
        # interpolated from Argo into the shell, so values with quotes or shell
        # metacharacters are safe. -sSf makes a non-2xx response fail the step.
        args:
          - |
            set -eu
            curl -sSf -u "$CREDENTIALS" --upload-file "$FILE_PATH" "$REGISTRY_URL"
        env:
          - name: FILE_PATH
            value: "{{inputs.parameters.file-path}}"
          - name: REGISTRY_URL
            value: "{{inputs.parameters.registry-url}}"
          - name: CREDENTIALS
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.credentials-secret-name}}"
                key: "{{inputs.parameters.credentials-secret-key}}"
