diff --git a/.github/workflows/sync-openapi-artifacts.yml b/.github/workflows/sync-openapi-artifacts.yml new file mode 100644 index 000000000..c3fcee385 --- /dev/null +++ b/.github/workflows/sync-openapi-artifacts.yml @@ -0,0 +1,75 @@ +name: Sync OpenAPI Artifacts + +on: + workflow_dispatch: + inputs: + version: + description: 'Version name (e.g., 2025-12-15.clover)' + required: false + type: string + default: '2025-12-15.clover' + +permissions: + contents: write + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Fetch app installation token + uses: tibdex/github-app-token@v1.5.2 + id: gh-api-token + with: + app_id: ${{ secrets.GH_APP_STRIPE_OPENAPI_APP_ID }} + private_key: ${{ secrets.GH_APP_STRIPE_OPENAPI_PRIVATE_KEY }} + + - name: Get current version + id: current-version + run: echo "value=$(jq -r '.info.version' ./latest/openapi.json 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT + + - name: Create directories + run: | + mkdir -p ./latest + mkdir -p ./preview + + - name: Download latest (GA) specs + run: | + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/ga/public.json" \ + -o ./latest/openapi.json + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/ga/public.yaml" \ + -o ./latest/openapi.yaml + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/ga/sdk.json" \ + -o ./latest/openapi.sdk.json + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/ga/sdk.yaml" \ + -o ./latest/openapi.sdk.yaml + + - name: Download preview specs + run: | + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/public-preview/sdk.json" \ + -o ./preview/openapi.sdk.json + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/public-preview/sdk.yaml" \ + -o ./preview/openapi.sdk.yaml + + - name: Check for changes + id: changes + run: | + if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then + echo "has_changes=false" >> $GITHUB_OUTPUT + echo "No changes detected, skipping PR creation" + else + echo "has_changes=true" >> $GITHUB_OUTPUT + fi + + - name: Commit and push + if: steps.changes.outputs.has_changes == 'true' + run: | + git config user.name "Stripe OpenAPI" + git config user.email "105521251+stripe-openapi[bot]@users.noreply.github.com" + git add -A + git commit -m "Update OpenAPI for ${{ inputs.version }}" + git push + env: + GITHUB_TOKEN: ${{ steps.gh-api-token.outputs.token }}