openapi-updated #108
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: | |
| # Triggered by the API repository when OpenAPI spec changes | |
| repository_dispatch: | |
| types: [openapi-updated] | |
| # Allow manual trigger | |
| 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 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Fetch latest OpenAPI spec | |
| run: | | |
| curl -f -o openapi.yaml https://zernio.com/openapi.yaml | |
| echo "Fetched OpenAPI spec:" | |
| head -20 openapi.yaml | |
| - name: Generate SDK | |
| run: | | |
| echo "Starting SDK generation..." | |
| npm run generate | |
| echo "Generation complete. Checking generated files:" | |
| ls -la src/generated/ | |
| - name: Generate README SDK Reference | |
| run: | | |
| echo "Starting README SDK Reference generation..." | |
| npx tsx scripts/generate-readme-reference.ts | |
| echo "README SDK Reference generation complete." | |
| - name: Generate endpoint tests | |
| run: | | |
| echo "Starting endpoint tests generation..." | |
| npx tsx scripts/generate-endpoint-tests.ts | |
| echo "Endpoint tests generation complete." | |
| - name: Build | |
| run: npm run build | |
| - name: Type check | |
| run: npm run typecheck | |
| - name: Run tests | |
| run: npm test | |
| - 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: Bump version and commit | |
| if: steps.changes.outputs.has_changes == 'true' | |
| id: version | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Bump patch version | |
| NEW_VERSION=$(npm version patch --no-git-tag-version) | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| # Stage version change | |
| git add package.json package-lock.json | |
| # Commit all changes | |
| git commit -m "chore: regenerate from OpenAPI spec | |
| - Auto-generated SDK updates | |
| - Version: $NEW_VERSION" | |
| git push | |
| - name: Publish to npm as @zernio/node | |
| if: steps.changes.outputs.has_changes == 'true' | |
| continue-on-error: true | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish to npm as @getlatedev/node (legacy) | |
| if: steps.changes.outputs.has_changes == 'true' | |
| continue-on-error: true | |
| run: | | |
| node -e "const p=JSON.parse(require('fs').readFileSync('package.json','utf8')); p.name='@getlatedev/node'; require('fs').writeFileSync('package.json', JSON.stringify(p, null, 2)+'\n')" | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - 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 | |
| This release was automatically generated from the latest OpenAPI spec. | |
| ```bash | |
| npm install @zernio/node@${{ steps.version.outputs.new_version }} | |
| ``` | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |