Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions .github/workflows/generate-from-spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
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"
}
91 changes: 91 additions & 0 deletions .github/workflows/notify-node-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Notify Node SDK on Python Code Changes

on:
push:
paths:
- 'videodb/*.py'
- 'videodb/**/*.py'
- '!videodb/__about__.py'
- '!videodb/__init__.py'

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Check if spec also changed
id: check_spec
run: |
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

# Check if openapi.yaml changed in this push
if [[ -n "$BEFORE_SHA" ]]; then
SPEC_CHANGED=$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- openapi.yaml | wc -l)
else
SPEC_CHANGED=0
fi

if [[ "$SPEC_CHANGED" -gt 0 ]]; then
echo "spec_changed=true" >> $GITHUB_OUTPUT
echo "Spec also changed - skipping (generate-from-spec.yml will handle this)"
else
echo "spec_changed=false" >> $GITHUB_OUTPUT
echo "Only Python code changed - will notify Node SDK"
fi

- name: Get branch and changed files
if: steps.check_spec.outputs.spec_changed == 'false'
id: info
run: |
# Get the branch name
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT

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

# Get changed Python files (comma-separated for JSON)
if [[ -n "$BEFORE_SHA" ]]; then
FILES=$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- 'videodb/*.py' 'videodb/**/*.py' | grep -v '__about__\|__init__' | tr '\n' ',' | sed 's/,$//' || true)
else
FILES=""
fi

echo "changed_files=$FILES" >> $GITHUB_OUTPUT
echo "before_sha=$BEFORE_SHA" >> $GITHUB_OUTPUT
echo "after_sha=$AFTER_SHA" >> $GITHUB_OUTPUT

echo "Branch: $BRANCH_NAME"
echo "Changed files: $FILES"

- name: Trigger Node SDK Generation
if: steps.check_spec.outputs.spec_changed == 'false' && steps.info.outputs.changed_files != ''
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.info.outputs.branch_name }}",
"target_branch": "${{ steps.info.outputs.branch_name }}",
"trigger_type": "code_change",
"changed_files": "${{ steps.info.outputs.changed_files }}",
"before_sha": "${{ steps.info.outputs.before_sha }}",
"after_sha": "${{ steps.info.outputs.after_sha }}"
}
Loading