name: chown
description: "Take or change ownership of the specified files."
inputs:
  uid:
    description: "User id."
    required: false
    default: ""
  gid:
    description: "Group id."
    required: false
    default: ""
  file:
    description: "File or folder to own."
    required: true
runs:
  using: "composite"
  steps:
  - name: "Determine UID and GID."
    id: ids
    run: |
      USER_UID="${{ inputs.uid }}"
      USER_GID="${{ inputs.gid }}"
      if [[ -z "$USER_UID" ]]; then
        USER_UID=$(id -u)
      fi
      if [[ -z "$USER_GID" ]]; then
        USER_GID=$(id -g)
      fi

      echo $USER_UID:$USER_GID

      echo "uid=$USER_UID" >> "$GITHUB_OUTPUT"
      echo "gid=$USER_GID" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Take ownership of output."
    uses: act/common/distros/busybox@master
    with:
      args: chown ${{ steps.ids.outputs.uid }}:${{ steps.ids.outputs.gid }} "${{ inputs.file }}" -R
