-
Notifications
You must be signed in to change notification settings - Fork 3
160 lines (144 loc) · 6.01 KB
/
openapi-generate-and-push.yml
File metadata and controls
160 lines (144 loc) · 6.01 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
name: "OpenAPI: Automated Generate and Push"
on:
repository_dispatch:
types: [generate_publish_release]
workflow_dispatch:
inputs:
payload_json:
description: 'JSON payload (e.g., {"api_versions":"v20111101","version":"patch","commit_sha":"abc123"})'
required: false
type: string
env:
# Parse payload from workflow_dispatch if provided, otherwise empty object
PARSED_PAYLOAD: ${{ fromJson(github.event.inputs.payload_json || '{}') }}
# Default to v20111101 only for backwards compatibility
# When openapi repo sends api_versions, use that instead
VERSIONS_TO_GENERATE: ${{ github.event.client_payload.api_versions || env.PARSED_PAYLOAD.api_versions || 'v20111101' }}
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set up matrix
id: set-matrix
run: |
VERSIONS="${{ env.VERSIONS_TO_GENERATE }}"
echo "Versions to generate: $VERSIONS"
# Build matrix JSON
MATRIX_JSON='{"include":['
FIRST=true
for VERSION in $(echo $VERSIONS | tr ',' ' '); do
if [ "$FIRST" = false ]; then
MATRIX_JSON+=','
fi
FIRST=false
# Map version to config file and major version
if [ "$VERSION" = "v20111101" ]; then
CONFIG="openapi/config-v20111101.yml"
elif [ "$VERSION" = "v20250224" ]; then
CONFIG="openapi/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: ruby .github/config_validator.rb "${{ matrix.config_file }}" "${{ matrix.api_version }}"
- name: Bump version
id: bump_version
run: |
NEW_VERSION=$(ruby .github/version.rb ${{ github.event.client_payload.version || env.PARSED_PAYLOAD.version || 'patch' }} ${{ matrix.config_file }})
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Clean repo
run: ruby .github/clean.rb ${{ matrix.api_version }}
- name: Copy generator ignore rules
run: |
mkdir -p ./${{ matrix.api_version }}/
cp .openapi-generator-ignore ./${{ matrix.api_version }}/
- name: Install openapi-generator-cli
run: npm install @openapitools/openapi-generator-cli -g
- name: Generate SDK
run: |
# Versioned spec URLs with commit SHA to avoid GitHub CDN cache race condition
# Problem: GitHub's raw.githubusercontent.com CDN caches files for 5 minutes
# If openapi repo commits and immediately triggers this workflow, CDN may serve stale spec
# Using commit SHA in URL to bypass cache and guarantee correct spec version
# Falls back to 'master' if openapi doesn't send commit_sha
openapi-generator-cli generate \
-i https://raw.githubusercontent.com/mxenabled/openapi/${{ github.event.client_payload.commit_sha || env.PARSED_PAYLOAD.commit_sha || 'master' }}/openapi/${{ matrix.api_version }}.yml \
-g typescript-axios \
-c ${{ matrix.config_file }} \
-t ./openapi/templates \
-o ./${{ matrix.api_version }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: generated-${{ matrix.api_version }}
path: ./${{ matrix.api_version }}
Process-and-Push:
runs-on: ubuntu-latest
needs: [Setup, Generate]
steps:
- uses: actions/checkout@v3
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./generated
- name: Move generated files and track versions
id: track_versions
run: |
GENERATED_VERSIONS=""
for dir in ./generated/generated-*; do
VERSION=$(basename "$dir" | sed 's/generated-//')
mv "$dir" "./$VERSION"
GENERATED_VERSIONS="$GENERATED_VERSIONS $VERSION"
done
echo "generated_versions=$GENERATED_VERSIONS" >> $GITHUB_OUTPUT
- name: Update CHANGELOG
run: |
GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}"
# Only update if something was generated
if [ -z "$GENERATED_VERSIONS" ]; then
echo "No versions generated, skipping changelog update"
exit 0
fi
# Convert space-separated versions to comma-separated for changelog_manager.rb
VERSIONS_CSV=$(echo "$GENERATED_VERSIONS" | tr ' ' ',')
ruby .github/changelog_manager.rb "$VERSIONS_CSV"
- name: Copy documentation
run: |
GENERATED_VERSIONS="${{ steps.track_versions.outputs.generated_versions }}"
for VERSION in $GENERATED_VERSIONS; do
cp LICENSE "./$VERSION/LICENSE"
cp CHANGELOG.md "./$VERSION/CHANGELOG.md"
cp MIGRATION.md "./$VERSION/MIGRATION.md"
done
- name: Checkout master
run: git checkout master
- name: Create commit
run: |
git config user.name "devexperience"
git config user.email "devexperience@mx.com"
git add .
git commit -m "Generated SDK versions: ${{ env.VERSIONS_TO_GENERATE }}
This commit was automatically created by a GitHub Action."
- name: Push to master
run: git push origin master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}