Skip to content

openapi-updated

openapi-updated #1194

Workflow file for this run

name: Regenerate
on:
repository_dispatch:
types: [openapi-updated]
workflow_dispatch:
# Serialize runs: concurrent dispatches race each other's push to main and
# compute the same next version from the same tag state (the second publish
# is rejected by the registry).
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
generate:
name: Regenerate from OpenAPI
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Explicit ref: for repository_dispatch, the default github.sha is
# resolved at dispatch time, so a run queued behind another run
# checks out a tip that misses the earlier push and then conflicts.
ref: main
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: Normalize spec for the Java generator
run: |
python3 -c 'import yaml' 2>/dev/null || python3 -m pip install --quiet --break-system-packages pyyaml
python3 scripts/normalize-spec-for-java.py openapi.yaml "$RUNNER_TEMP/openapi-java.json"
- name: Generate SDK
run: |
openapi-generator-cli generate \
-i "$RUNNER_TEMP/openapi-java.json" \
-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: |
# Base = max(highest tag, highest published Maven version). git
# describe can select an older tag when multiple tags point to the
# same commit, which made every run recompute and republish 0.0.952.
# Checking Central also self-heals any publish/tag divergence.
TAG_VERSION=$(git tag -l 'v*' | sed 's/^v//' | sort -V | tail -1)
CENTRAL_PUBLISHED=$(curl -sf --retry 3 https://repo1.maven.org/maven2/com/zernio/zernio-sdk/maven-metadata.xml | sed -n 's:.*<latest>\([^<]*\)</latest>.*:\1:p' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' || echo "0.0.0")
BASE=$(printf '%s\n' "${TAG_VERSION:-0.0.0}" "$CENTRAL_PUBLISHED" | sort -V | tail -1)
MVN_VERSION=$(echo "$BASE" | awk -F. '{printf "%d.%d.%d", $1, $2, $3+1}')
echo "new_version=v$MVN_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. -X theirs: the replayed commit is a
# full regeneration from a fresher spec fetch, so on conflicting
# hunks the regenerated content wins instead of aborting the run.
for attempt in 1 2 3; do
if git push; then break; fi
echo "Push attempt $attempt failed; rebasing and retrying..."
git pull --rebase -X theirs 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 }}
- name: Trigger Maven Central publish
# Releases created with GITHUB_TOKEN do not fire `release: published`
# workflows (GitHub anti-recursion rule), so publish.yml never ran on
# auto-releases and Maven Central sat at 0.0.307 (2026-06-01) while
# GitHub releases advanced. workflow_dispatch is exempt from that rule.
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run publish.yml --ref main