name: mc-cp
description: "Copy files to or from s3."
inputs:
  target:
    description: "Target file."
    required: true
  dest:
    description: "Destination file."
    required: true
  accessKey:
    description: "S3 access key."
    required: true
  secretKey:
    description: "S3 secret key."
    required: true
  alias:
    description: "S3 alias."
    required: true
  url:
    description: "S3 url."
    required: true
    default: https://s3-us-gov-west-1.amazonaws.com
  recursive:
    description: "Is the command recursive."
    required: true
    default: "true"
  tags:
    description: "Tags as ampersand-separated list of key-value pairs."
    required: true
    default: ""
runs:
  using: "composite"
  steps:
  - name: "Build command."
    id: command
    run: |
      # Replace each space with a backslash and a space
      TARGET="${{ inputs.target }}"
      TARGET="${TARGET// /\\ }"
      DEST="${{ inputs.dest }}"
      DEST="${DEST// /\\ }"
      COMMAND="cp $TARGET $DEST"
      RECURSIVE="${{ inputs.recursive }}"
      if [[ "$RECURSIVE" == "true" ]]; then
        COMMAND="$COMMAND --recursive"
      fi
      TAGS="${{ inputs.tags }}"
      if [[ -n "$TAGS" ]]; then
        COMMAND="$COMMAND --tags $TAGS"
      fi
      echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Copy files to/from S3."
    uses: act/common/minio/mc@master
    with:
      alias: ${{ inputs.alias }}
      command: ${{ steps.command.outputs.command }}
      accessKey: ${{ inputs.accessKey }}
      secretKey: ${{ inputs.secretKey }}
      url: ${{ inputs.url }}
