jobs: # skip-all

  # This is ci/actions-templates/test-docs-templates.yaml
  # Do not edit this file in .github/workflows
  #
  # Builds docs for both stable and main branches.
  # stable is placed in the root of the gh-pages branch, while main is placed at /devel
  doc: # job-name
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: Install mdbook
        uses: taiki-e/install-action@v2
        env:
          # renovate: datasource=crate depName=mdbook
          MDBOOK_VERSION: "0.4.43"
        with:
          tool: mdbook@${{ env.MDBOOK_VERSION }}
      - name: Build user-guide (stable)
        if: ${{ !contains('["pull_request", "merge_group"]', github.event_name) }}
        run: |
          git checkout stable
          # Support both old and new directory structure during the transition
          cd doc/user-guide || cd doc
          mdbook build
          mv book ${{ runner.temp }}
      - name: Build user-guide (main)
        run: |
          git checkout main
          cd doc/user-guide
          mdbook build
          mkdir -p ${{ runner.temp }}/book
          mv book ${{ runner.temp }}/book/devel
      - name: Build dev-guide (main)
        run: |
          git checkout main
          cd doc/dev-guide
          mdbook build
          mkdir -p ${{ runner.temp }}/book
          mv book ${{ runner.temp }}/book/dev-guide
      - name: Deploy to GitHub
        if: ${{ !contains('["pull_request", "merge_group"]', github.event_name) }}
        run: |
          cd ${{ runner.temp }}/book
          git config --global init.defaultBranch main
          git init
          git config user.name "Deploy from CI"
          git config user.email ""
          git add . .nojekyll
          git commit -m "Deploy $GITHUB_REF $GITHUB_SHA to gh-pages"
          git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
          git push --force --set-upstream origin main:gh-pages
