-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (130 loc) · 5.65 KB
/
test-multi-version.yml
File metadata and controls
152 lines (130 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 }}