|
| 1 | +name: Generate docs |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +# Generates Doxygen docs and uploads them as a workflow artifact. |
| 6 | + |
| 7 | +# This workflow is used to validate documentation before merge, for example catching |
| 8 | +# things like broken @ref tags, missing @param tags, etc. |
| 9 | + |
| 10 | +# The artifact is attached to the workflow run so reviewers can download a preview, |
| 11 | +# but also to verify the documentation artifact is valid for subsequent release runs |
| 12 | +# that will publish them to the LiveKit docs web page: https://docs.livekit.io/reference/client-sdk-cpp/ |
| 13 | +on: |
| 14 | + pull_request: |
| 15 | + branches: ["main"] |
| 16 | + paths: |
| 17 | + - include/** |
| 18 | + - src/** |
| 19 | + - docs/** |
| 20 | + - scripts/generate-docs.sh |
| 21 | + - .github/workflows/generate-docs.yml |
| 22 | + - .github/workflows/publish-docs.yml |
| 23 | + workflow_call: |
| 24 | + inputs: |
| 25 | + version: |
| 26 | + description: 'Documentation version (e.g. v0.1.0)' |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + upload_artifact: |
| 30 | + description: 'Upload the generated docs folder as a workflow artifact' |
| 31 | + required: false |
| 32 | + type: boolean |
| 33 | + default: true |
| 34 | + artifact_name: |
| 35 | + description: 'Name to use for the uploaded docs artifact' |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + default: livekit-cpp-docs |
| 39 | + artifact_retention_days: |
| 40 | + description: 'Retention (days) for the uploaded docs artifact' |
| 41 | + required: false |
| 42 | + type: number |
| 43 | + default: 7 |
| 44 | + outputs: |
| 45 | + project_number: |
| 46 | + description: 'Doxygen PROJECT_NUMBER used for the build (e.g., v1.2.3)' |
| 47 | + value: ${{ jobs.validate.outputs.project_number }} |
| 48 | + artifact_name: |
| 49 | + description: 'Name of the uploaded docs artifact (empty if upload was skipped via upload_artifact: false)' |
| 50 | + value: ${{ jobs.validate.outputs.artifact_name }} |
| 51 | + |
| 52 | +jobs: |
| 53 | + validate: |
| 54 | + name: Generate and verify docs |
| 55 | + runs-on: ubuntu-latest |
| 56 | + outputs: |
| 57 | + project_number: ${{ steps.build_docs.outputs.project_number }} |
| 58 | + artifact_name: ${{ steps.artifact_meta.outputs.name }} |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 61 | + with: |
| 62 | + # fetch-depth: 0 is required so `git describe --tags` in |
| 63 | + # scripts/generate-docs.sh resolves the right version from the git history. |
| 64 | + fetch-depth: 0 |
| 65 | + |
| 66 | + # Doxygen is available on ubuntu-latest, but we install explicitly for stability |
| 67 | + - name: Install Doxygen |
| 68 | + run: | |
| 69 | + sudo apt-get update |
| 70 | + sudo apt-get install -y doxygen graphviz |
| 71 | +
|
| 72 | + - name: Generate docs (Doxygen) |
| 73 | + id: build_docs |
| 74 | + shell: bash |
| 75 | + env: |
| 76 | + INPUT_VERSION: ${{ inputs.version || '' }} |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | +
|
| 80 | + args=() |
| 81 | + if [[ -n "$INPUT_VERSION" ]]; then |
| 82 | + args+=(--version "$INPUT_VERSION") |
| 83 | + elif [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 84 | + args+=(--version "${{ github.ref_name }}") |
| 85 | + fi |
| 86 | +
|
| 87 | + ./scripts/generate-docs.sh "${args[@]}" |
| 88 | +
|
| 89 | + - name: Print docs version |
| 90 | + shell: bash |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | +
|
| 94 | + PROJECT_NUMBER="${{ steps.build_docs.outputs.project_number }}" |
| 95 | +
|
| 96 | + if [[ -z "$PROJECT_NUMBER" ]]; then |
| 97 | + echo "ERROR: build_docs step did not emit a project_number output." |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + echo "Docs version: ${PROJECT_NUMBER}" |
| 102 | +
|
| 103 | + { |
| 104 | + echo "Docs version: \`${PROJECT_NUMBER}\`" |
| 105 | + echo "" |
| 106 | + echo "> Note: On a non-tag/release run, the version will resolve to:" |
| 107 | + echo " \`<closest tag>-<commits since tag>-<commit sha>\`" |
| 108 | + } >>"$GITHUB_STEP_SUMMARY" |
| 109 | +
|
| 110 | + - name: Verify docs were generated |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + if [[ ! -f docs/doxygen/html/index.html ]]; then |
| 115 | + echo "ERROR: Expected docs at docs/doxygen/html/index.html but file not found." |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | +
|
| 119 | + # `inputs.*` is only populated on `workflow_call`. On a direct |
| 120 | + # `pull_request` trigger every `inputs.*` lookup is the empty string, so |
| 121 | + # we OR-fold to the documented defaults to keep PR runs behaving the same |
| 122 | + # as the workflow_call default of `upload_artifact: true`. |
| 123 | + - name: Resolve artifact metadata |
| 124 | + id: artifact_meta |
| 125 | + if: inputs.upload_artifact || github.event_name == 'pull_request' |
| 126 | + shell: bash |
| 127 | + env: |
| 128 | + INPUT_NAME: ${{ inputs.artifact_name || 'livekit-cpp-docs' }} |
| 129 | + INPUT_RETENTION: ${{ inputs.artifact_retention_days || '7' }} |
| 130 | + run: | |
| 131 | + set -euo pipefail |
| 132 | + if [[ -z "$INPUT_NAME" ]]; then |
| 133 | + echo "ERROR: artifact name resolved to empty." |
| 134 | + exit 1 |
| 135 | + fi |
| 136 | + echo "name=${INPUT_NAME}" >>"$GITHUB_OUTPUT" |
| 137 | + echo "retention=${INPUT_RETENTION}" >>"$GITHUB_OUTPUT" |
| 138 | +
|
| 139 | + - name: Upload docs artifact |
| 140 | + if: steps.artifact_meta.outputs.name != '' |
| 141 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 142 | + with: |
| 143 | + name: ${{ steps.artifact_meta.outputs.name }} |
| 144 | + path: docs/doxygen/html/ |
| 145 | + retention-days: ${{ steps.artifact_meta.outputs.retention }} |
| 146 | + if-no-files-found: error |
| 147 | + |
| 148 | + # Simple check to make sure the documentation artifact is valid. |
| 149 | + - name: Re-download artifact (publish workflow pre-validation) |
| 150 | + if: steps.artifact_meta.outputs.name != '' |
| 151 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 152 | + with: |
| 153 | + name: ${{ steps.artifact_meta.outputs.name }} |
| 154 | + path: html |
| 155 | + |
| 156 | + - name: Inspect downloaded artifact |
| 157 | + if: steps.artifact_meta.outputs.name != '' |
| 158 | + shell: bash |
| 159 | + run: | |
| 160 | + set -euo pipefail |
| 161 | +
|
| 162 | + NAME="${{ steps.artifact_meta.outputs.name }}" |
| 163 | + ROOT="html" |
| 164 | +
|
| 165 | + echo "Artifact '${NAME}' extracted into '${ROOT}/'. Top-level contents:" |
| 166 | + # `sed -n '1,Np'` reads the whole pipe before truncating its output, |
| 167 | + # so the producer (ls) never hits SIGPIPE under `pipefail`. |
| 168 | + ls -la "$ROOT" | sed -n '1,40p' |
| 169 | +
|
| 170 | + TOTAL=$(find "$ROOT" -type f | wc -l | tr -d ' ') |
| 171 | + echo "Total files: ${TOTAL}" |
| 172 | +
|
| 173 | + if [[ ! -f "${ROOT}/index.html" ]]; then |
| 174 | + echo "ERROR: ${ROOT}/index.html is missing -- artifact layout regressed." |
| 175 | + echo " publish-docs.yml expects html/index.html." |
| 176 | + exit 1 |
| 177 | + fi |
0 commit comments