Skip to content

Commit c04f7d6

Browse files
authored
Add sync-artifacts workflow for remote OpenAPI updates (#1413)
Adds GH workflow that fetches OpenAPI artifacts from Stripe's CDN, runs codegen, and creates a PR with the changes. Example PR: #1414
1 parent 97206ee commit c04f7d6

File tree

1 file changed

+83
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)