name: compress
description: "Compress a file or directory"
inputs:
  files:
    description: "File or directory to compress."
    required: true
  name:
    description: "Filename of the zip file."
    required: true
  recursive:
    description: "Recursivly zip files. Default: true"
    required: false
    default: "true"
  quiet:
    description: "Don't output every zipped file. Default: true"
    required: false
    default: "true"
  compressionLevel:
    description: "Compression level between 1-9. Default: 6"
    required: false
    default: "6"
  compressionMethod:
    description: "Compression method. Options: deflate or store. Default: deflate"
    required: true
    default: "deflate"
  additionalArgs:
    description: "Additional arguments."
    required: false
outputs:
  archive:
    description: "The compressed archive."
    value: ${{ steps.command.outputs.archive }}
runs:
  using: "composite"
  steps:
  - name: "Build command."
    id: command
    run: |
      WORKDIR=${WORKDIR:-.}
      cd "$WORKDIR"
      mkdir -p "$(dirname '${{ inputs.name }}')"
      COMMAND="zip -${{ inputs.compressionLevel }} -Z ${{ inputs.compressionMethod }} ${{ inputs.additionalArgs }}"
      if [[ "${{ inputs.recursive }}" == "true" ]]; then
        COMMAND="$COMMAND -r"
      fi
      if [[ "${{ inputs.quiet }}" == "true" ]]; then
        COMMAND="$COMMAND -q"
      fi
      NAME="${{ inputs.name }}"
      NAME="${NAME/ /\\ }"
      FILES="${{ inputs.files }}"
      FILES="${FILES/ /\\ }"

      COMMAND="$COMMAND $NAME $FILES"
      echo "Compressing with: $COMMAND"
      echo "::set-output name=command::$COMMAND"
      echo "::set-output name=archive::${{ inputs.name }}"
    shell: bash
  - name: "Compress archive."
    id: compress
    uses: act/common/distros/rockylinux@master
    with:
      args: ${{ steps.command.outputs.command }}
