ci: simplify generate docs step to inline commands #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docs Automation | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "scripts/**" | |
| - ".github/workflows/docs.yml" | |
| workflow_dispatch: | |
| workflow_call: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| discover: | |
| name: Discover Repositories | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| repos: ${{ steps.repos.outputs.repos }} | |
| steps: | |
| - name: Discover source repos | |
| id: repos | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| ORG="${GITHUB_REPOSITORY_OWNER,,}" | |
| RUNNING_REPO="${GITHUB_REPOSITORY#*/}" | |
| RUNNING_REPO="${RUNNING_REPO,,}" | |
| # If triggered from a library repo, return only that repo | |
| if [ "$RUNNING_REPO" != "${ORG}.github.io" ]; then | |
| echo "repos=$(jq -cn --arg name "$RUNNING_REPO" '[{name: $name}]')" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # Discover all org repos that have a /types directory | |
| repos="$( | |
| gh api --paginate "/orgs/${ORG}/repos" \ | |
| --jq '[.[] | select(.archived == false and .disabled == false) | .name]' \ | |
| | jq -c '[.[] | select(ascii_downcase != "'"${ORG}.github.io"'")]' | |
| )" | |
| found="[]" | |
| while IFS= read -r name; do | |
| if gh api "/repos/${ORG}/${name}/contents/types" > /dev/null 2>&1; then | |
| found="$(jq -c --arg name "$name" '. + [{name: $name}]' <<< "$found")" | |
| fi | |
| done < <(jq -r '.[]' <<< "$repos") | |
| echo "repos=$(jq -c . <<< "$found")" >> "$GITHUB_OUTPUT" | |
| generate: | |
| name: Generate API Docs (${{ matrix.repo.name }}) | |
| needs: discover | |
| if: ${{ needs.discover.outputs.repos != '[]' }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| repo: ${{ fromJson(needs.discover.outputs.repos) }} | |
| steps: | |
| - name: Checkout docs repo | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ github.repository_owner }}/${{ github.repository_owner }}.github.io | |
| path: _docs | |
| - name: Checkout source repo | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ github.repository_owner }}/${{ matrix.repo.name }} | |
| path: _source | |
| fetch-depth: 1 | |
| - name: Setup LuaJIT | |
| uses: leafo/gh-actions-lua@v13 | |
| with: | |
| luaVersion: "luajit" | |
| - name: Generate docs | |
| run: | | |
| mkdir -p "_docs/docs/src/${{ matrix.repo.name }}/api" | |
| luajit _docs/scripts/generate-api-docs.lua "_source/types" "_docs/docs/src/${{ matrix.repo.name }}/api" | |
| - name: Format docs | |
| run: npx --yes prettier@latest --write "_docs/docs/src/${{ matrix.repo.name }}/api/*.md" --no-error-on-unmatched-pattern | |
| - name: Open docs PR | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| token: ${{ secrets.DOCS_TOKEN }} | |
| path: _docs | |
| commit-message: "docs(${{ matrix.repo.name }}): generate API docs" | |
| title: "docs(${{ matrix.repo.name }}): generate API docs" | |
| branch: "automation/generate-docs-${{ matrix.repo.name }}" | |
| add-paths: docs/src/${{ matrix.repo.name }}/api |