Skip to content

TEST: Auto Generate and Push #5

TEST: Auto Generate and Push

TEST: Auto Generate and Push #5

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