-
Notifications
You must be signed in to change notification settings - Fork 3
119 lines (112 loc) · 4.75 KB
/
generate.yml
File metadata and controls
119 lines (112 loc) · 4.75 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
name: Generate
on:
workflow_dispatch:
inputs:
api_version:
description: "API version to generate"
required: true
type: choice
options:
- v20111101
- v20250224
version_bump:
description: "Version bump type"
required: true
default: "skip"
type: choice
options:
- skip
- minor
- patch
jobs:
Validate:
runs-on: ubuntu-latest
outputs:
config_file: ${{ steps.validate.outputs.config_file }}
spec_url: ${{ steps.validate.outputs.spec_url }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Validate configuration
id: validate
run: |
API_VERSION="${{ github.event.inputs.api_version }}"
CONFIG_FILE="openapi/config-${API_VERSION}.yml"
SPEC_URL="https://raw.githubusercontent.com/mxenabled/openapi/master/openapi/${API_VERSION}.yml"
ruby .github/config_validator.rb "$CONFIG_FILE" "$API_VERSION"
echo "✅ Validation passed"
echo "config_file=$CONFIG_FILE" >> $GITHUB_OUTPUT
echo "spec_url=$SPEC_URL" >> $GITHUB_OUTPUT
Generate:
runs-on: ubuntu-latest
needs: Validate
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Bump version
id: bump_version
run: |
if [ "${{ github.event.inputs.version_bump }}" != "skip" ]; then
NEW_VERSION=$(ruby .github/version.rb ${{ github.event.inputs.version_bump }} ${{ needs.Validate.outputs.config_file }})
else
NEW_VERSION=$(jq -r '.version' ./${{ github.event.inputs.api_version }}/package.json 2>/dev/null || grep 'npmVersion' ${{ needs.Validate.outputs.config_file }} | cut -d':' -f2 | tr -d ' ')
fi
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📦 Version: $NEW_VERSION"
- name: Clean repo
run: ruby .github/clean.rb ${{ github.event.inputs.api_version }}
- name: Copy generator ignore rules
run: |
mkdir -p ./${{ github.event.inputs.api_version }}/
cp .openapi-generator-ignore ./${{ github.event.inputs.api_version }}/
- name: Install openapi-generator-cli and Generate SDK
run: npm install @openapitools/openapi-generator-cli -g
- name: Generate SDK
run: |
openapi-generator-cli generate \
-i ${{ needs.Validate.outputs.spec_url }} \
-g typescript-axios \
-c ${{ needs.Validate.outputs.config_file }} \
-t ./openapi/templates \
-o ./${{ github.event.inputs.api_version }}
- name: Update CHANGELOG
run: ruby .github/changelog_manager.rb ${{ github.event.inputs.api_version }}
- name: Copy documentation
run: |
cp LICENSE ./${{ github.event.inputs.api_version }}/LICENSE
cp CHANGELOG.md ./${{ github.event.inputs.api_version }}/CHANGELOG.md
cp MIGRATION.md ./${{ github.event.inputs.api_version }}/MIGRATION.md
- name: Create branch
run: git checkout -b "sdk/generate-api-${{ github.event.inputs.api_version }}-${{ steps.bump_version.outputs.version }}"
- name: Create commit
run: |
git config user.name "devexperience"
git config user.email "devexperience@mx.com"
git add .
git commit -m "Manually Generated API ${{ github.event.inputs.api_version }} SDK for version ${{ steps.bump_version.outputs.version }}
This pull request was automatically generated by generate GitHub Action.
API Version: ${{ github.event.inputs.api_version }}
SDK Version: ${{ steps.bump_version.outputs.version }}
Version Bump: ${{ github.event.inputs.version_bump }}
${{ github.event.inputs.version_bump == 'skip' && '⚠️ NO VERSION BUMP - This is a review-only generation for validation before release.' || '' }}"
git push -u origin "sdk/generate-api-${{ github.event.inputs.api_version }}-${{ steps.bump_version.outputs.version }}"
- name: Create PR
run: gh pr create -f
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Slack notification
uses: ravsamhq/notify-slack-action@v2
if: always()
with:
status: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: "{repo}: {workflow} workflow"
message_format: "{emoji} *<{workflow_url}|{workflow}>* {status_message} in <{repo_url}|{repo}>"
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}