|
| 1 | +name: Sync OpenAPI Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + # TODO: Remove pull_request trigger before merging |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + paths: |
| 9 | + - '.github/workflows/sync-openapi-artifacts.yml' |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: 'Version name (e.g., 2025-12-15.clover)' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: '2025-12-15.clover' |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + sync: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Fetch app installation token |
| 30 | + |
| 31 | + id: gh-api-token |
| 32 | + with: |
| 33 | + app_id: ${{ secrets.GH_APP_STRIPE_OPENAPI_APP_ID }} |
| 34 | + private_key: ${{ secrets.GH_APP_STRIPE_OPENAPI_PRIVATE_KEY }} |
| 35 | + |
| 36 | + - name: Get current version |
| 37 | + id: current-version |
| 38 | + run: echo "value=$(jq -r '.info.version' ./api/openapi-spec/spec3.cli.json)" >> $GITHUB_OUTPUT |
| 39 | + |
| 40 | + - name: Download GA CLI spec |
| 41 | + run: | |
| 42 | + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/ga/cli.json" \ |
| 43 | + -o ./api/openapi-spec/spec3.cli.json |
| 44 | +
|
| 45 | + - name: Download Preview CLI spec |
| 46 | + run: | |
| 47 | + curl -fsSL "https://b.stripecdn.com/api-artifacts/assets/${{ inputs.version }}/public-preview/cli.json" \ |
| 48 | + -o ./api/openapi-spec/spec3.cli.preview.json |
| 49 | +
|
| 50 | + - name: Check for changes |
| 51 | + id: changes |
| 52 | + run: | |
| 53 | + if git diff --quiet ./api/openapi-spec/; then |
| 54 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 55 | + echo "No changes detected, skipping PR creation" |
| 56 | + else |
| 57 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Set up Go |
| 61 | + if: steps.changes.outputs.has_changes == 'true' |
| 62 | + uses: actions/setup-go@v5 |
| 63 | + with: |
| 64 | + go-version: 1.24.1 |
| 65 | + |
| 66 | + - name: Run go generate |
| 67 | + if: steps.changes.outputs.has_changes == 'true' |
| 68 | + run: go generate ./... |
| 69 | + |
| 70 | + - name: Create pull request |
| 71 | + if: steps.changes.outputs.has_changes == 'true' |
| 72 | + uses: peter-evans/create-pull-request@v6 |
| 73 | + with: |
| 74 | + title: "OpenAPI Update for ${{ inputs.version }}" |
| 75 | + body: | |
| 76 | + Automated OpenAPI spec update. |
| 77 | +
|
| 78 | + - **Previous version:** `${{ steps.current-version.outputs.value }}` |
| 79 | + - **New version:** `${{ inputs.version }}` |
| 80 | + - **Initiated by:** @${{ github.actor }} |
| 81 | +
|
| 82 | + [→ Debug this workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 83 | + branch: update-openapi |
| 84 | + token: ${{ steps.gh-api-token.outputs.token }} |
| 85 | + delete-branch: true |
| 86 | + commit-message: "Update OpenAPI for ${{ inputs.version }}" |
| 87 | + committer: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>" |
| 88 | + author: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>" |
0 commit comments