-
Notifications
You must be signed in to change notification settings - Fork 1
80 lines (63 loc) · 2.1 KB
/
generate-sdk.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
name: Generate SDK on PR Merge
on:
push:
branches:
- main
paths:
- 'openapi.json'
permissions:
contents: write
jobs:
generate-sdk:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Last Commit Message
id: commit_message
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "commit_message=$COMMIT_MSG" >> $GITHUB_OUTPUT
- name: Check for Generate SDK Flag
if: contains(steps.commit_message.outputs.commit_message, '[generate-sdk]')
run: echo "Generate SDK flag found. Proceeding with SDK generation."
- name: Exit if Flag Not Found
if: "! contains(steps.commit_message.outputs.commit_message, '[generate-sdk]')"
run: |
echo "Generate SDK flag not found in commit message. Exiting."
exit 0
- name: Extract version from openapi.json
id: extract_version
run: |
VERSION=$(jq -r '.info.version' openapi.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.20'
- name: Install oapi-codegen
run: go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
- name: Generate sdk.go
run: oapi-codegen -generate types,client,spec -package oapiclient -o ./sdk/oapicodegenfromdoc.go ./openapi/openapi.json
- name: Generate version.go
run: |
cat <<EOF > ./sdk/version.go
package sdk
// Version of the SDK
const Version = "${{ steps.extract_version.outputs.version }}"
EOF
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit changes
run: |
git add ./sdk/oapicodegenfromdoc.go ./sdk/version.go
git commit -m "Generate oapicodegenfromdoc.go and version.go"
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main