1+ name : Check and deploy API documentation
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ pull_request :
9+ branches :
10+ - main
11+
12+ permissions :
13+ contents : read
14+ pull-requests : write
15+
16+ jobs :
17+ determine-doc-ids :
18+ runs-on : ubuntu-latest
19+ outputs :
20+ matrix : ${{ steps.set-matrix.outputs.matrix }}
21+ steps :
22+ - name : Checkout
23+ uses : actions/checkout@v4
24+ with :
25+ fetch-depth : 0
26+
27+ - name : Get changed files
28+ id : changed-files
29+ run : |
30+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
31+ CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
32+ else
33+ CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
34+ fi
35+ echo "CHANGED_FILES<<EOF" >> $GITHUB_ENV
36+ echo "$CHANGED_FILES" >> $GITHUB_ENV
37+ echo "EOF" >> $GITHUB_ENV
38+
39+ - name : Set matrix
40+ id : set-matrix
41+ run : |
42+ DOCS=()
43+
44+ # Check for changes in API doc folders
45+ if echo "$CHANGED_FILES" | grep -q "^admin/"; then
46+ DOCS+=("admin")
47+ fi
48+ if echo "$CHANGED_FILES" | grep -q "^cloud-controlplane/"; then
49+ DOCS+=("cloud-controlplane")
50+ fi
51+ if echo "$CHANGED_FILES" | grep -q "^cloud-dataplane/"; then
52+ DOCS+=("cloud-dataplane")
53+ fi
54+ if echo "$CHANGED_FILES" | grep -q "^schema-registry/"; then
55+ DOCS+=("schema-registry")
56+ fi
57+ if echo "$CHANGED_FILES" | grep -q "^http-proxy/"; then
58+ DOCS+=("http-proxy")
59+ fi
60+ # Check for changes in shared resources that might affect all docs
61+ if echo "$CHANGED_FILES" | grep -q "^shared/"; then
62+ if [ ${#DOCS[@]} -eq 0 ]; then
63+ # If only shared files changed and no specific doc files, include all docs
64+ DOCS+=("admin" "cloud-controlplane" "cloud-dataplane" "schema-registry" "http-proxy")
65+ fi
66+ fi
67+
68+ # If no files changed in any monitored directories, abort the workflow
69+ if [ ${#DOCS[@]} -eq 0 ]; then
70+ echo "No relevant files were changed. Exiting workflow."
71+ echo "matrix={\"doc_id\":[]}" >> $GITHUB_OUTPUT
72+ exit 0
73+ fi
74+
75+ # Convert bash array to JSON array for GitHub Actions matrix
76+ JSON_ARRAY=$(printf '"%s",' "${DOCS[@]}" | sed 's/,$//')
77+ JSON_MATRIX="{\"doc_id\":[$JSON_ARRAY]}"
78+ echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT
79+ echo "Created matrix: $JSON_MATRIX"
80+
81+ deploy-doc :
82+ if : ${{ github.event_name == 'push' && fromJson(needs.determine-doc-ids.outputs.matrix).doc_id[0] != null }}
83+ needs : determine-doc-ids
84+ name : Deploy API documentation on Bump.sh
85+ runs-on : ubuntu-latest
86+ strategy :
87+ matrix : ${{fromJson(needs.determine-doc-ids.outputs.matrix)}}
88+ fail-fast : false
89+ steps :
90+ - name : Checkout
91+ uses : actions/checkout@v4
92+
93+ - name : Determine file format
94+ id : format
95+ run : |
96+ if [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" ]; then
97+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" >> $GITHUB_OUTPUT
98+ elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" ]; then
99+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" >> $GITHUB_OUTPUT
100+ elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" ]; then
101+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" >> $GITHUB_OUTPUT
102+ else
103+ echo "No API definition file found for ${{ matrix.doc_id }}"
104+ exit 1
105+ fi
106+
107+ - name : Determine overlays
108+ id : overlays
109+ run : |
110+ OVERLAYS=""
111+
112+ # Function to add overlay path with comma if needed
113+ add_overlay() {
114+ local overlay_path="$1"
115+ if [ -f "$overlay_path" ]; then
116+ if [ -n "$OVERLAYS" ]; then
117+ OVERLAYS="$OVERLAYS,$overlay_path"
118+ else
119+ OVERLAYS="$overlay_path"
120+ fi
121+ fi
122+ }
123+
124+ # Check for doc-specific overlays (list each overlay file individually)
125+ if [ -d "${{ matrix.doc_id }}/overlays" ]; then
126+ find "${{ matrix.doc_id }}/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do
127+ add_overlay "$overlay_file"
128+ done
129+ fi
130+
131+ # Check for shared overlays - only apply to cloud APIs
132+ if [[ "${{ matrix.doc_id }}" == "cloud-"* ]] && [ -d "shared/overlays" ]; then
133+ find "shared/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do
134+ add_overlay "$overlay_file"
135+ done
136+ fi
137+
138+ echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
139+ echo "Using overlays: $OVERLAYS"
140+
141+ - name : Deploy API documentation
142+ uses : bump-sh/github-action@v1
143+ with :
144+ hub : redpanda
145+ doc : ${{ matrix.doc_id }}
146+ token : ${{secrets.BUMP_TOKEN}}
147+ file : ${{ steps.format.outputs.file_path }}
148+ overlay : ${{ steps.overlays.outputs.overlay_paths }}
149+
150+ api-diff :
151+ if : ${{ github.event_name == 'pull_request' && fromJson(needs.determine-doc-ids.outputs.matrix).doc_id[0] != null }}
152+ needs : determine-doc-ids
153+ name : Check API diff on Bump.sh
154+ runs-on : ubuntu-latest
155+ strategy :
156+ matrix : ${{fromJson(needs.determine-doc-ids.outputs.matrix)}}
157+ fail-fast : false
158+ steps :
159+ - name : Checkout
160+ uses : actions/checkout@v4
161+
162+ - name : Determine file format
163+ id : format
164+ run : |
165+ if [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" ]; then
166+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.yaml" >> $GITHUB_OUTPUT
167+ elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" ]; then
168+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}.json" >> $GITHUB_OUTPUT
169+ elif [ -f "${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" ]; then
170+ echo "file_path=${{ matrix.doc_id }}/${{ matrix.doc_id }}-api.json" >> $GITHUB_OUTPUT
171+ else
172+ echo "No API definition file found for ${{ matrix.doc_id }}"
173+ exit 1
174+ fi
175+
176+ - name : Comment pull request with API diff
177+ uses : bump-sh/github-action@v1
178+ with :
179+ hub : redpanda
180+ doc : ${{ matrix.doc_id }}
181+ token : ${{secrets.BUMP_TOKEN}}
182+ file : ${{ steps.format.outputs.file_path }}
183+ command : diff
0 commit comments