-
Notifications
You must be signed in to change notification settings - Fork 190
39 lines (37 loc) · 1.61 KB
/
sync-api-docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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"
PR_BODY=$(echo "This PR was automatically generated by the API docs synchronization action. Please review the changes and merge if they look good. \n ```$OUTPUT```")
gh pr create --title="Generate API docs from spec" --body="${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 }}