name: Release Tasks
on:
  release:
    types: [published]

jobs:
  docs:
    name: Publish Documentation
    runs-on: ubuntu-latest
    continue-on-error: false
    if: github.repository == 'fedora-modularity/libmodulemd'
    steps:
      - name: Checkout code repo
        uses: actions/checkout@v4

      - name: Checkout documentation repo
        uses: actions/checkout@v4
        with:
          repository: fedora-modularity/fedora-modularity.github.io
          ref: main
          path: fedora-modularity.github.io
          token: ${{ secrets.DOC_TOKEN }}

      - name: Get release version
        run: |
          echo "version=$(./get_version.sh)" >> $GITHUB_ENV

      - name: Generate documentation
        run: |
          ./.ci/ci-docs.sh $version

      - name: Commit documentation
        uses: EndBug/add-and-commit@v9
        with:
          new_branch: main
          token: ${{ secrets.DOC_TOKEN }}
          cwd: fedora-modularity.github.io
          author_name: Libmodulemd CI
          author_email: github-actions@github.com
          message: libmodulemd docs for ${{ env.version }}
          add: libmodulemd/${{ env.version }}
          commit: --signoff
          push: true
