-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (177 loc) · 8.63 KB
/
Copy pathupdate-openapi-spec.yml
File metadata and controls
206 lines (177 loc) · 8.63 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Update OpenAPI Specification
on:
schedule:
# Run daily at 2 AM UTC to check for updates
- cron: "0 2 * * *"
workflow_dispatch:
# Allow manual trigger
permissions:
contents: write
pull-requests: write
jobs:
update-openapi-spec:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
- name: Install dependencies
run: uv sync
- name: Check current OpenAPI spec info
id: current-spec
run: |
if [ -f "resources/openapi-spec.json" ]; then
CURRENT_VERSION=$(jq -r '.info.version // "unknown"' resources/openapi-spec.json)
CURRENT_PATHS=$(jq '.paths | length' resources/openapi-spec.json)
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "current-paths=$CURRENT_PATHS" >> $GITHUB_OUTPUT
echo "Current spec version: $CURRENT_VERSION, paths: $CURRENT_PATHS"
else
echo "current-version=none" >> $GITHUB_OUTPUT
echo "current-paths=0" >> $GITHUB_OUTPUT
echo "No existing OpenAPI spec found"
fi
- name: Update OpenAPI specification
id: update-spec
run: |
echo "Updating OpenAPI specification..."
uv run python scripts/update_openapi_spec.py
# Check if OpenAPI spec was changed
if git diff --quiet resources/openapi-spec.json; then
echo "has-changes=false" >> $GITHUB_OUTPUT
echo "No changes detected in OpenAPI specification"
else
echo "has-changes=true" >> $GITHUB_OUTPUT
echo "Changes detected in OpenAPI specification"
# Get new spec info
NEW_VERSION=$(jq -r '.info.version // "unknown"' resources/openapi-spec.json)
NEW_PATHS=$(jq '.paths | length' resources/openapi-spec.json)
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "new-paths=$NEW_PATHS" >> $GITHUB_OUTPUT
echo "New spec version: $NEW_VERSION, paths: $NEW_PATHS"
# Compute content hash for deduplication
SPEC_HASH=$(sha256sum resources/openapi-spec.json | cut -d' ' -f1)
echo "spec-sha256=$SPEC_HASH" >> $GITHUB_OUTPUT
echo "Spec content hash: $SPEC_HASH"
fi
- name: Determine branch name
id: branch-info
if: steps.update-spec.outputs.has-changes == 'true'
run: |
SPEC_HASH="${{ steps.update-spec.outputs.spec-sha256 }}"
if [ -z "$SPEC_HASH" ] || [ "$SPEC_HASH" = "unknown" ]; then
SPEC_HASH=$(sha256sum resources/openapi-spec.json | cut -d' ' -f1)
fi
BRANCH="update-openapi-spec-${SPEC_HASH:0:12}"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Using branch $BRANCH for this update"
- name: Check for existing PR
id: existing-pr
if: steps.update-spec.outputs.has-changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="${{ steps.branch-info.outputs.branch }}"
if [ -z "$BRANCH" ]; then
echo "exists=false" >> $GITHUB_OUTPUT
exit 0
fi
PR_COUNT=$(gh pr list --state open --head "$BRANCH" --repo "$GITHUB_REPOSITORY" --json number --jq 'length')
if [ "$PR_COUNT" -gt 0 ]; then
echo "An open PR already exists for $BRANCH (count: $PR_COUNT)"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Update search database
if: steps.update-spec.outputs.has-changes == 'true'
run: |
echo "Updating search database with new OpenAPI specification..."
uv run python scripts/create_search_database.py
# Check if database was created/updated
if [ -f "resources/authlete_apis.duckdb" ]; then
DB_SIZE=$(wc -c < "resources/authlete_apis.duckdb")
echo "✅ Search database updated successfully (size: $DB_SIZE bytes)"
# Get API count from database
API_COUNT=$(uv run python -c "import duckdb; \
conn = duckdb.connect('resources/authlete_apis.duckdb'); \
result = conn.execute('SELECT COUNT(*) FROM api_endpoints').fetchone(); \
print(result[0]); \
conn.close()" 2>/dev/null || echo "0")
echo "📊 APIs indexed in search database: $API_COUNT"
else
echo "❌ Failed to create search database"
exit 1
fi
- name: Create Pull Request
if: steps.update-spec.outputs.has-changes == 'true' && steps.existing-pr.outputs.exists != 'true'
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
chore: update OpenAPI specification and search database
- Updated from Authlete docs (https://docs.authlete.com/en/shared/3.0.0/spec)
- Version: ${{ steps.current-spec.outputs.current-version }} → ${{ steps.update-spec.outputs.new-version }}
- Paths: ${{ steps.current-spec.outputs.current-paths }} → ${{ steps.update-spec.outputs.new-paths }}
- Regenerated DuckDB search database for API search functionality
- Content hash: ${{ steps.update-spec.outputs.spec-sha256 }}
Auto-generated by update-openapi-spec workflow
branch: ${{ steps.branch-info.outputs.branch }}
delete-branch: true
title: "chore: update OpenAPI specification to v${{ steps.update-spec.outputs.new-version }}"
body: |
## OpenAPI Specification Update
This PR updates the OpenAPI specification from the latest Authlete documentation.
**Changes:**
- **Version:** `${{ steps.current-spec.outputs.current-version }}` → \
`${{ steps.update-spec.outputs.new-version }}`
- **API Endpoints:** `${{ steps.current-spec.outputs.current-paths }}` → \
`${{ steps.update-spec.outputs.new-paths }}`
- **Source:** https://raw.githubusercontent.com/authlete/openapi/refs/heads/main/spec_next.yaml
**Files Updated:**
- `resources/openapi-spec.json` - OpenAPI specification
- `resources/authlete_apis.duckdb` - Search database for API search functionality
**Verification:**
- [ ] OpenAPI spec is valid JSON
- [ ] Spec contains expected Authlete API endpoints
- [ ] Search database was successfully generated
- [ ] API search functionality works with updated database
- [ ] No breaking changes in existing endpoint definitions
---
🤖 This PR was automatically created by the `update-openapi-spec` GitHub Action.
**Review Guidelines:**
1. Verify the changes are legitimate updates from Authlete
2. Check that no critical API definitions have been removed
3. Ensure the new version is correctly parsed
4. Consider updating any dependent code or documentation
labels: |
dependencies
automation
documentation
reviewers: |
watahani
- name: Summary
run: |
if [ "${{ steps.update-spec.outputs.has-changes }}" = "true" ]; then
if [ "${{ steps.existing-pr.outputs.exists }}" = "true" ]; then
echo "ℹ️ OpenAPI spec update matches an existing open PR."
echo "🔁 Reusing branch ${{ steps.branch-info.outputs.branch }}"
else
echo "✅ OpenAPI spec and search database updated successfully"
echo "📊 Version: ${{ steps.current-spec.outputs.current-version }} → \
${{ steps.update-spec.outputs.new-version }}"
echo "🔧 Paths: ${{ steps.current-spec.outputs.current-paths }} → \
${{ steps.update-spec.outputs.new-paths }}"
echo "🗃️ Search database regenerated for Python API search MCP server"
echo "📋 PR created with both OpenAPI spec and DuckDB database updates"
fi
else
echo "ℹ️ OpenAPI spec is already up to date - no database update needed"
fi