|
| 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 | + else |
| 101 | + echo "No API definition file found for ${{ matrix.doc_id }}" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Determine overlays |
| 106 | + id: overlays |
| 107 | + run: | |
| 108 | + OVERLAYS="" |
| 109 | +
|
| 110 | + # Function to add overlay path with comma if needed |
| 111 | + add_overlay() { |
| 112 | + local overlay_path="$1" |
| 113 | + if [ -f "$overlay_path" ]; then |
| 114 | + if [ -n "$OVERLAYS" ]; then |
| 115 | + OVERLAYS="$OVERLAYS,$overlay_path" |
| 116 | + else |
| 117 | + OVERLAYS="$overlay_path" |
| 118 | + fi |
| 119 | + fi |
| 120 | + } |
| 121 | +
|
| 122 | + # Check for doc-specific overlays (list each overlay file individually) |
| 123 | + if [ -d "${{ matrix.doc_id }}/overlays" ]; then |
| 124 | + find "${{ matrix.doc_id }}/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do |
| 125 | + add_overlay "$overlay_file" |
| 126 | + done |
| 127 | + fi |
| 128 | +
|
| 129 | + # Check for shared overlays - only apply to cloud APIs |
| 130 | + if [[ "${{ matrix.doc_id }}" == "cloud-"* ]] && [ -d "shared/overlays" ]; then |
| 131 | + find "shared/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do |
| 132 | + add_overlay "$overlay_file" |
| 133 | + done |
| 134 | + fi |
| 135 | +
|
| 136 | + echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT |
| 137 | + echo "Using overlays: $OVERLAYS" |
| 138 | +
|
| 139 | + - name: Deploy API documentation |
| 140 | + uses: bump-sh/github-action@v1 |
| 141 | + with: |
| 142 | + hub: redpanda |
| 143 | + doc: ${{ matrix.doc_id }} |
| 144 | + token: ${{secrets.BUMP_TOKEN}} |
| 145 | + file: ${{ steps.format.outputs.file_path }} |
| 146 | + overlay: ${{ steps.overlays.outputs.overlay_paths }} |
| 147 | + env: |
| 148 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 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: Determine overlays |
| 177 | + id: overlays |
| 178 | + run: | |
| 179 | + OVERLAYS="" |
| 180 | +
|
| 181 | + # Function to add overlay path with comma if needed |
| 182 | + add_overlay() { |
| 183 | + local overlay_path="$1" |
| 184 | + if [ -f "$overlay_path" ]; then |
| 185 | + if [ -n "$OVERLAYS" ]; then |
| 186 | + OVERLAYS="$OVERLAYS,$overlay_path" |
| 187 | + else |
| 188 | + OVERLAYS="$overlay_path" |
| 189 | + fi |
| 190 | + fi |
| 191 | + } |
| 192 | +
|
| 193 | + # Check for doc-specific overlays (list each overlay file individually) |
| 194 | + if [ -d "${{ matrix.doc_id }}/overlays" ]; then |
| 195 | + find "${{ matrix.doc_id }}/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do |
| 196 | + add_overlay "$overlay_file" |
| 197 | + done |
| 198 | + fi |
| 199 | +
|
| 200 | + # Check for shared overlays - only apply to cloud APIs |
| 201 | + if [[ "${{ matrix.doc_id }}" == "cloud-"* ]] && [ -d "shared/overlays" ]; then |
| 202 | + find "shared/overlays" -name "*.yaml" -type f | sort | while read overlay_file; do |
| 203 | + add_overlay "$overlay_file" |
| 204 | + done |
| 205 | + fi |
| 206 | +
|
| 207 | + echo "overlay_paths=$OVERLAYS" >> $GITHUB_OUTPUT |
| 208 | + echo "Using overlays: $OVERLAYS" |
| 209 | +
|
| 210 | + - name: Comment pull request with API diff |
| 211 | + uses: bump-sh/github-action@v1 |
| 212 | + with: |
| 213 | + hub: redpanda |
| 214 | + doc: ${{ matrix.doc_id }} |
| 215 | + token: ${{secrets.BUMP_TOKEN}} |
| 216 | + file: ${{ steps.format.outputs.file_path }} |
| 217 | + overlay: ${{ steps.overlays.outputs.overlay_paths }} |
| 218 | + command: diff |
| 219 | + env: |
| 220 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments