Merge pull request #59 from video-db/release-0-4-0 #3
This file contains hidden or 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: Generate SDK from OpenAPI Spec | |
| on: | |
| push: | |
| paths: | |
| - 'openapi.yaml' | |
| # Manual trigger for testing | |
| workflow_dispatch: | |
| jobs: | |
| generate: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout Python SDK | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get branch and diff info | |
| id: info | |
| run: | | |
| # Get the branch name this workflow is running on | |
| BRANCH_NAME="${GITHUB_REF#refs/heads/}" | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| # Get commit SHAs for diff | |
| BEFORE_SHA="${{ github.event.before }}" | |
| AFTER_SHA="${{ github.sha }}" | |
| # Handle new branch case | |
| if [[ "$BEFORE_SHA" == "0000000000000000000000000000000000000000" ]]; then | |
| BEFORE_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "") | |
| fi | |
| echo "before_sha=$BEFORE_SHA" >> $GITHUB_OUTPUT | |
| echo "after_sha=$AFTER_SHA" >> $GITHUB_OUTPUT | |
| # Generate diff for the spec file | |
| if [[ -n "$BEFORE_SHA" ]]; then | |
| git diff "$BEFORE_SHA" "$AFTER_SHA" -- openapi.yaml > spec.diff || touch spec.diff | |
| else | |
| touch spec.diff | |
| fi | |
| echo "Diff size: $(wc -l < spec.diff) lines" | |
| echo "Running on branch: $BRANCH_NAME" | |
| - name: Fetch prompt and build context | |
| run: | | |
| # Fetch static prompt from agent-toolkit | |
| curl -sL https://raw.githubusercontent.com/video-db/agent-toolkit/main/context/prompts/spec-to-python-sdk.txt > static_prompt.txt | |
| # Build full prompt with dynamic content | |
| cat > codex_prompt.md << 'PROMPT_EOF' | |
| ## Git Diff of OpenAPI Spec Changes | |
| The following diff shows what changed in the API specification: | |
| ```diff | |
| PROMPT_EOF | |
| cat spec.diff >> codex_prompt.md | |
| cat >> codex_prompt.md << 'PROMPT_EOF' | |
| ``` | |
| ## Current OpenAPI Spec | |
| If you need to reference the full spec for context, it's available at: openapi.yaml | |
| --- | |
| PROMPT_EOF | |
| # Append static instructions | |
| cat static_prompt.txt >> codex_prompt.md | |
| echo "Prompt built successfully" | |
| - name: Run Codex | |
| uses: openai/codex-action@v1 | |
| with: | |
| openai-api-key: ${{ secrets.OPENAI_API_KEY }} | |
| model: o4-mini | |
| sandbox: workspace-write | |
| prompt-file: codex_prompt.md | |
| - name: Check for changes and create PR | |
| id: create_pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Check if there are changes | |
| if git diff --quiet && git diff --staged --quiet; then | |
| echo "No changes generated by Codex" | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| # Clean up temporary files - DO NOT commit these | |
| rm -f spec.diff static_prompt.txt codex_prompt.md | |
| # Get the base branch name | |
| BASE_BRANCH="${{ steps.info.outputs.branch_name }}" | |
| # Create work branch from the current branch | |
| WORK_BRANCH="auto/spec-sync-$(date +%Y%m%d-%H%M%S)" | |
| git checkout -b "$WORK_BRANCH" | |
| git add -A | |
| # Commit | |
| git commit -m "feat: sync with OpenAPI spec changes | |
| Source branch: ${BASE_BRANCH} | |
| Generated by OpenAI Codex" | |
| # Push | |
| git push origin "$WORK_BRANCH" | |
| echo "work_branch=$WORK_BRANCH" >> $GITHUB_OUTPUT | |
| echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT | |
| # Create PR targeting the original branch | |
| gh pr create \ | |
| --base "$BASE_BRANCH" \ | |
| --title "feat: sync with OpenAPI spec" \ | |
| --body "## Summary | |
| Automated SDK update based on OpenAPI spec changes. | |
| **Base branch**: \`$BASE_BRANCH\` | |
| ## Review Checklist | |
| - [ ] Generated code follows SDK conventions | |
| - [ ] Method signatures are correct | |
| - [ ] No breaking changes introduced | |
| - [ ] Tests pass locally | |
| --- | |
| *Generated by [OpenAI Codex](https://github.com/openai/codex)*" | |
| - name: Trigger Node SDK Generation | |
| if: steps.create_pr.outputs.has_changes == 'true' | |
| uses: peter-evans/repository-dispatch@v3 | |
| with: | |
| token: ${{ secrets.SDK_SYNC_PAT }} | |
| repository: ${{ github.repository_owner }}/videodb-node | |
| event-type: python-updated | |
| client-payload: | | |
| { | |
| "source_branch": "${{ steps.create_pr.outputs.work_branch }}", | |
| "target_branch": "${{ steps.create_pr.outputs.base_branch }}", | |
| "trigger_type": "spec_change" | |
| } |