openapi-updated #100
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 Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.2' | |
| bundler-cache: false | |
| - 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 -o openapi.yaml https://zernio.com/openapi.yaml | |
| echo "Fetched OpenAPI spec" | |
| - name: Clean generated files | |
| run: | | |
| rm -rf lib/late-sdk/models lib/late-sdk/api docs spec | |
| rm -rf lib/late lib/late.rb late.gemspec | |
| - name: Generate SDK | |
| run: | | |
| openapi-generator-cli generate \ | |
| -i openapi.yaml \ | |
| -g ruby \ | |
| -o . \ | |
| --skip-validate-spec \ | |
| --additional-properties=gemName=late-sdk,moduleName=Late,gemVersion=0.1.0 \ | |
| --inline-schema-name-mappings "getGoogleBusinessLocationDetails_200_response_specialHours_specialHourPeriods_inner_startDate=GbpSpecialHourPeriodStartDate,getGoogleBusinessLocationDetails_200_response_specialHours_specialHourPeriods_inner=GbpSpecialHourPeriod,getGoogleBusinessLocationDetails_200_response_serviceItems_inner_freeFormServiceItem_label=GbpFreeFormServiceItemLabel,updateGoogleBusinessLocationDetails_request_serviceItems_inner_freeFormServiceItem_label=GbpUpdateFreeFormServiceItemLabel" \ | |
| --git-user-id=zernio-dev \ | |
| --git-repo-id=zernio-ruby | |
| - name: Rebrand gemspec name to zernio-sdk | |
| run: | | |
| # The generator creates s.name = "late-sdk", change it to "zernio-sdk" | |
| # so the primary gem is published as zernio-sdk | |
| sed -i 's/s.name = "late-sdk"/s.name = "zernio-sdk"/' late-sdk.gemspec | |
| - name: Restore zernio-sdk.rb entry point | |
| run: | | |
| # The generator cleans files, so recreate the zernio-sdk.rb alias | |
| printf '%s\n' "# Zernio SDK - forwards to late-sdk for backwards compatibility" "require 'late-sdk'" "" "# Alias the module so both Late and Zernio work" "Zernio = Late unless defined?(Zernio)" > lib/zernio-sdk.rb | |
| - name: Add Zernio alias to late-sdk.rb | |
| run: | | |
| # Ensure the Zernio alias is present at the end of lib/late-sdk.rb | |
| if ! grep -q 'Zernio = Late' lib/late-sdk.rb; then | |
| echo '' >> lib/late-sdk.rb | |
| echo '# Zernio alias for backwards compatibility during rebrand' >> lib/late-sdk.rb | |
| echo 'Zernio = Late unless defined?(Zernio)' >> lib/late-sdk.rb | |
| fi | |
| - 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 RubyGems: | |
| \`\`\`bash | |
| gem install late-sdk | |
| \`\`\` | |
| Or add it to your Gemfile: | |
| \`\`\`ruby | |
| gem \"late-sdk\" | |
| \`\`\`''') | |
| content = re.sub(r'## Installation.*?(?=\n## )', install_section + '\n\n', content, flags=re.DOTALL) | |
| with open('README.md', 'w') as f: | |
| f.write(content) | |
| " | |
| - name: Install dependencies | |
| run: bundle install | |
| - name: Run tests | |
| run: bundle exec rake spec | |
| - 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/') | |
| GEM_VERSION=$(echo $NEW_VERSION | sed 's/v//') | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "gem_version=$GEM_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update gem version | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| sed -i "s/VERSION = '.*'/VERSION = '${{ steps.version.outputs.gem_version }}'/" lib/late-sdk/version.rb | |
| - 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 }}" | |
| git push | |
| - name: Setup RubyGems credentials | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| mkdir -p ~/.gem | |
| echo -e "---\n:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials | |
| chmod 0600 ~/.gem/credentials | |
| - name: Build and publish zernio-sdk (primary) | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| # late-sdk.gemspec has s.name = "zernio-sdk" (set in rebrand step) | |
| # so gem build produces zernio-sdk-VERSION.gem | |
| gem build late-sdk.gemspec | |
| gem push zernio-sdk-${{ steps.version.outputs.gem_version }}.gem | |
| continue-on-error: true | |
| - name: Build and publish late-sdk (legacy alias) | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: | | |
| # Create a copy with s.name swapped back to "late-sdk" for the legacy gem | |
| cp late-sdk.gemspec late-sdk-legacy.gemspec | |
| sed -i 's/s.name = "zernio-sdk"/s.name = "late-sdk"/' late-sdk-legacy.gemspec | |
| gem build late-sdk-legacy.gemspec | |
| gem push late-sdk-${{ steps.version.outputs.gem_version }}.gem | |
| rm -f late-sdk-legacy.gemspec | |
| continue-on-error: true | |
| - 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 | |
| gem install late-sdk | |
| # or | |
| gem install zernio-sdk | |
| ``` | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |