name: Generate Documentation
on:
    push:
        branches:
            - main
        tags:
            - "*"
    workflow_dispatch:

jobs:
    docs:
        name: "Generate Project Documentation"
        runs-on: ubuntu-latest
        steps:
        - name: Checkout
          uses: actions/checkout@v4
        - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
        - name: Setup PHP
          uses: shivammathur/setup-php@v2
          with:
            php-version: 8.1
        - name: Install Dependencies
          uses: nick-invision/retry@v3
          with:
            timeout_minutes: 10
            max_attempts: 3
            command: composer config repositories.sami vcs https://${{ secrets.GITHUB_TOKEN }}@github.com/jdpedrie/sami.git && composer require sami/sami:v4.2 && git reset --hard HEAD
        - name: Generate Documentation
          env:
            GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
          run: .github/actions/docs/entrypoint.sh
        - name: Deploy 🚀
          uses: JamesIves/github-pages-deploy-action@releases/v3
          with:
            ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
            BRANCH: gh-pages
            FOLDER: .docs
