-
Notifications
You must be signed in to change notification settings - Fork 2
220 lines (197 loc) · 7.56 KB
/
Copy pathbump.yml
File metadata and controls
220 lines (197 loc) · 7.56 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: Check and deploy API documentation
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
pull-requests: write
jobs:
determine-doc-ids:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
else
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
fi
echo "CHANGED_FILES<<EOF" >> $GITHUB_ENV
echo "$CHANGED_FILES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Set matrix
id: set-matrix
run: |
DOCS=()
# Check for changes in API doc folders
if echo "$CHANGED_FILES" | grep -q "^admin/"; then
DOCS+=("admin")
fi
if echo "$CHANGED_FILES" | grep -q "^cloud-controlplane/"; then
DOCS+=("cloud-controlplane")
fi
if echo "$CHANGED_FILES" | grep -q "^cloud-dataplane/"; then
DOCS+=("cloud-dataplane")
fi
if echo "$CHANGED_FILES" | grep -q "^schema-registry/"; then
DOCS+=("schema-registry")
fi
if echo "$CHANGED_FILES" | grep -q "^http-proxy/"; then
DOCS+=("http-proxy")
fi
# Check for changes in shared resources that might affect all docs
if echo "$CHANGED_FILES" | grep -q "^shared/"; then
if [ ${#DOCS[@]} -eq 0 ]; then
# If only shared files changed and no specific doc files, include all docs
DOCS+=("admin" "cloud-controlplane" "cloud-dataplane" "schema-registry" "http-proxy")
fi
fi
# If no files changed in any monitored directories, abort the workflow
if [ ${#DOCS[@]} -eq 0 ]; then
echo "No relevant files were changed. Exiting workflow."
echo "matrix={\"doc_id\":[]}" >> $GITHUB_OUTPUT
exit 0
fi
# Convert bash array to JSON array for GitHub Actions matrix
JSON_ARRAY=$(printf '"%s",' "${DOCS[@]}" | sed 's/,$//')
JSON_MATRIX="{\"doc_id\":[$JSON_ARRAY]}"
echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT
echo "Created matrix: $JSON_MATRIX"
deploy-doc:
if: ${{ github.event_name == 'push' && fromJson(needs.determine-doc-ids.outputs.matrix).doc_id[0] != null }}
needs: determine-doc-ids
name: Deploy API documentation on Bump.sh
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.determine-doc-ids.outputs.matrix)}}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determine file format
id: format
run: |
if [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" ]; then
echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" >> $GITHUB_OUTPUT
elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" ]; then
echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" >> $GITHUB_OUTPUT
else
echo "No API definition file found for ${{ matrix.doc_id }}"
exit 1
fi
- name: Determine overlays
id: overlays
run: |
OVERLAYS=""
# Check for doc-specific overlays
if [ -d "${{ matrix.doc_id }}/overlays" ]; then
for overlay_file in "${{ matrix.doc_id }}/overlays"/*.yaml; do
if [ -f "$overlay_file" ]; then
if [ -n "$OVERLAYS" ]; then
OVERLAYS="$OVERLAYS,$overlay_file"
else
OVERLAYS="$overlay_file"
fi
fi
done
fi
# Check for shared overlays - only apply to cloud APIs
if [[ "${{ matrix.doc_id }}" == "cloud-"* ]] && [ -d "shared/overlays" ]; then
for overlay_file in shared/overlays/*.yaml; do
if [ -f "$overlay_file" ]; then
if [ -n "$OVERLAYS" ]; then
OVERLAYS="$OVERLAYS,$overlay_file"
else
OVERLAYS="$overlay_file"
fi
fi
done
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using overlays: $OVERLAYS"
- name: Deploy API documentation
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: ${{ matrix.doc_id }}
token: ${{secrets.BUMP_TOKEN}}
file: ${{ steps.format.outputs.file_path }}
overlay: ${{ steps.overlays.outputs.overlay_paths }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
api-diff:
if: ${{ github.event_name == 'pull_request' && fromJson(needs.determine-doc-ids.outputs.matrix).doc_id[0] != null }}
needs: determine-doc-ids
name: Check API diff on Bump.sh
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.determine-doc-ids.outputs.matrix)}}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determine file format
id: format
run: |
if [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" ]; then
echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" >> $GITHUB_OUTPUT
elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" ]; then
echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" >> $GITHUB_OUTPUT
elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" ]; then
echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" >> $GITHUB_OUTPUT
else
echo "No API definition file found for ${{ matrix.doc_id }}"
exit 1
fi
- name: Determine overlays
id: overlays
run: |
OVERLAYS=""
# Check for doc-specific overlays
if [ -d "${{ matrix.doc_id }}/overlays" ]; then
for overlay_file in "${{ matrix.doc_id }}/overlays"/*.yaml; do
if [ -f "$overlay_file" ]; then
if [ -n "$OVERLAYS" ]; then
OVERLAYS="$OVERLAYS,$overlay_file"
else
OVERLAYS="$overlay_file"
fi
fi
done
fi
# Check for shared overlays - only apply to cloud APIs
if [[ "${{ matrix.doc_id }}" == "cloud-"* ]] && [ -d "shared/overlays" ]; then
for overlay_file in shared/overlays/*.yaml; do
if [ -f "$overlay_file" ]; then
if [ -n "$OVERLAYS" ]; then
OVERLAYS="$OVERLAYS,$overlay_file"
else
OVERLAYS="$overlay_file"
fi
fi
done
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using overlays: $OVERLAYS"
- name: Comment pull request with API diff
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: ${{ matrix.doc_id }}
token: ${{secrets.BUMP_TOKEN}}
file: ${{ steps.format.outputs.file_path }}
overlay: ${{ steps.overlays.outputs.overlay_paths }}
command: diff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}