Skip to content

Commit 442dfeb

Browse files
committed
feat(cd): auto-generate SDK
1 parent 35570c5 commit 442dfeb

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

.github/workflows/generate.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Generate
2+
3+
on:
4+
workflow_dispatch: {}
5+
pull_request:
6+
paths:
7+
- openapi.json
8+
- "codegen/**"
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
generate:
17+
name: Generate SDK
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22+
with:
23+
repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
24+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
25+
persist-credentials: false
26+
27+
- name: Install Go
28+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
29+
with:
30+
go-version-file: "./codegen/go.mod"
31+
32+
- name: Set up PHP
33+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.31.0
34+
with:
35+
php-version: '8.4'
36+
extensions: intl
37+
coverage: none
38+
tools: composer:v2
39+
40+
- name: Install dependencies
41+
run: composer install --prefer-dist --no-progress --no-interaction
42+
43+
- name: Generate SDK
44+
run: go run ./... generate ../openapi.json ../src
45+
working-directory: codegen
46+
47+
- name: Format
48+
run: make fmt
49+
50+
- name: Create GitHub App token
51+
id: app-token
52+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
53+
with:
54+
app-id: ${{ secrets.SUMUP_BOT_APP_ID }}
55+
private-key: ${{ secrets.SUMUP_BOT_PRIVATE_KEY }}
56+
57+
- name: Get GitHub App User ID
58+
id: get-user-id
59+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
60+
env:
61+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
62+
63+
- name: Configure git
64+
run: |
65+
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
66+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
67+
68+
- name: Commit changes
69+
id: commit
70+
run: |
71+
git add .
72+
if git diff --cached --quiet; then
73+
echo "changed=false" >> "$GITHUB_OUTPUT"
74+
else
75+
git commit -m "chore: generate code"
76+
echo "changed=true" >> "$GITHUB_OUTPUT"
77+
fi
78+
79+
- name: Push changes
80+
if: steps.commit.outputs.changed == 'true'
81+
env:
82+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
83+
TARGET_REPO: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
84+
TARGET_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
85+
run: |
86+
git push "https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git" "HEAD:${TARGET_REF}"

0 commit comments

Comments
 (0)