name: mc-find-tag-exists
description: "Find files in s3."
inputs:
  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
  path:
    description: "The path to search for."
    required: true
  name:
    description: "The name pattern to search for."
    required: true
    default: ""
  tagName:
    description: "The tag to see if exists."
    required: true
  tagValue:
    description: "The tag value to see if exists."
    required: true
  additionalArgs:
    description: "Additional arguments."
    required: false
outputs:
  success:
    description: "Whether files with the tag were found."
    value: ${{ steps.find.outputs.success }}
runs:
  using: "composite"
  steps:
  - name: "Build command."
    id: command
    run: |
      EXEC_COMMAND="mc tag list {}"
      if [[ "${{ inputs.searchVersions }}"  == "true" ]]; then
        EXEC_COMMAND="$EXEC_COMMAND --versions"
      fi

      GREP_COMMAND="grep -E '${{ inputs.tagName }} *: ${{ inputs.tagValue }}'"

      COMMAND="--exec '$EXEC_COMMAND' ${{ inputs.additionalArgs }} | $GREP_COMMAND"
      echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Find file in S3."
    id: find
    uses: act/common/minio/mc-find@master
    with:
      alias: ${{ inputs.alias }}
      path: ${{ inputs.path }}
      name: ${{ inputs.name }}
      accessKey: ${{ inputs.accessKey }}
      secretKey: ${{ inputs.secretKey }}
      additionalArgs: ${{ steps.command.outputs.command }}
      url: ${{ inputs.url }}
