Skip to content

Auto-update types from OpenAPI #91

Auto-update types from OpenAPI

Auto-update types from OpenAPI #91

Workflow file for this run

name: Auto-update types from OpenAPI
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch: # Allow manual trigger
jobs:
update-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Fetch latest OpenAPI schemas
run: npm run update-schemas
env:
GITHUB_TOKEN: ${{ secrets.AGENTIC_API_TOKEN || secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Check for changes
id: git-check
run: |
git diff --exit-code src/types/ outcome-agent-openapi.yaml partner-api.yaml platform-api.yaml || echo "changed=true" >> $GITHUB_OUTPUT
- name: Close existing auto-update PRs
if: steps.git-check.outputs.changed == 'true'
run: |
# Find and close all existing auto-update PRs
gh pr list --state open --json number,headRefName --jq '.[] | select(.headRefName | startswith("auto-update-openapi-")) | .number' | while read pr_number; do
echo "Closing PR #$pr_number"
gh pr close $pr_number --comment "Closing this PR as a new auto-update is available." --delete-branch
done
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Create Pull Request
if: steps.git-check.outputs.changed == 'true'
run: |
# Configure git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Create a new branch
BRANCH_NAME="auto-update-openapi-$(date +%s)"
git checkout -b $BRANCH_NAME
# Commit type changes
git add src/types/ outcome-agent-openapi.yaml partner-api.yaml platform-api.yaml
git commit -m "chore: update types from OpenAPI spec"
# Create changeset
cat << EOF > .changeset/auto-update-$(date +%s).md
---
"@scope3/agentic-client": patch
---
Update types from latest OpenAPI specification
EOF
git add .changeset/
git commit -m "chore: create changeset for type updates"
# Push branch
git push -u origin $BRANCH_NAME
# Create PR using GitHub CLI
gh pr create \
--title "chore: auto-update types from OpenAPI spec" \
--body "This PR was automatically generated by the auto-update workflow.
## Changes
- Updated types from latest OpenAPI specifications from [agentic-api repo](https://github.com/scope3data/agentic-api/tree/main/mintlify)
- Outcome Agent API (replacing Media Agent)
- Partner API
- Platform API
- Created changeset for patch version bump
The types will be published once this PR is merged and the release workflow runs." \
--base main \
--head $BRANCH_NAME
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}