Add github action to sync api docs to the user docs site #14
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 user-docs -- --depth=1 --quiet --branch chore/docs-action | |
cd ./user-docs | |
OUTPUT=$(cd tools/api-docs-generator && 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 checkout -b docs/automatic-api-docs-update | |
git push --force origin docs/automatic-api-docs-update | |
if [[ ! $(gh pr view docs/automatic-api-docs-update 2>&1 | grep -q "no open pull requests";) ]]; then | |
echo "Creating PR" | |
echo "This PR was automatically generated by the API docs synchronization action. Please review the changes and merge if they look good. \n \`$OUTPUT\`" > /tmp/pr_body | |
gh pr create --title="Generate API docs from spec" --body="$(cat /tmp/pr_body)" --head docs/automatic-api-docs-update | |
fi | |
echo "PR exists, pushed changes to it." | |
else | |
echo "No documentation changes detected, exiting." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |