update-sdk #84
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: Update and Publish SDK | |
| on: | |
| repository_dispatch: | |
| types: [update-sdk] | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| update-and-publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '11' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Install OpenAPI Generator | |
| run: | | |
| npm install -g @openapitools/openapi-generator-cli | |
| - name: Fetch current version from swagger | |
| id: fetch-version | |
| run: | | |
| SWAGGER_URL="https://api.linkbreakers.com/internal/openapi/api/v1/api.swagger.json" | |
| NEW_VERSION=$(curl -s "$SWAGGER_URL" | jq -r '.info.version') | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "Swagger version: $NEW_VERSION" | |
| - name: Read current OPENAPI_VERSION | |
| id: current-version | |
| run: | | |
| if [ -f OPENAPI_VERSION ]; then | |
| CURRENT_VERSION=$(cat OPENAPI_VERSION) | |
| else | |
| CURRENT_VERSION="0.0.0" | |
| fi | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Compare versions | |
| id: compare | |
| run: | | |
| if [ "${{ steps.fetch-version.outputs.new_version }}" == "${{ steps.current-version.outputs.current_version }}" ]; then | |
| echo "needs_update=false" >> $GITHUB_OUTPUT | |
| echo "✅ Versions match. No update needed." | |
| else | |
| echo "needs_update=true" >> $GITHUB_OUTPUT | |
| echo "🔄 Version changed: ${{ steps.current-version.outputs.current_version }} → ${{ steps.fetch-version.outputs.new_version }}" | |
| fi | |
| - name: Download and convert OpenAPI spec to 3.1 | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| # Download OpenAPI 3.2.0 spec | |
| curl -o openapi-3.2.json https://api.linkbreakers.com/internal/openapi/api/v1/api.swagger.json | |
| # Convert OpenAPI 3.2 to 3.1 (remove 3.2-specific fields) | |
| jq '.openapi = "3.1.0" | del(.jsonSchemaDialect)' openapi-3.2.json > openapi-3.1.json | |
| echo "✅ OpenAPI spec converted from 3.2 to 3.1" | |
| - name: Generate SDK using OpenAPI Generator | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}" | |
| # Backup custom files that we want to preserve | |
| mkdir -p .backup | |
| cp pom.xml .backup/ 2>/dev/null || true | |
| cp README.md .backup/ 2>/dev/null || true | |
| # Remove old generated code | |
| rm -rf src/main/java/com/linkbreakers 2>/dev/null || true | |
| rm -rf src/main/java/org/openapitools 2>/dev/null || true | |
| # Generate SDK using OpenAPI Generator with java generator | |
| openapi-generator-cli generate \ | |
| -i openapi-3.1.json \ | |
| -g java \ | |
| -o . \ | |
| --skip-validate-spec \ | |
| --global-property apiTests=false,modelTests=false,apiDocs=false,modelDocs=false \ | |
| --additional-properties=groupId=com.linkbreakers,artifactId=linkbreakers-sdk,artifactVersion=$NEW_VERSION,invokerPackage=com.linkbreakers,apiPackage=com.linkbreakers.api,modelPackage=com.linkbreakers.model,library=okhttp-gson,dateLibrary=java8,hideGenerationTimestamp=true | |
| # Restore custom pom.xml (contains publishing config) | |
| cp .backup/pom.xml . 2>/dev/null || true | |
| cp .backup/README.md . 2>/dev/null || true | |
| # Update ONLY the project version in pom.xml (not plugin versions) | |
| # This targets the <version> tag that comes right after <artifactId>linkbreakers-sdk</artifactId> | |
| sed -i "/<artifactId>linkbreakers-sdk<\/artifactId>/!b;n;s|<version>.*</version>|<version>$NEW_VERSION</version>|" pom.xml | |
| # Clean up | |
| rm -rf .backup | |
| rm openapi-3.2.json openapi-3.1.json | |
| echo "✅ SDK generated successfully with version $NEW_VERSION" | |
| - name: Update version files | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}" | |
| # Update OPENAPI_VERSION file | |
| echo "$NEW_VERSION" > OPENAPI_VERSION | |
| echo "✅ Version files updated to $NEW_VERSION" | |
| - name: Build with Maven | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| mvn clean package -DskipTests | |
| echo "✅ Maven build completed" | |
| - name: Import GPG key | |
| if: steps.compare.outputs.needs_update == 'true' | |
| env: | |
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| run: | | |
| echo "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --import | |
| echo "✅ GPG key imported" | |
| - name: Configure Maven settings | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| mkdir -p ~/.m2 | |
| cat > ~/.m2/settings.xml <<EOF | |
| <settings> | |
| <servers> | |
| <server> | |
| <id>central</id> | |
| <username>${{ secrets.CENTRAL_TOKEN_USERNAME }}</username> | |
| <password>${{ secrets.CENTRAL_TOKEN_PASSWORD }}</password> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| echo "✅ Maven settings configured for Sonatype Central Portal" | |
| - name: Configure Git | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Commit changes | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}" | |
| git add . | |
| git commit -m "chore: update SDK to API version $NEW_VERSION" | |
| echo "✅ Changes committed" | |
| - name: Create and push tag | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}" | |
| git tag "v$NEW_VERSION" | |
| git push origin main | |
| git push origin "v$NEW_VERSION" | |
| echo "✅ Tag v$NEW_VERSION created and pushed" | |
| - name: Deploy to Maven Central | |
| if: steps.compare.outputs.needs_update == 'true' | |
| env: | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| run: | | |
| mvn clean deploy -DskipTests -Dgpg.passphrase=$GPG_PASSPHRASE | |
| echo "✅ Published to Maven Central" | |
| - name: Summary | |
| if: steps.compare.outputs.needs_update == 'true' | |
| run: | | |
| echo "🎉 SDK successfully updated and published!" | |
| echo "Version: ${{ steps.fetch-version.outputs.new_version }}" | |
| echo "Maven Central: https://central.sonatype.com/artifact/com.linkbreakers/linkbreakers-sdk" |