-
Notifications
You must be signed in to change notification settings - Fork 7
178 lines (162 loc) · 6.99 KB
/
versioned-sdk-dispatch.yml
File metadata and controls
178 lines (162 loc) · 6.99 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Versioned SDK Dispatch
# Dispatches repository_dispatch to opted-in SDK repos when versioned OAS files change.
on:
pull_request:
types: [closed]
paths:
- 'openapi/v*.yml'
workflow_dispatch:
inputs:
version_level:
description: "Bump version"
required: true
default: "minor"
type: choice
options:
- minor
- patch
api_versions:
description: "Comma-separated API versions (e.g., v20111101,v20250224)"
required: true
type: string
jobs:
# ──────────────────────────────────────────────────
# Job: Detect which versioned OAS files changed (PR merge only)
# ──────────────────────────────────────────────────
detect-changes:
name: Detect Changed OAS Files
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
outputs:
api_versions: ${{ steps.build-versions.outputs.api_versions }}
version: ${{ steps.read-label.outputs.version }}
has_changes: ${{ steps.build-versions.outputs.has_changes }}
steps:
- uses: actions/checkout@v3
- name: Get changed versioned OAS files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: openapi/v*.yml
- name: Build api_versions from changed files
id: build-versions
run: |
CHANGED="${{ steps.changed-files.outputs.all_changed_files }}"
echo "Changed files: $CHANGED"
if [ -z "$CHANGED" ]; then
echo "No versioned OAS files changed"
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "api_versions=" >> $GITHUB_OUTPUT
exit 0
fi
# Extract version names from filenames (e.g., openapi/v20111101.yml → v20111101)
API_VERSIONS=""
for file in $CHANGED; do
# Get filename without path and extension
basename=$(basename "$file" .yml)
if [ -n "$API_VERSIONS" ]; then
API_VERSIONS="${API_VERSIONS},${basename}"
else
API_VERSIONS="${basename}"
fi
done
echo "api_versions=$API_VERSIONS" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Detected API versions: $API_VERSIONS"
- name: Read version label from PR
id: read-label
run: |
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "PR labels: $LABELS"
if echo "$LABELS" | jq -e 'map(select(. == "patch")) | length > 0' > /dev/null 2>&1; then
echo "version=patch" >> $GITHUB_OUTPUT
echo "Version label: patch"
else
# Default to minor if no patch label found
echo "version=minor" >> $GITHUB_OUTPUT
echo "Version label: minor (default)"
fi
# ──────────────────────────────────────────────────
# Job: Dispatch to opted-in SDK repos (PR merge)
# ──────────────────────────────────────────────────
dispatch:
name: Dispatch to ${{ matrix.repo }}
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
repo:
- mxenabled/mx-platform-node
# Add more repos here as they are migrated to multi-version support:
# - mxenabled/mx-platform-ruby
# - mxenabled/mx-platform-python
# - mxenabled/mx-platform-java
# - mxenabled/mx-platform-csharp
# - mxenabled/mx-platform-go
steps:
- name: Generate GitHub App token
id: app-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: Dispatch to ${{ matrix.repo }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ steps.app-token.outputs.token }}
repository: ${{ matrix.repo }}
event-type: generate_publish_release
client-payload: '{"version":"${{ needs.detect-changes.outputs.version }}","commit_sha":"${{ github.sha }}","api_versions":"${{ needs.detect-changes.outputs.api_versions }}"}'
- name: Slack notification
uses: ravsamhq/notify-slack-action@v2
if: failure()
with:
status: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: "{repo}: {workflow} workflow"
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
footer: "<{workflow_url}|View Workflow>"
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# ──────────────────────────────────────────────────
# Job: Manual dispatch (workflow_dispatch)
# ──────────────────────────────────────────────────
manual-dispatch:
name: Manual dispatch to ${{ matrix.repo }}
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
strategy:
matrix:
repo:
- mxenabled/mx-platform-node
# Add more repos here as they are migrated to multi-version support
steps:
- name: Generate GitHub App token
id: app-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: Dispatch to ${{ matrix.repo }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ steps.app-token.outputs.token }}
repository: ${{ matrix.repo }}
event-type: generate_publish_release
client-payload: '{"version":"${{ github.event.inputs.version_level }}","commit_sha":"${{ github.sha }}","api_versions":"${{ github.event.inputs.api_versions }}"}'
- name: Slack notification
uses: ravsamhq/notify-slack-action@v2
if: failure()
with:
status: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: "{repo}: {workflow} workflow"
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
footer: "<{workflow_url}|View Workflow>"
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}