name: generate
on:
  workflow_dispatch: {}
  schedule:
    - cron: "0 8 * * *"
permissions: read-all
jobs:
  docs:
    permissions:
      contents: read
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
        with:
          go-version-file: go.mod
          cache: true
      - uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0
        with:
          version: 3.x
          repo-token: ${{ secrets.GITHUB_TOKEN }}
      - name: "install tools"
        run: |
          mkdir -p ~/bin
          wget -O ~/bin/gofumpt https://github.com/mvdan/gofumpt/releases/download/v0.9.1/gofumpt_v0.9.1_linux_amd64
          chmod +x ~/bin/gofumpt
          wget -O jv.tar.gz https://github.com/santhosh-tekuri/jsonschema/releases/download/v6.0.2/jv-v6.0.2-linux-amd64.tar.gz
          tar xzvf jv.tar.gz -C ~/bin jv
          chmod +x ~/bin/jv
          rm jv.tar.gz
          echo "$HOME/bin" >> $GITHUB_PATH
      - run: task docs:releases
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - run: task docs:generate
      - run: task docs:sponsors
        env:
          GITHUB_TOKEN: ${{ secrets.SPONSORS_TOKEN }}
      - run: task schema:generate
      - run: task schema:validate
      - run: task nix:licenses:generate
      - run: "git pull"
      - uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
        with:
          commit_message: "chore: auto-update generated files"
          branch: main
          commit_user_name: actions-user
          commit_user_email: actions@github.com
          commit_author: actions-user <actions@github.com>
  notify:
    runs-on: ubuntu-latest
    needs:
      - docs
    if: ${{ failure() }}
    steps:
      - name: Notify
        uses: nobrayner/discord-webhook@1766a33bf571acdcc0678f00da4fb83aad01ebc7 # v1
        with:
          github-token: ${{ secrets.github_token }}
          title: "generate job failed"
          description: "this may cause goreleaser-action to fail, please check: https://github.com/goreleaser/goreleaser/actions/workflows/generate.yml"
          discord-webhook: ${{ secrets.NIGHTLY_DISCORD_WEBHOOK }}
          username: GoReleaser
          avatar-url: https://avatars.githubusercontent.com/u/24697112?v=4
          include-details: false
