-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (131 loc) · 5.06 KB
/
openapi-update-generate-new-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
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
name: Update bundled openapi definition & Generate SDK
on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: '0 7 * * *' # At 07:00 every day
jobs:
scheduled:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch latest OpenAPI definition
shell: bash
run: |
curl -s https://openapi-v2.exoscale.com/source.yaml -o api/openapi.yaml
- name: Check for changes in OpenAPI definition
id: changes
run: |
git diff --exit-code api/openapi.yaml || echo "CHANGED=true" >> $GITHUB_ENV
- name: Install xmlstarlet
if: env.CHANGED == 'true'
run: sudo apt-get update && sudo apt-get install -y xmlstarlet
- name: Increment artifactVersion
if: env.CHANGED == 'true'
id: increment_version
run: |
current_version=$(xmlstarlet sel -t -v "//*[local-name()='artifactVersion']" pom.xml)
echo "Current version: $current_version"
unique_id=$(git rev-parse --short HEAD)
if [[ "$current_version" == *"SNAPSHOT"* ]]; then
echo "Current version is a SNAPSHOT."
base_version=$(echo "$current_version" | sed -E 's/-SNAPSHOT-.*//')
new_version="${base_version}-SNAPSHOT-${unique_id}"
else
echo "Current version is the last release."
IFS='.-' read -r -a parts <<< "$current_version"
major=${parts[0]}
minor=${parts[1]}
patch=${parts[2]}
qualifier=${parts[3]}
new_patch=$((patch + 1))
if [ -z "$qualifier" ]; then
base_version="${major}.${minor}.${new_patch}"
else
base_version="${major}.${minor}.${new_patch}-${qualifier}"
fi
new_version="${base_version}-SNAPSHOT-${unique_id}"
fi
echo "New version: $new_version"
xmlstarlet ed --inplace --update "//*[local-name()='artifactVersion']" --value "$new_version" pom.xml
echo "new_version=$new_version" >> $GITHUB_ENV
echo "Updated version to $new_version"
- name: Delete existing SDK if OpenAPI definition has changed
if: env.CHANGED == 'true'
run: |
rm -rf sdk/*
- name: Generate code if OpenAPI definition has changed
if: env.CHANGED == 'true'
run: |
mvn generate-sources process-resources
cd sdk
mvn install
cd ..
- name: Check target folder for JavaDocs
if: env.CHANGED == 'true'
run: ls -lR sdk/target/
- name: Copy Javadoc JAR to a temporary location
if: env.CHANGED == 'true'
run: |
echo "Checking target folder for JavaDocs"
ls -lR sdk/target/
mkdir -p /tmp/javadoc
cp sdk/target/*-javadoc.jar /tmp/javadoc/
- name: Commit and push changes if OpenAPI definition has changed
if: env.CHANGED == 'true'
run: |-
git config user.name "Exoscale"
git config user.email "[email protected]"
git add .
timestamp=$(date -u)
git commit -m "OpenAPI spec and SDK update: ${timestamp}" || exit 0
git push
- name: Checkout gh-pages branch
if: env.CHANGED == 'true'
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Move Javadoc JAR back to working directory
if: env.CHANGED == 'true'
run: |
mkdir -p sdk/target/
mv /tmp/javadoc/* sdk/target/
- name: Clean current Javadoc and docs folders before new extraction
if: env.CHANGED == 'true'
run: |
rm -rf docs/*
rm -rf javadoc/current/*
- name: Extract Javadoc JAR dynamically and create version-specific folder
if: env.CHANGED == 'true'
run: |
mkdir -p docs
mkdir -p javadoc/current
mkdir -p javadoc/$new_version
JAR_FILE=$(find sdk/target -name '*-javadoc.jar' | head -n 1)
echo "Found Javadoc JAR: $JAR_FILE"
cp "$JAR_FILE" docs/
cp "$JAR_FILE" javadoc/current/
cp "$JAR_FILE" javadoc/$new_version/
cd docs/
jar -xvf $(basename "$JAR_FILE")
cd ..
cd javadoc/current
jar -xvf $(basename "$JAR_FILE")
cd ../$new_version
jar -xvf $(basename "$JAR_FILE")
- name: Append new version to index.html files
if: env.CHANGED == 'true'
run: |
sed -i '/<ul>/a \ \ \ \ \ \ \ \ <li><a href="javadoc/'"$new_version"'">'"$new_version"'</a></li>' index.html
sed -i '/<ul>/a \ \ \ \ \ \ \ \ <li><a href="'$new_version'">'"$new_version"'</a></li>' javadoc/index.html
- name: Commit and push JavaDocs
if: env.CHANGED == 'true'
run: |-
git config user.name "Exoscale"
git config user.email "[email protected]"
git add .
git commit -m "Update JavaDocs for $new_version"
git push