name: urlencode
description: "Encode or decode the input string as a url."
inputs:
  input:
    description: "Input to encode/decode."
    required: true
  mild:
    description: "Do a mild conversion."
    required: false
    default: "false"
  decode:
    description: "Whether or not to decode instead of encode."
    required: true
    default: "false"
outputs:
  result:
    description: "The url-encoded or decoded string."
    value: ${{ steps.url.outputs.console }}
runs:
  using: "composite"
  steps:
  - name: "Build the command."
    id: command
    run: |
      COMMAND="urlencode"

      DECODE="${{ inputs.decode }}"
      if [[ "$DECODE" == "true" ]]; then
        COMMAND="$COMMAND -d"
      fi

      MILD="${{ inputs.mild }}"
      if [[ "$MILD" == "true" ]]; then
        if [[ "$DECODE" == "true" ]]; then
          echo "Cannot perform url decoding in mild mode."
          exit 1
        fi
        COMMAND="$COMMAND -m"
      fi

      echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Encode/decode the input."
    id: url
    uses: act/common/distros/debian@master
    with:
      args: ${{ steps.command.outputs.command }} "${{ inputs.input }}"
