-
Notifications
You must be signed in to change notification settings - Fork 4
101 lines (91 loc) · 3.79 KB
/
generate_sdk_code.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
name: Generate SDK Code
on:
repository_dispatch:
types: [publish_sdk]
env:
GENERATOR_VERISON: "7.6.0"
CONFIG_FILE: "sdk-gen-config.json"
jobs:
sdk:
name: Generate SDK code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Latest Release
id: latest-version
uses: pozetroninc/[email protected]
with:
owner: ${{ github.repository_owner }}
repo: databox-go
excludes: prerelease, draft
token: ${{ secrets.PAT_APPROVE_PR }}
- name: Determine Version
id: version
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.latest-version.outputs.release }}';
const parts = version.split('.');
switch('${{ github.event.client_payload.labels }}') {
case 'patch':
parts[2] = parseInt(parts[2]) + 1;
break;
case 'minor':
parts[1] = parseInt(parts[1]) + 1;
break;
case 'major':
parts[0] = parseInt(parts[0]) + 1;
break;
default:
parts[2] = parseInt(parts[2]) + 1;
break;
}
const newVersion = parts.join('.');
return newVersion;
- name: Download OpenAPI Generator
run: |
curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${{ env.GENERATOR_VERISON }}/openapi-generator-cli-${{ env.GENERATOR_VERISON }}.jar -o ${{ runner.temp }}/openapi-generator-cli.jar
- name: Download OpenAPI Specification
uses: actions/download-artifact@v4
with:
name: ${{ github.event.client_payload.openapi_spec }}
path: ${{ runner.temp }}/openapispec
repository: databox/data-link
github-token: ${{ secrets.PAT_APPROVE_PR }}
run-id: ${{ github.event.client_payload.run_id }}
- name: Remove old SDK
run: |
rm -rf src/*
rm -rf docs/*
rm -f go.mod
rm -f go.sum
- name: Set API and SDK versions
run: |
cp .github/${{ env.CONFIG_FILE }} ${{ runner.temp }}/${{ env.CONFIG_FILE }}
#set SDK version
sed -i "s/{VERSION}/${{ steps.version.outputs.result }}/g" ${{ runner.temp }}/${{ env.CONFIG_FILE }}
#set API version
sed -i 's/version: "1.0"/version: ${{ github.event.client_payload.version }}/g' ${{ runner.temp }}/openapispec/openapi.yml
- name: Generate SDK
run: |
java --version
java -jar ${{ runner.temp }}/openapi-generator-cli.jar generate -i ${{ runner.temp }}/openapispec/openapi.yml -g go -o ./src -c ${{ runner.temp }}/${{ env.CONFIG_FILE }} --skip-validate-spec -t ./codegen-template
cp ./src/README.md ./README.md
cp -r ./src/docs ./docs
cp ./src/go.mod ./go.mod
cp ./src/go.sum ./go.sum
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
base: master
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: release data-link SDK'
title: '[SDK release] Generated SDK code based on data-link ${{ github.event.client_payload.version }} API changes'
branch: 'release/${{ github.event.client_payload.version }}/${{ github.event.client_payload.timestamp }}'
body: >
This is a release of the SDK based on the API changes for `data-link` [${{ github.event.client_payload.version }}](${{ github.event.client_payload.release_url }}).
labels: |
automated
${{ github.event.client_payload.labels || 'patch' }}