---
name: Build and deploy docs
"on":
  schedule:
    # Run at 05:17 on Tuesday and Thursday
    - cron: '17 5 * * 2,4'
  workflow_dispatch:
    inputs:
      repository-owner:
        description: GitHub account or org that owns the repository
        type: string
        required: true
        default: ansible
      repository-name:
        description: Name of the GitHub repository
        type: string
        required: true
        default: ansible-documentation
      repository-branch:
        description: Branch, tag, or commit SHA
        type: string
        required: true
        default: devel
      ansible-package-version:
        description: Ansible community package version
        type: choice
        required: true
        default: devel
        options:
        - devel
        - '13'
        - '12'
        - '11'
        - '10'
        - '9'
      generate-redirects:
        description: Generate page redirects
        type: boolean
        default: true
      deploy:
        description: Deploy the build
        type: boolean
        required: true
        default: false
      deployment-environment:
        description: Deployment environment
        type: choice
        required: true
        default: test
        options:
        - production
        - test

jobs:
  build-package-docs:
    name: 📝 Build
    uses: ./.github/workflows/reusable-build-docs.yaml
    with:
      repository-owner: ${{ github.event.inputs.repository-owner || 'ansible' }}
      repository-name:  ${{ github.event.inputs.repository-name || 'ansible-documentation' }}
      repository-branch: ${{ github.event.inputs.repository-branch || 'devel' }}
      ansible-package-version: ${{ github.event.inputs.ansible-package-version || 'devel' }}
      generate-redirects: >-
        ${{ github.event_name == 'workflow_dispatch'
        && github.event.inputs.generate-redirects == 'true' }}
    secrets:
      DOCS_BOT_TOKEN: ${{ secrets.DOCS_BOT_TOKEN }}

  deploy-package-docs:
    name: 🚀 Deploy
    if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'true'
    needs: build-package-docs
    uses: ./.github/workflows/reusable-deploy-docs.yaml
    with:
      ansible-package-version: ${{ github.event.inputs.ansible-package-version }}
      deployment-environment: ${{ github.event.inputs.deployment-environment }}
      repository-owner: ${{ github.event.inputs.repository-owner }}
      repository-branch:  ${{ github.event.inputs.repository-branch }}
    secrets:
      DEPLOY_DOC_BUILD: ${{ secrets.DEPLOY_DOC_BUILD }}
