name: Audit

on:
  push:
  pull_request:

jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
          ref: ${{github.event.pull_request.head.ref}}
          repository: ${{github.event.pull_request.head.repo.full_name}}

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: latest
          extended: true

      - name: Build
        run: |
          HUGO_MINIFY_TDEWOLFF_HTML_KEEPCOMMENTS=true HUGO_ENABLEMISSINGTRANSLATIONPLACEHOLDERS=true hugo --buildDrafts --printI18nWarnings --printPathWarnings

      # For the following steps, see
      # https://discourse.gohugo.io/t/audit-your-published-site-for-problems/35184

      - name: Audit - raw HTML
        if: always()
        run: |
          ! grep -inorE "<\!-- raw HTML omitted -->" public/

      - name: Audit - ZgotmplZ (unsafe URL content)
        if: always()
        run: |
          ! grep -inorE "ZgotmplZ" public/

      #- name: Audit - missing translations
      #  if: always()
      #  run: |
      #    ! grep -inorE "\[i18n\]" public/

      - name: Audit - nil values in printf
        if: always()
        run: |
          ! grep -inorE "\(<nil>\)" public/

      - name: Audit - nil values in printf without safeHTML
        if: always()
        run: |
          ! grep -inorE "(&lt;nil&gt;)" public/

      - name: Audit - HAHAHUGO
        if: always()
        run: |
          ! grep -inorE "hahahugo" public/
