|
| 1 | +name: "TEST: Auto Generate and Push" |
| 2 | + |
| 3 | +# ============================================================================ |
| 4 | +# SANDBOX TEST WORKFLOW - Phase 8A |
| 5 | +# Mirrors openapi-generate-and-push.yml but uses test configs, test directories, |
| 6 | +# and pushes to a test branch. Incorporates fixes for Issues 2, 5, and 6. |
| 7 | +# DELETE THIS FILE after Phase 8A testing is complete. |
| 8 | +# ============================================================================ |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + payload_json: |
| 14 | + description: 'JSON payload (e.g., {"api_versions":"v20111101","version":"minor","commit_sha":"abc123"})' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + Setup: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 23 | + versions_to_generate: ${{ steps.parse-payload.outputs.versions_to_generate }} |
| 24 | + steps: |
| 25 | + - name: Parse payload |
| 26 | + id: parse-payload |
| 27 | + run: | |
| 28 | + echo "📋 Raw payload: ${{ github.event.inputs.payload_json }}" |
| 29 | + VERSIONS=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.api_versions // "v20111101"') |
| 30 | + echo "📋 Parsed versions: $VERSIONS" |
| 31 | + echo "versions_to_generate=$VERSIONS" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + - name: Set up matrix |
| 34 | + id: set-matrix |
| 35 | + run: | |
| 36 | + VERSIONS="${{ steps.parse-payload.outputs.versions_to_generate }}" |
| 37 | + echo "📋 Versions to generate: $VERSIONS" |
| 38 | +
|
| 39 | + # Build matrix JSON — uses TEST config files |
| 40 | + MATRIX_JSON='{"include":[' |
| 41 | + FIRST=true |
| 42 | +
|
| 43 | + for VERSION in $(echo $VERSIONS | tr ',' ' '); do |
| 44 | + if [ "$FIRST" = false ]; then |
| 45 | + MATRIX_JSON+=',' |
| 46 | + fi |
| 47 | + FIRST=false |
| 48 | +
|
| 49 | + # Map version to TEST config file (not production configs) |
| 50 | + if [ "$VERSION" = "v20111101" ]; then |
| 51 | + CONFIG="openapi/test-config-v20111101.yml" |
| 52 | + elif [ "$VERSION" = "v20250224" ]; then |
| 53 | + CONFIG="openapi/test-config-v20250224.yml" |
| 54 | + fi |
| 55 | +
|
| 56 | + MATRIX_JSON+="{\"api_version\":\"$VERSION\",\"config_file\":\"$CONFIG\"}" |
| 57 | + done |
| 58 | +
|
| 59 | + MATRIX_JSON+=']}' |
| 60 | + echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT |
| 61 | + echo "📋 Matrix: $MATRIX_JSON" |
| 62 | +
|
| 63 | + Generate: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: Setup |
| 66 | + strategy: |
| 67 | + matrix: ${{ fromJson(needs.Setup.outputs.matrix) }} |
| 68 | + fail-fast: false |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@v3 |
| 71 | + - uses: actions/setup-node@v3 |
| 72 | + with: |
| 73 | + node-version: "20" |
| 74 | + - uses: ruby/setup-ruby@v1 |
| 75 | + with: |
| 76 | + ruby-version: 3.1 |
| 77 | + |
| 78 | + - name: Validate configuration |
| 79 | + run: | |
| 80 | + # Skip config_validator.rb for test configs since it validates major version |
| 81 | + # against SUPPORTED_VERSIONS map (98/99 would fail). Just validate file exists. |
| 82 | + echo "📋 Validating test config: ${{ matrix.config_file }}" |
| 83 | + if [ ! -f "${{ matrix.config_file }}" ]; then |
| 84 | + echo "❌ Config file not found: ${{ matrix.config_file }}" |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + echo "✅ Config file exists" |
| 88 | + cat "${{ matrix.config_file }}" |
| 89 | +
|
| 90 | + - name: Bump version |
| 91 | + id: bump_version |
| 92 | + run: | |
| 93 | + # Parse version bump type from payload |
| 94 | + VERSION=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.version // "patch"') |
| 95 | + echo "📋 VERSION parsed as: $VERSION" |
| 96 | +
|
| 97 | + # *** ISSUE 2 FIX: $VERSION unquoted (was "$VERSION" in production) *** |
| 98 | + NEW_VERSION=$(ruby .github/version.rb $VERSION ${{ matrix.config_file }}) |
| 99 | + echo "📋 NEW_VERSION returned: $NEW_VERSION" |
| 100 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 101 | +
|
| 102 | + # Verify the config was actually updated |
| 103 | + echo "📋 Config file after bump:" |
| 104 | + cat ${{ matrix.config_file }} |
| 105 | +
|
| 106 | + - name: Clean test directory |
| 107 | + run: | |
| 108 | + # Use clean.rb with test- prefix directory |
| 109 | + ruby .github/clean.rb test-${{ matrix.api_version }} |
| 110 | +
|
| 111 | + - name: Copy generator ignore rules |
| 112 | + run: | |
| 113 | + mkdir -p ./test-${{ matrix.api_version }}/ |
| 114 | + cp .openapi-generator-ignore ./test-${{ matrix.api_version }}/ |
| 115 | +
|
| 116 | + - name: Install openapi-generator-cli |
| 117 | + run: npm install @openapitools/openapi-generator-cli -g |
| 118 | + |
| 119 | + - name: Generate SDK |
| 120 | + run: | |
| 121 | + # Parse commit_sha from payload |
| 122 | + COMMIT_SHA=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.commit_sha // "master"') |
| 123 | + echo "📋 Using commit SHA: $COMMIT_SHA" |
| 124 | +
|
| 125 | + # Generate into test- prefixed directory |
| 126 | + openapi-generator-cli generate \ |
| 127 | + -i https://raw.githubusercontent.com/mxenabled/openapi/$COMMIT_SHA/openapi/${{ matrix.api_version }}.yml \ |
| 128 | + -g typescript-axios \ |
| 129 | + -c ${{ matrix.config_file }} \ |
| 130 | + -t ./openapi/templates \ |
| 131 | + -o ./test-${{ matrix.api_version }} |
| 132 | +
|
| 133 | + echo "📋 Generated files in test-${{ matrix.api_version }}/:" |
| 134 | + ls -la ./test-${{ matrix.api_version }}/ |
| 135 | +
|
| 136 | + - name: Upload artifacts |
| 137 | + uses: actions/upload-artifact@v4 |
| 138 | + with: |
| 139 | + name: test-generated-${{ matrix.api_version }} |
| 140 | + path: ./test-${{ matrix.api_version }} |
| 141 | + |
| 142 | + Process-and-Push: |
| 143 | + runs-on: ubuntu-latest |
| 144 | + needs: [Setup, Generate] |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@v3 |
| 147 | + with: |
| 148 | + ref: test-auto-generate |
| 149 | + fetch-depth: 0 |
| 150 | + |
| 151 | + - uses: ruby/setup-ruby@v1 |
| 152 | + with: |
| 153 | + ruby-version: 3.1 |
| 154 | + |
| 155 | + - name: Download all artifacts |
| 156 | + uses: actions/download-artifact@v4 |
| 157 | + with: |
| 158 | + path: ./test-generated |
| 159 | + |
| 160 | + - name: Move generated files and track versions |
| 161 | + id: track_versions |
| 162 | + run: | |
| 163 | + echo "📋 Downloaded artifacts:" |
| 164 | + ls -la ./test-generated/ |
| 165 | +
|
| 166 | + GENERATED_VERSIONS="" |
| 167 | +
|
| 168 | + for dir in ./test-generated/test-generated-*; do |
| 169 | + VERSION=$(basename "$dir" | sed 's/test-generated-//') |
| 170 | + TARGET_DIR="./test-$VERSION" |
| 171 | +
|
| 172 | + echo "📋 Processing: $dir → $TARGET_DIR" |
| 173 | + echo "📋 Target directory exists? $([ -d "$TARGET_DIR" ] && echo 'YES' || echo 'NO')" |
| 174 | +
|
| 175 | + # *** ISSUE 5 FIX: Remove target directory before moving *** |
| 176 | + # Without this, mv places the source INSIDE the existing directory |
| 177 | + # as a subdirectory instead of replacing its contents |
| 178 | + if [ -d "$TARGET_DIR" ]; then |
| 179 | + echo "📋 Removing existing target: $TARGET_DIR" |
| 180 | + rm -rf "$TARGET_DIR" |
| 181 | + fi |
| 182 | +
|
| 183 | + mv "$dir" "$TARGET_DIR" |
| 184 | + GENERATED_VERSIONS="$GENERATED_VERSIONS $VERSION" |
| 185 | +
|
| 186 | + echo "📋 Files now in $TARGET_DIR:" |
| 187 | + ls -la "$TARGET_DIR/" |
| 188 | +
|
| 189 | + # Verify no nested subdirectory was created (Issue 5 validation) |
| 190 | + if [ -d "$TARGET_DIR/test-generated-$VERSION" ]; then |
| 191 | + echo "❌ ISSUE 5 NOT FIXED: Found nested subdirectory $TARGET_DIR/test-generated-$VERSION" |
| 192 | + exit 1 |
| 193 | + else |
| 194 | + echo "✅ ISSUE 5 VALIDATED: No nested subdirectory created" |
| 195 | + fi |
| 196 | + done |
| 197 | +
|
| 198 | + echo "generated_versions=$GENERATED_VERSIONS" >> $GITHUB_OUTPUT |
| 199 | + echo "📋 All generated versions: $GENERATED_VERSIONS" |
| 200 | +
|
| 201 | + - name: Update TEST-CHANGELOG |
| 202 | + run: | |
| 203 | + GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}" |
| 204 | +
|
| 205 | + if [ -z "$GENERATED_VERSIONS" ]; then |
| 206 | + echo "No versions generated, skipping changelog update" |
| 207 | + exit 0 |
| 208 | + fi |
| 209 | +
|
| 210 | + # Use changelog_manager.rb but pointed at TEST-CHANGELOG.md |
| 211 | + # We need to temporarily swap CHANGELOG.md for the test |
| 212 | + # Back up real CHANGELOG, replace with test, run manager, restore |
| 213 | + cp CHANGELOG.md CHANGELOG.md.bak |
| 214 | + cp TEST-CHANGELOG.md CHANGELOG.md |
| 215 | +
|
| 216 | + VERSIONS_CSV=$(echo "$GENERATED_VERSIONS" | xargs | tr ' ' ',') |
| 217 | + echo "📋 Updating TEST-CHANGELOG for versions: $VERSIONS_CSV" |
| 218 | + ruby .github/changelog_manager.rb "$VERSIONS_CSV" |
| 219 | +
|
| 220 | + # Move updated changelog to TEST-CHANGELOG and restore real one |
| 221 | + cp CHANGELOG.md TEST-CHANGELOG.md |
| 222 | + mv CHANGELOG.md.bak CHANGELOG.md |
| 223 | +
|
| 224 | + echo "📋 TEST-CHANGELOG.md after update:" |
| 225 | + head -30 TEST-CHANGELOG.md |
| 226 | +
|
| 227 | + - name: Copy documentation to test directories |
| 228 | + run: | |
| 229 | + GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}" |
| 230 | +
|
| 231 | + for VERSION in $GENERATED_VERSIONS; do |
| 232 | + cp LICENSE "./test-$VERSION/LICENSE" |
| 233 | + cp TEST-CHANGELOG.md "./test-$VERSION/CHANGELOG.md" |
| 234 | + cp MIGRATION.md "./test-$VERSION/MIGRATION.md" |
| 235 | + done |
| 236 | +
|
| 237 | + - name: Create commit and push to test branch |
| 238 | + run: | |
| 239 | + git config user.name "devexperience" |
| 240 | + git config user.email "devexperience@mx.com" |
| 241 | + git add . |
| 242 | + git status |
| 243 | + git commit -m "TEST: Generated SDK versions: ${{ needs.Setup.outputs.versions_to_generate }} |
| 244 | +
|
| 245 | + This commit was automatically created by the test-auto-generate workflow. |
| 246 | + Payload: ${{ github.event.inputs.payload_json }}" |
| 247 | + git push origin test-auto-generate |
| 248 | + env: |
| 249 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 250 | + |
| 251 | + - name: Generate access token |
| 252 | + id: generate_token |
| 253 | + uses: tibdex/github-app-token@v1 |
| 254 | + with: |
| 255 | + app_id: ${{ secrets.PAPI_SDK_APP_ID }} |
| 256 | + installation_id: ${{ secrets.PAPI_SDK_INSTALLATION_ID }} |
| 257 | + private_key: ${{ secrets.PAPI_SDK_PRIVATE_KEY }} |
| 258 | + |
| 259 | + - name: Trigger test-on-push workflow |
| 260 | + uses: peter-evans/repository-dispatch@v2 |
| 261 | + with: |
| 262 | + token: ${{ steps.generate_token.outputs.token }} |
| 263 | + event-type: test_push_to_branch |
| 264 | + |
| 265 | + - name: Summary |
| 266 | + run: | |
| 267 | + echo "============================================" |
| 268 | + echo "📋 TEST AUTO-GENERATE SUMMARY" |
| 269 | + echo "============================================" |
| 270 | + echo "Versions generated: ${{ needs.Setup.outputs.versions_to_generate }}" |
| 271 | + echo "Pushed to branch: test-auto-generate" |
| 272 | + echo "Triggered: test-on-push workflow via repository_dispatch" |
| 273 | + echo "============================================" |
0 commit comments