openapi-updated #794
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Setup Java (for openapi-generator) | |
| 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: Clean previous generation | |
| run: | | |
| # Remove both Zernio (re-gen) and pre-rebrand Late trees so only the | |
| # fresh Zernio.* tree is committed. | |
| rm -rf src/Zernio src/Zernio.Test Zernio.sln | |
| rm -rf src/Late src/Late.Test Late.sln | |
| rm -rf docs | |
| - name: Generate SDK (primary — Zernio namespace) | |
| run: | | |
| openapi-generator-cli generate \ | |
| -i openapi.yaml \ | |
| -g csharp \ | |
| -o . \ | |
| --skip-validate-spec \ | |
| --additional-properties=packageName=Zernio,targetFramework=net8.0,library=httpclient \ | |
| --git-user-id=zernio-dev \ | |
| --git-repo-id=zernio-dotnet | |
| - name: Patch README install instructions | |
| run: | | |
| python3 -c " | |
| import re, textwrap | |
| with open('README.md', 'r') as f: | |
| content = f.read() | |
| install_section = textwrap.dedent('''## Installation | |
| Install via NuGet: | |
| \`\`\`bash | |
| dotnet add package Zernio | |
| \`\`\` | |
| Then add the namespaces to your project: | |
| \`\`\`csharp | |
| using Zernio.Api; | |
| using Zernio.Client; | |
| using Zernio.Model; | |
| \`\`\` | |
| The legacy \`Late\` package is still published at the same version and ships the same SDK under the \`Late.*\` namespace for pre-rebrand users.''') | |
| content = re.sub(r'<a id=\"frameworks-supported\">.*?(?=<a id=\"packaging\">)', '<a id=\"installation\">\n' + install_section + '\n\n', content, flags=re.DOTALL) | |
| with open('README.md', 'w') as f: | |
| f.write(content) | |
| " | |
| - name: Build | |
| run: dotnet build -c Release | |
| - name: Run tests | |
| run: dotnet test -c Release | |
| - 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/') | |
| NUGET_VERSION=$(echo $NEW_VERSION | sed 's/v//') | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "nuget_version=$NUGET_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update version in csproj | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| find . -name "*.csproj" -exec sed -i "s/<Version>.*<\/Version>/<Version>${{ steps.version.outputs.nuget_version }}<\/Version>/" {} \; || 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: Build | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: dotnet build -c Release | |
| - name: Pack and publish Zernio (primary) | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| dotnet pack -c Release --no-build -o ./nupkg | |
| dotnet nuget push ./nupkg/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate | |
| - name: Generate and publish legacy Late package | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| # Regenerate the SDK with packageName=Late into an ephemeral dir, | |
| # build, pack, and publish as the `Late` NuGet package. Not committed | |
| # back to the repo — only published so `using Late.Api;` callers | |
| # keep working. | |
| LATE_BUILD_DIR=$(mktemp -d) | |
| openapi-generator-cli generate \ | |
| -i openapi.yaml \ | |
| -g csharp \ | |
| -o "$LATE_BUILD_DIR" \ | |
| --skip-validate-spec \ | |
| --additional-properties=packageName=Late,targetFramework=net8.0,library=httpclient \ | |
| --git-user-id=zernio-dev \ | |
| --git-repo-id=zernio-dotnet | |
| find "$LATE_BUILD_DIR" -name "*.csproj" -exec sed -i "s/<Version>.*<\/Version>/<Version>${{ steps.version.outputs.nuget_version }}<\/Version>/" {} \; | |
| dotnet build "$LATE_BUILD_DIR" -c Release | |
| dotnet pack "$LATE_BUILD_DIR" -c Release --no-build -o "$LATE_BUILD_DIR/nupkg-late" | |
| dotnet nuget push "$LATE_BUILD_DIR"/nupkg-late/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate | |
| rm -rf "$LATE_BUILD_DIR" | |
| - 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 | |
| ```bash | |
| dotnet add package Zernio --version ${{ steps.version.outputs.nuget_version }} | |
| ``` | |
| The legacy `Late` package is also published at the same version for | |
| backwards compatibility with pre-rebrand users. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |