Skip to content

auto-docs: Update Cloud API spec #93

auto-docs: Update Cloud API spec

auto-docs: Update Cloud API spec #93

Workflow file for this run

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: Set matrix
id: set-matrix
run: |
DOCS=()
for d in */ ; do
# Exclude shared and .github or any other non-doc folders
if [[ "$d" != "shared/" && "$d" != ".github/" && ( -f "${d%/}/${d%/}.yaml" || -f "${d%/}/${d%/}.json" ) ]]; then
DOCS+=("${d%/}")
fi
done
# If no doc folders found, abort the workflow
if [ ${#DOCS[@]} -eq 0 ]; then
echo "No doc folders found. Exiting workflow."
echo "matrix={\"doc_id\":[]}" >> $GITHUB_OUTPUT
exit 0
fi
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=""
# Add doc-specific overlays (if any)
if [ -d "${{ matrix.doc_id }}/overlays" ]; then
shopt -s nullglob
for overlay_file in "${{ matrix.doc_id }}/overlays"/*.yaml; do
if [ -f "$overlay_file" ]; then
OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
fi
done
shopt -u nullglob
fi
# Determine shared overlay prefix
if [[ "${{ matrix.doc_id }}" == "cloud-"* ]]; then
OVERLAY_PREFIX="cloud-"
else
OVERLAY_PREFIX="sm-"
fi
# Add matching shared overlays
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/${OVERLAY_PREFIX}*.yaml; do
if [ -f "$overlay_file" ]; then
OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
fi
done
shopt -u nullglob
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 diff
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=""
# Add doc-specific overlays (if any)
if [ -d "${{ matrix.doc_id }}/overlays" ]; then
shopt -s nullglob
for overlay_file in "${{ matrix.doc_id }}/overlays"/*.yaml; do
if [ -f "$overlay_file" ]; then
OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
fi
done
shopt -u nullglob
fi
# Determine shared overlay prefix
if [[ "${{ matrix.doc_id }}" == "cloud-"* ]]; then
OVERLAY_PREFIX="cloud-"
else
OVERLAY_PREFIX="sm-"
fi
# Add matching shared overlays
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/${OVERLAY_PREFIX}*.yaml; do
if [ -f "$overlay_file" ]; then
OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
fi
done
shopt -u nullglob
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 }}