Skip to content

Generate documentation #326

Generate documentation

Generate documentation #326

name: Generate documentation
on:
schedule:
- cron: '0 0 * * *' # Launch this workflow everyday at midnight
jobs:
generate-docs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.11.1]
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies with yarn
run: yarn install
- name: Build documentation and check for errors
id: build
run: |
yarn build:remote | tee build.log
if grep -qi "error" build.log; then
echo "error=true" >> "$GITHUB_OUTPUT"
else
echo "error=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check for changes
id: changes
if: steps.build.outputs.error == 'false'
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git diff --quiet && git diff --staged --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"
shell: bash
- name: Commit and push if there were changes
if: steps.changes.outputs.changed == 'true'
run: |
git commit -m "Add newly generated documentation"
git push -f origin HEAD:actions-generate-docs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR with updated documentation
if: steps.changes.outputs.changed == 'true'
run: |
PR_EXISTS=$(gh pr view actions-generate-docs --json state -q '.state' || echo "no")
if [ "$PR_EXISTS" = "no" ] || [ "$PR_EXISTS" != "OPEN" ]; then
gh pr create --base main --title "chore(docs): generate documentation" \
--body "This is an auto-generated PR for documentation updates made by GitHub Actions." \
--head actions-generate-docs
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}