1+ name : Update OpenAPI Spec
2+
3+ on :
4+ # Run once daily at 00:00 UTC
5+ schedule :
6+ - cron : ' 0 0 * * *'
7+
8+ # Run when PRs are opened or synchronized
9+ pull_request :
10+ types : [opened, synchronize]
11+ paths :
12+ - ' openapi-spec.yaml'
13+ - ' .github/workflows/update-openapi-spec.yml'
14+
15+ # Allow manual triggering
16+ workflow_dispatch :
17+
18+ # Add a repository_dispatch event for external triggers if needed
19+ repository_dispatch :
20+ types : [openapi_spec_updated]
21+
22+ jobs :
23+ update-openapi-spec :
24+ name : Update OpenAPI Spec
25+ # Don't run this job on PR events if the PR is from the update-openapi-spec branch (to avoid loops)
26+ if : github.event_name != 'pull_request' || github.head_ref != 'update-openapi-spec'
27+ runs-on : ubuntu-latest
28+ permissions :
29+ contents : write
30+ pull-requests : write
31+
32+ steps :
33+ - name : Checkout code
34+ uses : actions/checkout@v3
35+ with :
36+ # For PRs, check out the head of the PR
37+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}
38+
39+ - name : Set up Go
40+ uses : actions/setup-go@v4
41+ with :
42+ go-version : ' 1.24.3'
43+ check-latest : true
44+
45+ - name : Install mage
46+ run : go install github.com/magefile/mage@latest
47+
48+ - name : Update OpenAPI spec
49+ id : update-spec
50+ run : |
51+ mage openapi:update
52+ # Check if there are changes
53+ if [[ -n "$(git status --porcelain openapi-spec.yaml)" ]]; then
54+ echo "changes=true" >> $GITHUB_OUTPUT
55+ else
56+ echo "changes=false" >> $GITHUB_OUTPUT
57+ fi
58+
59+ # When not in a PR, create a new PR with changes
60+ - name : Create Pull Request
61+ if : steps.update-spec.outputs.changes == 'true' && github.event_name != 'pull_request'
62+ uses : peter-evans/create-pull-request@v5
63+ with :
64+ commit-message : ' chore: update OpenAPI spec'
65+ title : ' chore: update OpenAPI spec'
66+ body : |
67+ This PR updates the OpenAPI spec to the latest version.
68+
69+ This is an automated PR created by the GitHub Actions workflow.
70+ branch : update-openapi-spec
71+ base : main
72+ labels : dependencies,automated
73+
74+ # When in a PR context, update the PR with the latest spec
75+ - name : Commit changes to PR
76+ if : steps.update-spec.outputs.changes == 'true' && github.event_name == 'pull_request'
77+ run : |
78+ git config --global user.name 'GitHub Actions'
79+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
80+ git add openapi-spec.yaml
81+ git commit -m "chore: update OpenAPI spec to latest version"
82+ git push
83+
84+ # Also add a comment to the PR about the update
85+ - name : Comment on PR
86+ if : steps.update-spec.outputs.changes == 'true' && github.event_name == 'pull_request'
87+ uses : actions/github-script@v6
88+ with :
89+ script : |
90+ github.rest.issues.createComment({
91+ issue_number: context.issue.number,
92+ owner: context.repo.owner,
93+ repo: context.repo.repo,
94+ body: '✅ The OpenAPI spec in this PR has been automatically updated to the latest version.'
95+ })
0 commit comments