Simplify/update GitHub workflow for nightly openapi spec updates (#2297)
Co-authored-by: Suchintan <suchintan@users.noreply.github.com>
This commit is contained in:
74
.github/workflows/update-openapi.yml
vendored
74
.github/workflows/update-openapi.yml
vendored
@@ -12,67 +12,13 @@ jobs:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Fetch OpenAPI specification
|
||||
run: |
|
||||
npm install -g fern-api
|
||||
fern api update
|
||||
|
||||
- name: Check for changes
|
||||
id: check_changes
|
||||
run: |
|
||||
if git diff --quiet ./fern/apis/api/openapi.json; then
|
||||
echo "No changes detected in OpenAPI specification"
|
||||
echo "changes_detected=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Changes detected in OpenAPI specification"
|
||||
echo "changes_detected=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Setup GitHub CLI
|
||||
id: setup_cli
|
||||
if: steps.check_changes.outputs.changes_detected == 'true'
|
||||
run: |
|
||||
# Create timestamp for unique branch name
|
||||
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
||||
BRANCH_NAME="update-openapi-spec-${TIMESTAMP}"
|
||||
|
||||
# Setup branch for changes
|
||||
git config --global user.name "GitHub Actions"
|
||||
git config --global user.email "actions@github.com"
|
||||
|
||||
# Create new branch with timestamp
|
||||
git checkout -b $BRANCH_NAME
|
||||
git add ./fern/apis/api/openapi.json
|
||||
git commit -m "chore: update OpenAPI specification"
|
||||
git push -u origin $BRANCH_NAME
|
||||
|
||||
# Store branch name for PR creation
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Pull Request with GitHub CLI
|
||||
if: steps.check_changes.outputs.changes_detected == 'true'
|
||||
run: |
|
||||
gh pr create \
|
||||
--base main \
|
||||
--head ${{ steps.setup_cli.outputs.branch_name }} \
|
||||
--title "Update OpenAPI Specification" \
|
||||
--body "This PR updates the OpenAPI specification from the official Vapi API endpoint.
|
||||
|
||||
- Auto-generated by the Update OpenAPI Specification workflow
|
||||
- Source: https://api.vapi.ai/api-json
|
||||
- Generated at: $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: PR Result
|
||||
if: steps.check_changes.outputs.changes_detected == 'true'
|
||||
run: |
|
||||
echo "Pull request created successfully!"
|
||||
|
||||
- name: No Changes Result
|
||||
if: steps.check_changes.outputs.changes_detected == 'false'
|
||||
run: |
|
||||
echo "No changes detected in OpenAPI specification. No PR created."
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Update OpenAPI Spec
|
||||
uses: fern-api/sync-openapi@v2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: 'update-openapi-spec'
|
||||
update_from_source: true
|
||||
add_timestamp: true
|
||||
|
||||
Reference in New Issue
Block a user