name: "Publish Docker Images"
description: "Publish Docker Image to the provided registry"

inputs:
  registry:
    description: 'Docker registry'
    required: true
    type: string
  username:
    description: 'login username'
    required: true
    type: string
  password:
    description: 'login password'
    required: true
    type: string
  branch_name:
    description: 'Name of the branch the workflow runs on'
    required: true
    type: string
  dry-run:
    description: dry run flag
    required: true
    type: boolean

runs:
  using: "composite"
  steps:
    - name: Login to Docker Registry
      uses: docker/login-action@v2
      with:
        registry: ${{ inputs.registry }}
        username: ${{ inputs.username }}
        password: ${{ inputs.password }}

    - name: Get Tag
      uses: ./.github/actions/get-image-tag
      with:
        branch_name: ${{ inputs.branch_name }}

    - name: Publish
      if: ${{ github.event.inputs.dry-run != 'true' }}
      shell: bash
      run: |
        npm ci && npm run build.release
        echo "Running the docker with tag $TAG_VERSION"

        npx @alfresco/adf-cli docker-publish \
          --dockerRepo "${{ inputs.registry }}/alfresco/dev" \
          --buildArgs "PROJECT_NAME=content-ce" \
          --dockerTags "$TAG_VERSION" \
          --pathProject "$(pwd)"
