Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 273 additions & 0 deletions .github/workflows/test-auto-generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
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
- 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 artifacts
uses: actions/upload-artifact@v4
with:
name: test-generated-${{ matrix.api_version }}
path: ./test-${{ matrix.api_version }}

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: 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 but pointed at TEST-CHANGELOG.md
# We need to temporarily swap CHANGELOG.md for the test
# Back up real CHANGELOG, replace with test, run manager, restore
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"

# Move updated changelog to TEST-CHANGELOG and restore real one
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

- 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 "============================================"
Loading