name: extract
description: "Extract a compressed file."
inputs:
  file:
    description: "File to extract."
    required: true
  outputDir:
    description: "Directory to extract to."
    required: false
    default: ""
  prefixArgs:
    description: "Additional arguments to pass in early."
    required: false
  additionalArgs:
    description: "Additional arguments to pass in."
    required: false
  deleteSource:
    description: "Delete the compressed file afterwards."
    required: false
    default: "false"
runs:
  using: "composite"
  steps:
  - name: "Build command."
    id: command
    run: |
      COMMAND="unzip ${{ inputs.prefixArgs }} -o ${{ inputs.file }} ${{ inputs.additionalArgs }}"
      OUTPUT_DIR="${{ inputs.outputDir }}"
      if [[ -n "$OUTPUT_DIR" ]]; then
        COMMAND="$COMMAND -d \"$OUTPUT_DIR\""
      fi
      echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Convert file."
    id: convert
    uses: act/common/distros/busybox@master
    with:
      args: ${{ steps.command.outputs.command }}
  - name: "Delete source."
    run: |
      if [[ ${{ inputs.deleteSource }} != "true" ]]; then
        exit 0
      fi
      
      rm ${{ inputs.file }}
    shell: bash