Generate Docs #4
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: Generate Docs | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check for relevant changes | |
| id: changes | |
| run: | | |
| CHANGED=$(git diff --name-only HEAD~1 HEAD | grep -E '^(lib/|docs/playground/)' | grep -v 'docs/playground/public/' | grep -v 'docs/reference/' || true) | |
| if [ -z "$CHANGED" ]; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| echo "No relevant changes, skipping generation" | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| echo "Changed files:" | |
| echo "$CHANGED" | |
| fi | |
| - uses: ruby/setup-ruby@v1 | |
| if: steps.changes.outputs.skip != 'true' | |
| with: | |
| ruby-version: '3.2' | |
| bundler-cache: true | |
| working-directory: docs/playground | |
| - name: Cache YARD | |
| if: steps.changes.outputs.skip != 'true' | |
| uses: actions/cache@v4 | |
| with: | |
| path: .yardoc | |
| key: yard-${{ hashFiles('lib/**/*.rb') }} | |
| - name: Generate docs | |
| if: steps.changes.outputs.skip != 'true' | |
| run: | | |
| cd docs/playground | |
| bundle install | |
| RAILS_ENV=test bundle exec rake db:reset | |
| bundle exec rake apiwork:docs:reference | |
| bundle exec rake docs:generate | |
| - name: Commit and push | |
| if: steps.changes.outputs.skip != 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add docs/reference/ docs/playground/public/ | |
| git diff --staged --quiet || git commit -m "chore: regenerate docs" | |
| git push |