@@ -3,12 +3,6 @@ name: "OpenAPI: Automated Generate and Push"
33on :
44 repository_dispatch :
55 types : [generate_publish_release]
6- workflow_dispatch :
7- inputs :
8- payload_json :
9- description : ' JSON payload (e.g., {"api_versions":"v20111101","version":"patch","commit_sha":"abc123"})'
10- required : false
11- type : string
126
137jobs :
148 Setup :
2014 - name : Parse payload
2115 id : parse-payload
2216 run : |
23- # Parse workflow_dispatch payload if provided, otherwise use repository_dispatch payload
24- if [ -n "${{ github.event.inputs.payload_json }}" ]; then
25- VERSIONS=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.api_versions // "v20111101"')
26- else
27- VERSIONS="${{ github.event.client_payload.api_versions || 'v20111101' }}"
28- fi
17+ VERSIONS="${{ github.event.client_payload.api_versions || 'v20111101' }}"
2918 echo "versions_to_generate=$VERSIONS" >> $GITHUB_OUTPUT
3019
3120 - name : Set up matrix
7766 - name : Bump version
7867 id : bump_version
7968 run : |
80- # Parse version from workflow_dispatch or repository_dispatch
81- if [ -n "${{ github.event.inputs.payload_json }}" ]; then
82- VERSION=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.version // "patch"')
83- else
84- VERSION="${{ github.event.client_payload.version || 'patch' }}"
85- fi
86- NEW_VERSION=$(ruby .github/version.rb "$VERSION" ${{ matrix.config_file }})
69+ VERSION="${{ github.event.client_payload.version || 'patch' }}"
70+ NEW_VERSION=$(ruby .github/version.rb $VERSION ${{ matrix.config_file }})
8771 echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
8872 - name : Clean repo
8973 run : ruby .github/clean.rb ${{ matrix.api_version }}
9579 run : npm install @openapitools/openapi-generator-cli -g
9680 - name : Generate SDK
9781 run : |
98- # Parse commit_sha from workflow_dispatch or repository_dispatch
99- if [ -n "${{ github.event.inputs.payload_json }}" ]; then
100- COMMIT_SHA=$(echo '${{ github.event.inputs.payload_json }}' | jq -r '.commit_sha // "master"')
101- else
102- COMMIT_SHA="${{ github.event.client_payload.commit_sha || 'master' }}"
103- fi
82+ COMMIT_SHA="${{ github.event.client_payload.commit_sha || 'master' }}"
10483
10584 # Versioned spec URLs with commit SHA to avoid GitHub CDN cache race condition
10685 # Problem: GitHub's raw.githubusercontent.com CDN caches files for 5 minutes
@@ -113,11 +92,16 @@ jobs:
11392 -c ${{ matrix.config_file }} \
11493 -t ./openapi/templates \
11594 -o ./${{ matrix.api_version }}
116- - name : Upload artifacts
95+ - name : Upload SDK artifacts
11796 uses : actions/upload-artifact@v4
11897 with :
11998 name : generated-${{ matrix.api_version }}
12099 path : ./${{ matrix.api_version }}
100+ - name : Upload config artifact
101+ uses : actions/upload-artifact@v4
102+ with :
103+ name : config-${{ matrix.api_version }}
104+ path : ${{ matrix.config_file }}
121105
122106 Process-and-Push :
123107 runs-on : ubuntu-latest
@@ -128,13 +112,33 @@ jobs:
128112 uses : actions/download-artifact@v4
129113 with :
130114 path : ./generated
115+ - name : Restore config files from artifacts
116+ run : |
117+ # Config files are bumped in the Generate job (separate runner).
118+ # Restore them here so the version bump persists in the commit.
119+ for dir in ./generated/config-*; do
120+ [ -d "$dir" ] || continue
121+ VERSION=$(basename "$dir" | sed 's/config-//')
122+ CONFIG_FILE="openapi/config-${VERSION}.yml"
123+ cp "$dir"/* "./$CONFIG_FILE" 2>/dev/null || echo "Config not found in $dir"
124+ echo "Restored $CONFIG_FILE"
125+ done
126+
127+ # Clean up config artifact directories so they don't get committed
128+ rm -rf ./generated/config-*
131129 - name : Move generated files and track versions
132130 id : track_versions
133131 run : |
134132 GENERATED_VERSIONS=""
135133
136134 for dir in ./generated/generated-*; do
137135 VERSION=$(basename "$dir" | sed 's/generated-//')
136+
137+ # Remove target directory before moving to prevent nesting
138+ if [ -d "./$VERSION" ]; then
139+ rm -rf "./$VERSION"
140+ fi
141+
138142 mv "$dir" "./$VERSION"
139143 GENERATED_VERSIONS="$GENERATED_VERSIONS $VERSION"
140144 done
@@ -170,9 +174,9 @@ jobs:
170174 git config user.name "devexperience"
171175 git config user.email "devexperience@mx.com"
172176 git add .
173- git commit -m "Generated SDK versions: ${{ needs.Setup.outputs.versions_to_generate }}
177+ git commit -m "Automated Generated SDK versions: ${{ needs.Setup.outputs.versions_to_generate }}
174178
175- This commit was automatically created by a GitHub Action."
179+ This commit was automatically created by openapi-generate-and-push GitHub Action."
176180 - name : Push to master
177181 run : git push origin master
178182 env :
0 commit comments