Skip to content

Add GitHub Action workflows to support Admin API v2 #147

Add GitHub Action workflows to support Admin API v2

Add GitHub Action workflows to support Admin API v2 #147

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
id-token: write
jobs:
determine-doc-ids:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.RP_AWS_CRED_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.RP_AWS_CRED_ACCOUNT_ID }}:role/${{ vars.RP_AWS_CRED_BASE_ROLE_NAME }}${{ github.event.repository.name }}
- uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
,sdlc/prod/github/bump_api_key
parse-json-secrets: true
- 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/" ]]; then
continue
fi
base="${d%/}"
if [[ -f "${base}/${base}.yaml" || -f "${base}/${base}.yml" || -f "${base}/${base}.json" ]]; then
DOCS+=("${base}")
fi
done
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
# Figure out the file path for non-admin docs
- name: Determine file format (non-admin)
id: format
run: |
base="${{ matrix.doc_id }}"
if [ "$base" = "admin" ]; then
# Not used for admin; we deploy v1/v2 explicitly below
echo "file_path=" >> $GITHUB_OUTPUT
exit 0
fi
if [ -f "${base}/${base}.yaml" ]; then
echo "file_path=${base}/${base}.yaml" >> $GITHUB_OUTPUT
elif [ -f "${base}/${base}.yml" ]; then
echo "file_path=${base}/${base}.yml" >> $GITHUB_OUTPUT
elif [ -f "${base}/${base}.json" ]; then
echo "file_path=${base}/${base}.json" >> $GITHUB_OUTPUT
else
echo "No API definition file found for ${base}"
exit 1
fi
- name: Determine overlays (non-admin)
id: overlays
run: |
OVERLAYS=""
DOC_ID="${{ matrix.doc_id }}"
# Skip overlay determination for admin - handled separately
if [ "$DOC_ID" = "admin" ]; then
echo "overlay_paths=" >> $GITHUB_OUTPUT
exit 0
fi
# Doc-specific overlays
if [ -d "${DOC_ID}/overlays" ]; then
shopt -s nullglob
for overlay_file in "${DOC_ID}/overlays"/*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
# Shared overlays
if [[ "$DOC_ID" == cloud-* ]]; then
PREFIX="cloud-"
else
PREFIX="sm-"
fi
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/${PREFIX}*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using overlays: $OVERLAYS"
- name: Determine admin v1 overlays
id: admin-v1-overlays
run: |
OVERLAYS=""
DOC_ID="${{ matrix.doc_id }}"
# Only run for admin
if [ "$DOC_ID" != "admin" ]; then
echo "overlay_paths=" >> $GITHUB_OUTPUT
exit 0
fi
# Admin v1-specific overlays
if [ -d "admin/v1-overlays" ]; then
shopt -s nullglob
for overlay_file in admin/v1-overlays/*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
# Shared overlays for self-managed (admin is sm)
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/sm-*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using v1 overlays: $OVERLAYS"
- name: Determine admin v2 overlays
id: admin-v2-overlays
run: |
OVERLAYS=""
DOC_ID="${{ matrix.doc_id }}"
# Only run for admin
if [ "$DOC_ID" != "admin" ]; then
echo "overlay_paths=" >> $GITHUB_OUTPUT
exit 0
fi
# Admin v2-specific overlays
if [ -d "admin/v2-overlays" ]; then
shopt -s nullglob
for overlay_file in admin/v2-overlays/*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
# Shared overlays for self-managed (admin is sm)
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/sm-*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using v2 overlays: $OVERLAYS"
# ---- Admin v1 explicit deploy (only when matrix.doc_id == admin) ----
- name: Deploy API documentation (admin v1)
if: ${{ matrix.doc_id == 'admin' && hashFiles('admin/admin.yaml') != '' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: admin
token: ${{ env.BUMP_API_KEY }}
file: admin/admin.yaml
overlay: ${{ steps.admin-v1-overlays.outputs.overlay_paths }}
branch: v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ---- Admin v2 explicit deploy (only when matrix.doc_id == admin) ----
- name: Deploy API documentation (admin v2)
if: ${{ matrix.doc_id == 'admin' && hashFiles('admin/admin-v2.yaml') != '' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: admin
token: ${{ env.BUMP_API_KEY }}
file: admin/admin-v2.yaml
overlay: ${{ steps.admin-v2-overlays.outputs.overlay_paths }}
branch: v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ---- Other docs (non-admin) ----
- name: Deploy API documentation (other files)
if: ${{ matrix.doc_id != 'admin' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: ${{ matrix.doc_id }}
token: ${{ env.BUMP_API_KEY }}
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
# For non-admin docs, resolve file path
- name: Determine file format (non-admin)
id: format
run: |
base="${{ matrix.doc_id }}"
if [ "$base" = "admin" ]; then
echo "file_path=" >> $GITHUB_OUTPUT
exit 0
fi
if [ -f "${base}/${base}.yaml" ]; then
echo "file_path=${base}/${base}.yaml" >> $GITHUB_OUTPUT
elif [ -f "${base}/${base}.yml" ]; then
echo "file_path=${base}/${base}.yml" >> $GITHUB_OUTPUT
elif [ -f "${base}/${base}.json" ]; then
echo "file_path=${base}/${base}.json" >> $GITHUB_OUTPUT
else
echo "No API definition file found for ${base}"
exit 1
fi
- name: Determine overlays
id: overlays
run: |
OVERLAYS=""
DOC_ID="${{ matrix.doc_id }}"
if [ -d "${DOC_ID}/overlays" ]; then
shopt -s nullglob
for overlay_file in "${DOC_ID}/overlays"/*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
if [[ "$DOC_ID" == cloud-* ]]; then
PREFIX="cloud-"
else
PREFIX="sm-"
fi
if [ -d "shared/overlays" ]; then
shopt -s nullglob
for overlay_file in shared/overlays/${PREFIX}*.yaml; do
[ -f "$overlay_file" ] && OVERLAYS="${OVERLAYS:+$OVERLAYS,}$overlay_file"
done
shopt -u nullglob
fi
echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT
echo "Using overlays: $OVERLAYS"
# ---- Admin v1 explicit diff ----
- name: Comment PR with API diff (admin v1)
if: ${{ matrix.doc_id == 'admin' && hashFiles('admin/admin.yaml') != '' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: admin
token: ${{ env.BUMP_API_KEY }}
file: admin/admin.yaml
overlay: ${{ steps.overlays.outputs.overlay_paths }}
command: diff
branch: v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ---- Admin v2 explicit diff ----
- name: Comment PR with API diff (admin v2)
if: ${{ matrix.doc_id == 'admin' && hashFiles('admin/admin-v2.yaml') != '' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: admin
token: ${{ env.BUMP_API_KEY }}
file: admin/admin-v2.yaml
overlay: ${{ steps.overlays.outputs.overlay_paths }}
command: diff
branch: v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ---- Other docs (non-admin) ----
- name: Comment PR with API diff (other files)
if: ${{ matrix.doc_id != 'admin' }}
uses: bump-sh/github-action@v1
with:
hub: redpanda
doc: ${{ matrix.doc_id }}
token: ${{ env.BUMP_API_KEY }}
file: ${{ steps.format.outputs.file_path }}
overlay: ${{ steps.overlays.outputs.overlay_paths }}
command: diff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}