Add github action to sync api docs to the user docs site #4
This file contains 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: Synchronize API Docs | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 * * * 1-5' # Mon-Fri every hour | |
push: | |
branches: [chore/docs-action] | |
jobs: | |
build: | |
name: synchronize-api-docs | |
runs-on: ubuntu-latest | |
steps: | |
- run: | | |
gh auth setup-git | |
git config --global user.email "[email protected]" | |
git config --global user.name "$GITHUB_ACTOR" | |
gh repo clone snyk/user-docs docs -- --depth=1 --quiet | |
cd ./user-docs | |
OUTPUT=$(cd tools/api-docs && go mod tidy && go run . config.yml ../../) | |
if [[ $(git status --porcelain) ]]; then | |
echo "Documentation changes detected" | |
git --no-pager diff --name-only | |
git add . | |
git commit -m "docs: synchronizing api spec with user-docs" | |
git push --force --set-upstream origin docs/automatic-gitbook-update | |
if [[ ! $(gh pr view docs/automatic-gitbook-update 2>&1 | grep -q "no open pull requests";) ]]; then | |
echo "Creating PR" | |
gh pr create --title="Generate API docs from spec" --body="Automatic PR controlled by GitHub Action\n$OUTPUT" --head docs/automatic-gitbook-update | |
fi | |
echo "PR exists, pushed changes to it." | |
else | |
echo "No documentation changes detected, exiting." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |