Skip to content

Update bundled openapi definition & Generate SDK #182

Update bundled openapi definition & Generate SDK

Update bundled openapi definition & Generate SDK #182

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