Generate #36
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: Generate | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| api_version: | |
| description: "API version to generate" | |
| required: true | |
| type: choice | |
| options: | |
| - v20111101 | |
| - v20250224 | |
| version_bump: | |
| description: "Version bump type" | |
| required: true | |
| default: "skip" | |
| type: choice | |
| options: | |
| - skip | |
| - minor | |
| - patch | |
| jobs: | |
| Validate: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| config_file: ${{ steps.validate.outputs.config_file }} | |
| spec_url: ${{ steps.validate.outputs.spec_url }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: 3.1 | |
| - name: Validate configuration | |
| id: validate | |
| run: | | |
| API_VERSION="${{ github.event.inputs.api_version }}" | |
| CONFIG_FILE="openapi/config-${API_VERSION}.yml" | |
| SPEC_URL="https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/${API_VERSION}.yml" | |
| ruby .github/config_validator.rb "$CONFIG_FILE" "$API_VERSION" | |
| echo "✅ Validation passed" | |
| echo "config_file=$CONFIG_FILE" >> $GITHUB_OUTPUT | |
| echo "spec_url=$SPEC_URL" >> $GITHUB_OUTPUT | |
| Generate: | |
| runs-on: ubuntu-latest | |
| needs: Validate | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-node@v3 | |
| - uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: 3.1 | |
| - name: Bump version | |
| id: bump_version | |
| run: | | |
| if [ "${{ github.event.inputs.version_bump }}" != "skip" ]; then | |
| NEW_VERSION=$(ruby .github/version.rb ${{ github.event.inputs.version_bump }} ${{ needs.Validate.outputs.config_file }}) | |
| else | |
| NEW_VERSION=$(jq -r '.version' ./${{ github.event.inputs.api_version }}/package.json 2>/dev/null || grep 'npmVersion' ${{ needs.Validate.outputs.config_file }} | cut -d':' -f2 | tr -d ' ') | |
| fi | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "📦 Version: $NEW_VERSION" | |
| - name: Clean repo | |
| run: ruby .github/clean.rb ${{ github.event.inputs.api_version }} | |
| - name: Copy generator ignore rules | |
| run: | | |
| mkdir -p ./${{ github.event.inputs.api_version }}/ | |
| cp .openapi-generator-ignore ./${{ github.event.inputs.api_version }}/ | |
| - name: Install openapi-generator-cli and Generate SDK | |
| run: npm install @openapitools/openapi-generator-cli -g | |
| - name: Generate SDK | |
| run: | | |
| openapi-generator-cli generate \ | |
| -i ${{ needs.Validate.outputs.spec_url }} \ | |
| -g typescript-axios \ | |
| -c ${{ needs.Validate.outputs.config_file }} \ | |
| -t ./openapi/templates \ | |
| -o ./${{ github.event.inputs.api_version }} | |
| - name: Update CHANGELOG | |
| run: ruby .github/changelog_manager.rb ${{ github.event.inputs.api_version }} | |
| - name: Copy documentation | |
| run: | | |
| cp LICENSE ./${{ github.event.inputs.api_version }}/LICENSE | |
| cp CHANGELOG.md ./${{ github.event.inputs.api_version }}/CHANGELOG.md | |
| cp MIGRATION.md ./${{ github.event.inputs.api_version }}/MIGRATION.md | |
| - name: Create branch | |
| run: git checkout -b "sdk/generate-api-${{ github.event.inputs.api_version }}-${{ steps.bump_version.outputs.version }}" | |
| - name: Create commit | |
| run: | | |
| git config user.name "devexperience" | |
| git config user.email "devexperience@mx.com" | |
| git add . | |
| git commit -m "Generated API ${{ github.event.inputs.api_version }} SDK for version ${{ steps.bump_version.outputs.version }} | |
| This pull request was automatically generated by a GitHub Action. | |
| API Version: ${{ github.event.inputs.api_version }} | |
| SDK Version: ${{ steps.bump_version.outputs.version }} | |
| Version Bump: ${{ github.event.inputs.version_bump }} | |
| ${{ github.event.inputs.version_bump == 'skip' && '⚠️ NO VERSION BUMP - This is a review-only generation for validation before release.' || '' }}" | |
| git push -u origin "sdk/generate-api-${{ github.event.inputs.api_version }}-${{ steps.bump_version.outputs.version }}" | |
| - name: Create PR | |
| run: gh pr create -f | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Slack notification | |
| uses: ravsamhq/notify-slack-action@v2 | |
| if: always() | |
| with: | |
| status: ${{ job.status }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| notification_title: "{repo}: {workflow} workflow" | |
| message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>" | |
| footer: "<{workflow_url}|View Workflow>" | |
| notify_when: "failure" | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |