Skip to content

Test Multi-Version SDK #1

Test Multi-Version SDK

Test Multi-Version SDK #1

name: Test Multi-Version SDK
on:
workflow_dispatch:
inputs:
api_version:
description: 'API Version to generate'
required: true
default: 'v20111101'
type: choice
options:
- 'v20111101'
- 'v20250224'
- 'latest'
test_level:
description: 'Testing level'
required: true
default: 'generate_only'
type: choice
options:
- 'generate_only' # No commits, no publishing
- 'github_packages' # Publish to GitHub Packages (safe staging)
jobs:
Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20"
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
# Determine configuration based on API version
- name: Set version configuration
id: config
run: |
API_VERSION="${{ github.event.inputs.api_version }}"
echo "config_file=./openapi/config-$API_VERSION.yml" >> $GITHUB_OUTPUT
echo "output_dir=./test-output-$API_VERSION" >> $GITHUB_OUTPUT
if [ "$API_VERSION" = "latest" ]; then
echo "spec_url=https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/v20111101.yml" >> $GITHUB_OUTPUT
else
echo "spec_url=https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/$API_VERSION.yml" >> $GITHUB_OUTPUT
fi
# Create output directory for testing versions
- name: Prepare test output directory
run: mkdir -p ${{ steps.config.outputs.output_dir }}
# Install OpenAPI Generator
- name: Install openapi-generator-cli
run: |
npm install @openapitools/openapi-generator-cli -g
# Validate config file exists
- name: Validate config file
run: |
if [ ! -f "${{ steps.config.outputs.config_file }}" ]; then
echo "❌ Config file ${{ steps.config.outputs.config_file }} not found"
echo "Available config files:"
ls -la ./openapi/config*.yml || echo "No config files found"
exit 1
fi
echo "✅ Using config file: ${{ steps.config.outputs.config_file }}"
# Generate SDK
- name: Generate SDK
run: |
echo "🔧 Generating SDK for version: ${{ github.event.inputs.api_version }}"
echo "📄 Config: ${{ steps.config.outputs.config_file }}"
echo "🌐 Spec: ${{ steps.config.outputs.spec_url }}"
echo "📁 Output: ${{ steps.config.outputs.output_dir }}"
openapi-generator-cli generate \
-i ${{ steps.config.outputs.spec_url }} \
-g typescript-axios \
-c ${{ steps.config.outputs.config_file }} \
-t ./openapi/templates \
-o ${{ steps.config.outputs.output_dir }}
# Test TypeScript compilation
- name: Test TypeScript compilation
run: |
cd ${{ steps.config.outputs.output_dir }}
npm install
npm run build
echo "✅ TypeScript compilation successful"
# Archive generated code as artifact for inspection
- name: Archive generated code
uses: actions/upload-artifact@v3
with:
name: generated-sdk-${{ github.event.inputs.api_version }}
path: ${{ steps.config.outputs.output_dir }}
retention-days: 7
# Validation summary
- name: Validation summary
run: |
echo "🎉 Generation successful for ${{ github.event.inputs.api_version }}!"
# Show package.json name for verification
PACKAGE_NAME=$(cat ${{ steps.config.outputs.output_dir }}/package.json | grep '"name"' | cut -d'"' -f4)
PACKAGE_VERSION=$(cat ${{ steps.config.outputs.output_dir }}/package.json | grep '"version"' | cut -d'"' -f4)
echo "📦 Generated package: $PACKAGE_NAME@$PACKAGE_VERSION"
# Count API files
API_COUNT=$(find ${{ steps.config.outputs.output_dir }} -name "*api.ts" | wc -l)
echo "🔍 Generated API files: $API_COUNT"
# Show file structure
echo ""
echo "📂 Generated file structure:"
ls -lh ${{ steps.config.outputs.output_dir }}
# Publish to GitHub Packages (Safe Testing)
- name: Publish to GitHub Packages
if: ${{ github.event.inputs.test_level == 'github_packages' }}
run: |
cd ${{ steps.config.outputs.output_dir }}
# Configure for GitHub Packages
npm config set registry https://npm.pkg.github.com
npm config set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
# Publish the test package
npm publish
PACKAGE_NAME=$(cat package.json | grep '"name"' | cut -d'"' -f4)
PACKAGE_VERSION=$(cat package.json | grep '"version"' | cut -d'"' -f4)
echo "✅ Published test package to GitHub Packages"
echo "📦 Package: $PACKAGE_NAME@$PACKAGE_VERSION"
echo "🔗 View at: https://github.com/mxenabled/mx-platform-node/packages"
- name: Slack notification
if: always()
uses: ravsamhq/notify-slack-action@v2
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 }}