-
Notifications
You must be signed in to change notification settings - Fork 124
160 lines (138 loc) · 5.74 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Publish
on:
workflow_dispatch: {}
release:
types:
- created
push:
branches:
- master
jobs:
# Trigger generated code updates only after a release was created
# Generated code pipeline relies on latest release to pick up the spec
publish-latest-release:
if: >-
(github.event_name == 'workflow_dispatch') || (github.event_name == 'release')
name: Trigger generated code update
runs-on: ubuntu-latest
steps:
- name: Checkout openapi
uses: actions/checkout@v2
- 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: Trigger generated code update
run: |
curl --fail-with-body \
-XPOST \
-H 'Authorization: token ${{ steps.gh-api-token.outputs.token }}' \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/stripe/sdk-codegen/actions/workflows/codegen.yml/dispatches \
--data '{"ref":"master"}'
- uses: ./actions/notify-slack
if: always()
with:
action: 'Publishing the OpenAPI spec to other repositories'
send_on_success: false
bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
# stripe-mock and stripe-cli are updated with latest versions of files straight from master
publish-latest-master:
if: >-
(github.event_name == 'workflow_dispatch') || (github.event_name == 'push')
name: Publish spec to stripe-cli & stripe-mock
runs-on: ubuntu-latest
steps:
- name: Checkout openapi
uses: actions/checkout@v2
- 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 }}
# Fetch repositories to modify
- uses: actions/checkout@v3
with:
token: ${{ steps.gh-api-token.outputs.token }}
repository: stripe/stripe-mock
path: stripe-mock
- run: |
rm -f ./stripe-mock/embedded/openapi/spec3.json
rm -f ./stripe-mock/embedded/openapi/spec3.beta.sdk.json
rm -f ./stripe-mock/embedded/openapi/fixtures3.json
rm -f ./stripe-mock/embedded/openapi/fixtures3.beta.json
cp openapi/spec3.json stripe-mock/embedded/openapi/spec3.json
cp openapi/spec3.beta.sdk.json stripe-mock/embedded/openapi/spec3.beta.sdk.json
cp openapi/fixtures3.json stripe-mock/embedded/openapi/fixtures3.json
cp openapi/fixtures3.beta.json stripe-mock/embedded/openapi/fixtures3.beta.json
- name: Create Pull Request on stripe-mock
id: cpr
uses: peter-evans/create-pull-request@v6
with:
path: stripe-mock
title: OpenAPI Update
body: |
Automated OpenAPI update for https://github.com/stripe/openapi/commit/${{ github.sha }}
[→ Debug this workflow](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})
branch: update-openapi
token: ${{ steps.gh-api-token.outputs.token }}
delete-branch: true
commit-message: Update OpenAPI for ${{ github.sha }}
committer: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>"
author: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>"
- uses: ./actions/enable-auto-merge
name: Enable auto-merge for stripe-mock
if: ${{ steps.cpr.outputs.pull-request-url != '' }}
with:
pr_url: "${{ steps.cpr.outputs.pull-request-url }}"
github_token: ${{ steps.gh-api-token.outputs.token }}
repo: stripe/stripe-mock
- uses: ./actions/approve
name: Approve stripe-mock PR
if: ${{ steps.cpr.outputs.pull-request-url != '' }}
with:
pr_url_or_branch: ${{ steps.cpr.outputs.pull-request-url }}
repo: stripe/stripe-mock
github_app_id: ${{ secrets.GH_APP_STRIPE_OPENAPI_APPROVER_APP_ID }}
github_app_private_key: ${{ secrets.GH_APP_STRIPE_OPENAPI_APPROVER_PRIVATE_KEY }}
# Set up GO
- uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Checkout stripe-cli
uses: actions/checkout@v3
with:
token: ${{ steps.gh-api-token.outputs.token }}
repository: stripe/stripe-cli
path: stripe-cli
- name: Update generated code in stripe-cli
run: |
rm -f ./api/openapi-spec/spec3.sdk.json
cp ../openapi/spec3.sdk.json ./api/openapi-spec/spec3.sdk.json
go generate ./...
working-directory: ./stripe-cli
- name: Create pull request on stripe-cli
uses: peter-evans/create-pull-request@v6
with:
path: stripe-cli
title: OpenAPI Update
body: |
Automated OpenAPI update for https://github.com/stripe/openapi/commit/${{ github.sha }}
This pull request was initiated by @${{ github.actor }}
[→ Debug this workflow](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})
branch: update-openapi
token: ${{ steps.gh-api-token.outputs.token }}
delete-branch: true
commit-message: Update OpenAPI for ${{ github.sha }}
committer: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>"
author: "Stripe OpenAPI <105521251+stripe-openapi[bot]@users.noreply.github.com>"
- uses: ./actions/notify-slack
if: always()
with:
action: 'Publishing the OpenAPI spec to other repositories'
send_on_success: false
bot_token: ${{ secrets.SLACK_BOT_TOKEN }}