|
| 1 | +name: Test Multi-Version SDK |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + api_version: |
| 7 | + description: 'API Version to generate' |
| 8 | + required: true |
| 9 | + default: 'v20111101' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - 'v20111101' |
| 13 | + - 'v20250224' |
| 14 | + - 'latest' |
| 15 | + test_level: |
| 16 | + description: 'Testing level' |
| 17 | + required: true |
| 18 | + default: 'generate_only' |
| 19 | + type: choice |
| 20 | + options: |
| 21 | + - 'generate_only' # No commits, no publishing |
| 22 | + - 'github_packages' # Publish to GitHub Packages (safe staging) |
| 23 | + |
| 24 | +jobs: |
| 25 | + Test: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v3 |
| 29 | + - uses: actions/setup-node@v3 |
| 30 | + with: |
| 31 | + node-version: "20" |
| 32 | + - uses: ruby/setup-ruby@v1 |
| 33 | + with: |
| 34 | + ruby-version: 3.1 |
| 35 | + |
| 36 | + # Determine configuration based on API version |
| 37 | + - name: Set version configuration |
| 38 | + id: config |
| 39 | + run: | |
| 40 | + API_VERSION="${{ github.event.inputs.api_version }}" |
| 41 | + |
| 42 | + echo "config_file=./openapi/config-$API_VERSION.yml" >> $GITHUB_OUTPUT |
| 43 | + echo "output_dir=./test-output-$API_VERSION" >> $GITHUB_OUTPUT |
| 44 | + |
| 45 | + if [ "$API_VERSION" = "latest" ]; then |
| 46 | + echo "spec_url=https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/v20111101.yml" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "spec_url=https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/$API_VERSION.yml" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | +
|
| 51 | + # Create output directory for testing versions |
| 52 | + - name: Prepare test output directory |
| 53 | + run: mkdir -p ${{ steps.config.outputs.output_dir }} |
| 54 | + |
| 55 | + # Install OpenAPI Generator |
| 56 | + - name: Install openapi-generator-cli |
| 57 | + run: | |
| 58 | + npm install @openapitools/openapi-generator-cli -g |
| 59 | +
|
| 60 | + # Validate config file exists |
| 61 | + - name: Validate config file |
| 62 | + run: | |
| 63 | + if [ ! -f "${{ steps.config.outputs.config_file }}" ]; then |
| 64 | + echo "❌ Config file ${{ steps.config.outputs.config_file }} not found" |
| 65 | + echo "Available config files:" |
| 66 | + ls -la ./openapi/config*.yml || echo "No config files found" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + echo "✅ Using config file: ${{ steps.config.outputs.config_file }}" |
| 70 | +
|
| 71 | + # Generate SDK |
| 72 | + - name: Generate SDK |
| 73 | + run: | |
| 74 | + echo "🔧 Generating SDK for version: ${{ github.event.inputs.api_version }}" |
| 75 | + echo "📄 Config: ${{ steps.config.outputs.config_file }}" |
| 76 | + echo "🌐 Spec: ${{ steps.config.outputs.spec_url }}" |
| 77 | + echo "📁 Output: ${{ steps.config.outputs.output_dir }}" |
| 78 | + |
| 79 | + openapi-generator-cli generate \ |
| 80 | + -i ${{ steps.config.outputs.spec_url }} \ |
| 81 | + -g typescript-axios \ |
| 82 | + -c ${{ steps.config.outputs.config_file }} \ |
| 83 | + -t ./openapi/templates \ |
| 84 | + -o ${{ steps.config.outputs.output_dir }} |
| 85 | +
|
| 86 | + # Test TypeScript compilation |
| 87 | + - name: Test TypeScript compilation |
| 88 | + run: | |
| 89 | + cd ${{ steps.config.outputs.output_dir }} |
| 90 | + npm install |
| 91 | + npm run build |
| 92 | + echo "✅ TypeScript compilation successful" |
| 93 | +
|
| 94 | + # Archive generated code as artifact for inspection |
| 95 | + - name: Archive generated code |
| 96 | + uses: actions/upload-artifact@v3 |
| 97 | + with: |
| 98 | + name: generated-sdk-${{ github.event.inputs.api_version }} |
| 99 | + path: ${{ steps.config.outputs.output_dir }} |
| 100 | + retention-days: 7 |
| 101 | + |
| 102 | + # Validation summary |
| 103 | + - name: Validation summary |
| 104 | + run: | |
| 105 | + echo "🎉 Generation successful for ${{ github.event.inputs.api_version }}!" |
| 106 | + |
| 107 | + # Show package.json name for verification |
| 108 | + PACKAGE_NAME=$(cat ${{ steps.config.outputs.output_dir }}/package.json | grep '"name"' | cut -d'"' -f4) |
| 109 | + PACKAGE_VERSION=$(cat ${{ steps.config.outputs.output_dir }}/package.json | grep '"version"' | cut -d'"' -f4) |
| 110 | + echo "📦 Generated package: $PACKAGE_NAME@$PACKAGE_VERSION" |
| 111 | + |
| 112 | + # Count API files |
| 113 | + API_COUNT=$(find ${{ steps.config.outputs.output_dir }} -name "*api.ts" | wc -l) |
| 114 | + echo "🔍 Generated API files: $API_COUNT" |
| 115 | + |
| 116 | + # Show file structure |
| 117 | + echo "" |
| 118 | + echo "📂 Generated file structure:" |
| 119 | + ls -lh ${{ steps.config.outputs.output_dir }} |
| 120 | +
|
| 121 | + # Publish to GitHub Packages (Safe Testing) |
| 122 | + - name: Publish to GitHub Packages |
| 123 | + if: ${{ github.event.inputs.test_level == 'github_packages' }} |
| 124 | + run: | |
| 125 | + cd ${{ steps.config.outputs.output_dir }} |
| 126 | + |
| 127 | + # Configure for GitHub Packages |
| 128 | + npm config set registry https://npm.pkg.github.com |
| 129 | + npm config set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }} |
| 130 | + |
| 131 | + # Publish the test package |
| 132 | + npm publish |
| 133 | + |
| 134 | + PACKAGE_NAME=$(cat package.json | grep '"name"' | cut -d'"' -f4) |
| 135 | + PACKAGE_VERSION=$(cat package.json | grep '"version"' | cut -d'"' -f4) |
| 136 | + |
| 137 | + echo "✅ Published test package to GitHub Packages" |
| 138 | + echo "📦 Package: $PACKAGE_NAME@$PACKAGE_VERSION" |
| 139 | + echo "🔗 View at: https://github.com/mxenabled/mx-platform-node/packages" |
| 140 | +
|
| 141 | + - name: Slack notification |
| 142 | + if: always() |
| 143 | + uses: ravsamhq/notify-slack-action@v2 |
| 144 | + with: |
| 145 | + status: ${{ job.status }} |
| 146 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + notification_title: "{repo}: {workflow} workflow" |
| 148 | + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>" |
| 149 | + footer: "<{workflow_url}|View Workflow>" |
| 150 | + notify_when: "failure" |
| 151 | + env: |
| 152 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments