---
name: "Publish Debian package on a Aptly repository"
author: "Benjamin Renard <brenard@zionetrix.net>"
description: "Publish one (or more) Debian package on a Aptly repository using its API"
inputs:
  api_url:
    description: "Your Aptly API URL"
    required: true
  api_username:
    description: "Username to authenticate on your Aptly API"
    required: true
  api_password:
    description: "Password to authenticate on your Aptly API"
    required: true
  prefix:
    description: "The publishing prefix"
    default: "."
  repo_component:
    description: "The component name to publish on"
    default: "main"
  repo_name:
    description: "The repository name to publish on. If not specified, it will be computed using the specified prefix and component and the detected package distribution. See doc for details."
  path:
    description: "Path to the directory where files to publish are stored"
    default: "dist"
  source_name:
    description: "Name of the source package to publish (optional, default: all changes files are will be publish)"
  max_retries:
    description: "The number of retry in case of error calling the Aptly API (optional, default: no retry)"
  force_overwrite:
    description: "When publishing, overwrite files in pool/ directory without notice"
    default: false

runs:
  using: "composite"
  steps:
    - name: Set GitHub Path
      run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
      shell: bash
      env:
        GITHUB_ACTION_PATH: ${{ github.action_path }}

    - name: "Publishing"
      env:
        APTLY_API_URL: ${{ inputs.api_url }}
        APTLY_API_USERNAME: ${{ inputs.api_username }}
        APTLY_API_PASSWORD: ${{ inputs.api_password }}
        APTLY_PREFIX: ${{ inputs.prefix }}
        APTLY_REPO_COMPONENT: ${{ inputs.repo_component }}
        APTLY_REPO_NAME: ${{ inputs.repo_name }}
        APTLY_PATH: ${{ inputs.path }}
        APTLY_SOURCE_NAME: ${{ inputs.source_name }}
        APTLY_MAX_RETRIES: ${{ inputs.max_retries }}
        APTLY_FORCE_OVERWRITE: ${{ inputs.force_overwrite }}
      run: aptly-publish