name: gitea-upload-generic-package
description: "Upload a generic package to Gitea."
inputs:
  url:
    description: "Url of the Gitea server repository."
    required: true
    default: ${{ github.server_url }}
  organization:
    description: "Organization to upload the package to."
    required: true
    default: ${{ github.repository_owner }}
  apiToken:
    description: "Api Token to for Gitea."
    required: true
    default: ${{ github.token }}
  version:
    description: "The version of package to upload."
    required: false
    default: ""
  name:
    description: "Name of the package."
    required: false
    default: ""
  file:
    description: "Path of the file to upload."
    required: false
    default: ""
  filename:
    description: "Name to upload the file as. Defaults to the basename of the file."
    required: false
    default: ""
  additionalArgs:
    description: "Additional arguments to pass into curl."
    required: false
outputs:
  query:
    description: "The query result."
    value: ${{ steps.query.outputs.query }}
runs:
  using: "composite"
  steps:
  - name: "Get filename."
    id: file
    run: |
      FILE="${{ inputs.filename }}"
      if [[ -z "$FILE" ]]; then
        FILE="${{ inputs.file }}"
      fi
      FILE=$(basename "$FILE")
      echo "file=$FILE" >> "$GITHUB_OUTPUT"
    shell: bash
  - uses: act/common/utils/urlencode@master
    id: url
    with:
      input: ${{ steps.file.outputs.file }}
  - name: "Build route."
    id: route
    run: |
      ROUTE="/api/packages/${{ inputs.organization }}/generic/${{ inputs.name }}/${{ inputs.version }}/${{ steps.url.outputs.result }}"
      echo "route=$ROUTE" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Build and run query."
    id: query
    uses: act/common/github/github-query@master
    with:
      url: ${{ inputs.url }}
      route: ${{ steps.route.outputs.route }}
      apiToken: ${{ inputs.apiToken }}
      additionalArgs: --upload-file "${{ inputs.file }}" ${{ inputs.additionalArgs }}
