-
Notifications
You must be signed in to change notification settings - Fork 3
303 lines (254 loc) Β· 11.7 KB
/
test-auto-generate.yml
File metadata and controls
303 lines (254 loc) Β· 11.7 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: "TEST: Auto Generate and Push"
# ============================================================================
# SANDBOX TEST WORKFLOW - Phase 8A
# Mirrors openapi-generate-and-push.yml but uses test configs, test directories,
# and pushes to a test branch. Incorporates fixes for Issues 2, 5, and 6.
# DELETE THIS FILE after Phase 8A testing is complete.
# ============================================================================
on:
workflow_dispatch:
inputs:
payload_json:
description: 'JSON payload (e.g., {"api_versions":"v20111101","version":"minor","commit_sha":"abc123"})'
required: true
type: string
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
versions_to_generate: ${{ steps.parse-payload.outputs.versions_to_generate }}
steps:
- name: Parse payload
id: parse-payload
run: |
echo "π Raw payload: ${{ github.event.inputs.payload_json }}"
VERSIONS=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.api_versions // "v20111101"')
echo "π Parsed versions: $VERSIONS"
echo "versions_to_generate=$VERSIONS" >> $GITHUB_OUTPUT
- name: Set up matrix
id: set-matrix
run: |
VERSIONS="${{ steps.parse-payload.outputs.versions_to_generate }}"
echo "π Versions to generate: $VERSIONS"
# Build matrix JSON β uses TEST config files
MATRIX_JSON='{"include":['
FIRST=true
for VERSION in $(echo $VERSIONS | tr ',' ' '); do
if [ "$FIRST" = false ]; then
MATRIX_JSON+=','
fi
FIRST=false
# Map version to TEST config file (not production configs)
if [ "$VERSION" = "v20111101" ]; then
CONFIG="openapi/test-config-v20111101.yml"
elif [ "$VERSION" = "v20250224" ]; then
CONFIG="openapi/test-config-v20250224.yml"
fi
MATRIX_JSON+="{\"api_version\":\"$VERSION\",\"config_file\":\"$CONFIG\"}"
done
MATRIX_JSON+=']}'
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
echo "π Matrix: $MATRIX_JSON"
Generate:
runs-on: ubuntu-latest
needs: Setup
strategy:
matrix: ${{ fromJson(needs.Setup.outputs.matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
ref: test-auto-generate
- uses: actions/setup-node@v3
with:
node-version: "20"
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Validate configuration
run: |
# Skip config_validator.rb for test configs since it validates major version
# against SUPPORTED_VERSIONS map (98/99 would fail). Just validate file exists.
echo "π Validating test config: ${{ matrix.config_file }}"
if [ ! -f "${{ matrix.config_file }}" ]; then
echo "β Config file not found: ${{ matrix.config_file }}"
exit 1
fi
echo "β
Config file exists"
cat "${{ matrix.config_file }}"
- name: Bump version
id: bump_version
run: |
# Parse version bump type from payload
VERSION=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.version // "patch"')
echo "π VERSION parsed as: $VERSION"
# *** ISSUE 2 FIX: $VERSION unquoted (was "$VERSION" in production) ***
NEW_VERSION=$(ruby .github/version.rb $VERSION ${{ matrix.config_file }})
echo "π NEW_VERSION returned: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
# Verify the config was actually updated
echo "π Config file after bump:"
cat ${{ matrix.config_file }}
- name: Clean test directory
run: |
# Use clean.rb with test- prefix directory
ruby .github/clean.rb test-${{ matrix.api_version }}
- name: Copy generator ignore rules
run: |
mkdir -p ./test-${{ matrix.api_version }}/
cp .openapi-generator-ignore ./test-${{ matrix.api_version }}/
- name: Install openapi-generator-cli
run: npm install @openapitools/openapi-generator-cli -g
- name: Generate SDK
run: |
# Parse commit_sha from payload
COMMIT_SHA=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.commit_sha // "master"')
echo "π Using commit SHA: $COMMIT_SHA"
# Generate into test- prefixed directory
openapi-generator-cli generate \
-i https://raw.githubusercontent.com/mxenabled/openapi/$COMMIT_SHA/openapi/${{ matrix.api_version }}.yml \
-g typescript-axios \
-c ${{ matrix.config_file }} \
-t ./openapi/templates \
-o ./test-${{ matrix.api_version }}
echo "π Generated files in test-${{ matrix.api_version }}/:"
ls -la ./test-${{ matrix.api_version }}/
- name: Upload SDK artifacts
uses: actions/upload-artifact@v4
with:
name: test-generated-${{ matrix.api_version }}
path: ./test-${{ matrix.api_version }}
- name: Upload config artifact (for version bump persistence)
uses: actions/upload-artifact@v4
with:
name: test-config-${{ matrix.api_version }}
path: ${{ matrix.config_file }}
Process-and-Push:
runs-on: ubuntu-latest
needs: [Setup, Generate]
steps:
- uses: actions/checkout@v3
with:
ref: test-auto-generate
fetch-depth: 0
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./test-generated
- name: Restore config files from artifacts
run: |
echo "π Restoring config files from artifacts..."
if [ -d "./test-generated/test-config-v20111101" ]; then
echo "π Restoring test-config-v20111101.yml"
cp ./test-generated/test-config-v20111101/* ./openapi/test-config-v20111101.yml 2>/dev/null || echo " (file not found in artifact)"
fi
if [ -d "./test-generated/test-config-v20250224" ]; then
echo "π Restoring test-config-v20250224.yml"
cp ./test-generated/test-config-v20250224/* ./openapi/test-config-v20250224.yml 2>/dev/null || echo " (file not found in artifact)"
fi
echo "π Config files after restoration:"
cat ./openapi/test-config-v20111101.yml 2>/dev/null || echo " test-config-v20111101.yml not available"
echo "---"
cat ./openapi/test-config-v20250224.yml 2>/dev/null || echo " test-config-v20250224.yml not available"
# Clean up config artifact directories so they don't get committed
rm -rf ./test-generated/test-config-v20111101 ./test-generated/test-config-v20250224
echo "π Cleaned up config artifact directories"
- name: Move generated files and track versions
id: track_versions
run: |
echo "π Downloaded artifacts:"
ls -la ./test-generated/
GENERATED_VERSIONS=""
for dir in ./test-generated/test-generated-*; do
VERSION=$(basename "$dir" | sed 's/test-generated-//')
TARGET_DIR="./test-$VERSION"
echo "π Processing: $dir β $TARGET_DIR"
echo "π Target directory exists? $([ -d "$TARGET_DIR" ] && echo 'YES' || echo 'NO')"
# *** ISSUE 5 FIX: Remove target directory before moving ***
# Without this, mv places the source INSIDE the existing directory
# as a subdirectory instead of replacing its contents
if [ -d "$TARGET_DIR" ]; then
echo "π Removing existing target: $TARGET_DIR"
rm -rf "$TARGET_DIR"
fi
mv "$dir" "$TARGET_DIR"
GENERATED_VERSIONS="$GENERATED_VERSIONS $VERSION"
echo "π Files now in $TARGET_DIR:"
ls -la "$TARGET_DIR/"
# Verify no nested subdirectory was created (Issue 5 validation)
if [ -d "$TARGET_DIR/test-generated-$VERSION" ]; then
echo "β ISSUE 5 NOT FIXED: Found nested subdirectory $TARGET_DIR/test-generated-$VERSION"
exit 1
else
echo "β
ISSUE 5 VALIDATED: No nested subdirectory created"
fi
done
echo "generated_versions=$GENERATED_VERSIONS" >> $GITHUB_OUTPUT
echo "π All generated versions: $GENERATED_VERSIONS"
- name: Update TEST-CHANGELOG
run: |
GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}"
if [ -z "$GENERATED_VERSIONS" ]; then
echo "No versions generated, skipping changelog update"
exit 0
fi
# Use changelog_manager.rb pointed at TEST-CHANGELOG.md
# Pass real version names so changelog_manager validates and runs
# exactly like production. It reads from the real v20111101/package.json
# (not test-v20111101/) β the version number won't match the test config,
# but the workflow mechanics are what we're validating here.
cp CHANGELOG.md CHANGELOG.md.bak
cp TEST-CHANGELOG.md CHANGELOG.md
VERSIONS_CSV=$(echo "$GENERATED_VERSIONS" | xargs | tr ' ' ',')
echo "π Updating TEST-CHANGELOG for versions: $VERSIONS_CSV"
ruby .github/changelog_manager.rb "$VERSIONS_CSV"
cp CHANGELOG.md TEST-CHANGELOG.md
mv CHANGELOG.md.bak CHANGELOG.md
echo "π TEST-CHANGELOG.md after update:"
head -30 TEST-CHANGELOG.md
- name: Copy documentation to test directories
run: |
GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}"
for VERSION in $GENERATED_VERSIONS; do
cp LICENSE "./test-$VERSION/LICENSE"
cp TEST-CHANGELOG.md "./test-$VERSION/CHANGELOG.md"
cp MIGRATION.md "./test-$VERSION/MIGRATION.md"
done
- name: Create commit and push to test branch
run: |
git config user.name "devexperience"
git config user.email "devexperience@mx.com"
git add .
git status
git commit -m "TEST: Generated SDK versions: ${{ needs.Setup.outputs.versions_to_generate }}
This commit was automatically created by the test-auto-generate workflow.
Payload: ${{ github.event.inputs.payload_json }}"
git push origin test-auto-generate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate access token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.PAPI_SDK_APP_ID }}
installation_id: ${{ secrets.PAPI_SDK_INSTALLATION_ID }}
private_key: ${{ secrets.PAPI_SDK_PRIVATE_KEY }}
- name: Trigger test-on-push workflow
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ steps.generate_token.outputs.token }}
event-type: test_push_to_branch
client-payload: '{"versions": "${{ needs.Setup.outputs.versions_to_generate }}"}'
- name: Summary
run: |
echo "============================================"
echo "π TEST AUTO-GENERATE SUMMARY"
echo "============================================"
echo "Versions generated: ${{ needs.Setup.outputs.versions_to_generate }}"
echo "Pushed to branch: test-auto-generate"
echo "Triggered: test-on-push workflow via repository_dispatch"
echo "============================================"