name: "Validate flake & check documentation"
on:
  pull_request:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - docs/**
jobs:
  flake-docs-check:
    name: Validate Flake Documentation
    runs-on: ubuntu-latest
    strategy:
      matrix:
        package:
          - docs
          - docs-html
          - docs-manpages
          - docs-json
    steps:
      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@main
      - uses: DeterminateSystems/magic-nix-cache-action@main

      - name: Checkout
        uses: actions/checkout@v4

      - name: Set default git branch (to reduce log spam)
        run: git config --global init.defaultBranch main

      - name: Build documentation packages
        run: nix build .#${{ matrix.package }} --print-build-logs

      - name: Get current date
        id: get-date
        # output format: 2023-12-22-120000
        run: echo "date=$(date +'%Y-%m-%d-%H%M%S')" >> ${GITHUB_OUTPUT}

      - name: Upload doc artifacts
        uses: actions/upload-artifact@v4
        with:
          name: "${{ matrix.package }}"
          path: result/share/doc/nvf
  flake-docs-linkcheck:
    name: Validate hyperlinks in documentation sources
    runs-on: ubuntu-latest
    steps:
      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@main
      - uses: DeterminateSystems/magic-nix-cache-action@main

      - name: Checkout
        uses: actions/checkout@v4

      - name: Build documentation packages
        run: nix build .#docs-linkcheck -Lv