-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (118 loc) · 4.45 KB
/
Copy pathgenerate.yml
File metadata and controls
137 lines (118 loc) · 4.45 KB
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
name: Regenerate
on:
repository_dispatch:
types: [openapi-updated]
workflow_dispatch:
jobs:
generate:
name: Regenerate from OpenAPI
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Install OpenAPI Generator
run: npm install -g @openapitools/openapi-generator-cli
- name: Fetch latest OpenAPI spec
run: |
curl -f --retry 5 --retry-delay 2 --retry-all-errors --max-time 60 -o openapi.yaml https://zernio.com/openapi.yaml
echo "Fetched OpenAPI spec"
- name: Generate SDK
run: |
openapi-generator-cli generate \
-i openapi.yaml \
-g java \
-o . \
--skip-validate-spec \
--global-property skipFormModel=false \
--additional-properties=artifactId=zernio-sdk,groupId=dev.zernio,apiPackage=dev.zernio.api,modelPackage=dev.zernio.model,invokerPackage=dev.zernio,library=native \
--git-user-id=zernio-dev \
--git-repo-id=zernio-java
- name: Remove generated workflow files
run: |
rm -f .github/workflows/maven.yml || true
git checkout .github/workflows/generate.yml
- name: Build
run: mvn compile -q
- name: Check for changes
id: changes
run: |
git add -A
if git diff --staged --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Get next version
if: steps.changes.outputs.has_changes == 'true'
id: version
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
NEW_VERSION=$(echo $LATEST_TAG | awk -F. '{printf "v%d.%d.%d", $1, $2, $3+1}' | sed 's/vv/v/')
MVN_VERSION=$(echo $NEW_VERSION | sed 's/v//')
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "mvn_version=$MVN_VERSION" >> $GITHUB_OUTPUT
- name: Update pom version
if: steps.changes.outputs.has_changes == 'true'
run: |
mvn versions:set -DnewVersion=${{ steps.version.outputs.mvn_version }} -DgenerateBackupPoms=false || true
- name: Commit and push
if: steps.changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: regenerate from OpenAPI spec
- Auto-generated SDK updates
- Version: ${{ steps.version.outputs.new_version }}"
# Retry with rebase to survive concurrent dispatches that land
# back-to-back pushes to main.
for attempt in 1 2 3; do
if git push; then break; fi
echo "Push attempt $attempt failed; rebasing and retrying..."
git pull --rebase origin main
sleep $((attempt * 5))
done
- name: Create GitHub Release
if: steps.changes.outputs.has_changes == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.new_version }}
name: ${{ steps.version.outputs.new_version }}
generate_release_notes: true
body: |
## Auto-generated SDK Update
**Maven** (add JitPack repository):
```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.zernio-dev</groupId>
<artifactId>zernio-java</artifactId>
<version>${{ steps.version.outputs.new_version }}</version>
</dependency>
```
**Gradle**:
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.zernio-dev:zernio-java:${{ steps.version.outputs.new_version }}'
}
```
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}