name: butler-push
description: "Upload files to butler."
inputs:
  file:
    description: "Input file or folder to upload."
    required: true
  account:
    description: "ItchIo account name."
    required: true
  project:
    description: "ItchIo project name."
    required: true
  channel:
    description: "ItchIo channel name."
    required: true
  apiKey:
    description: "Itch.io API key."
    required: true
  version:
    description: "The version of the file to upload."
    required: true
    default: ""
runs:
  using: "composite"
  steps:
  - name: "Get channel."
    id: channel
    run: bash ${{ github.action_path }}/get_channel.sh "${{ inputs.channel }}"
    shell: bash
  - name: "Build command."
    id: command
    run: |
      # Replace each space with a backslash and a space
      FILE="${{ inputs.file }}"
      FILE="${FILE// /\\ }"

      DEST="${{ inputs.account }}/${{ inputs.project }}"
      CHANNEL="${{ steps.channel.outputs.channel }}"
      if [[ -n "$CHANNEL" ]]; then
        DEST="$DEST:$CHANNEL"
      fi
      COMMAND="push $FILE $DEST"

      VERSION="${{ inputs.version }}"
      if [[ -n "$VERSION" ]]; then
        COMMAND="$COMMAND --userversion $VERSION"
      fi
      echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Upload files to ItchIO."
    uses: act/common/itchio/butler@master
    with:
      command: ${{ steps.command.outputs.command }}
      apiKey: ${{ inputs.apiKey }}
