|
| 1 | +name: Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + # Allows running this workflow manually from the Actions tab |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: "Version of Slicer documentation to build and publish" |
| 9 | + required: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + # Needed in the publish step to update gh-pages branch |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-and-publish: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Collect Inputs |
| 20 | + id: collect_inputs |
| 21 | + run: | |
| 22 | + echo "EVENT_NAME [$EVENT_NAME]" |
| 23 | + if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then |
| 24 | + version=${{ github.event.inputs.version }} |
| 25 | + else |
| 26 | + echo "::error ::Unsupported EVENT_NAME [$EVENT_NAME]" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 30 | + env: |
| 31 | + EVENT_NAME: ${{ github.event_name }} |
| 32 | + |
| 33 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 34 | + with: |
| 35 | + ref: gh-pages |
| 36 | + path: gh-pages |
| 37 | + |
| 38 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 39 | + with: |
| 40 | + repository: Slicer/Slicer |
| 41 | + path: Slicer |
| 42 | + ref: ${{ steps.collect_inputs.outputs.version }} |
| 43 | + |
| 44 | + - uses: ssciwr/doxygen-install@527824132256e685f03ec80c0851fe79937eb1d6 # v1.6.3 |
| 45 | + with: |
| 46 | + version: "1.10.0" |
| 47 | + |
| 48 | + # The "dot" binary is provided by Graphviz |
| 49 | + - uses: ts-graphviz/setup-graphviz@b1de5da23ed0a6d14e0aeee8ed52fdd87af2363c # v2.0.2 |
| 50 | + |
| 51 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 52 | + with: |
| 53 | + repository: Slicer/slicer-apidocs-builder |
| 54 | + path: slicer-apidocs-builder |
| 55 | + ref: 1744509e91fa66186d34e4c6968ee684131c51d1 |
| 56 | + |
| 57 | + - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 58 | + with: |
| 59 | + python-version: '3.13' |
| 60 | + cache: 'pip' |
| 61 | + |
| 62 | + - name: Install slicer-apidocs-builder |
| 63 | + run: | |
| 64 | + pip install ./slicer-apidocs-builder |
| 65 | +
|
| 66 | + - name: Generate Documentation |
| 67 | + id: generate |
| 68 | + run: | |
| 69 | + WARNING_LOG_FILE=/tmp/Slicer-Slicer-$SLICER_REPO_BRANCH-build/Utilities/Doxygen/UserDoxygenWarnings.txt |
| 70 | + mkdir -p $(direname $WARNING_LOG_FILE) |
| 71 | +
|
| 72 | + slicer-apidocs-builder \ |
| 73 | + --skip-publish \ |
| 74 | + --slicer-repo-dir $(pwd)/Slicer \ |
| 75 | + --slicer-repo-branch "$SLICER_REPO_BRANCH" \ |
| 76 | + --slicer-repo-tag "${SLICER_REPO_TAG}" 2> >(tee $WARNING_LOG_FILE >&2) |
| 77 | +
|
| 78 | + echo "warning_log_file=$WARNING_LOG_FILE" >> $GITHUB_OUTPUT |
| 79 | + env: |
| 80 | + SLICER_REPO_BRANCH: ${{ steps.collect_inputs.outputs.version }} |
| 81 | + SLICER_REPO_TAG: "" |
| 82 | + |
| 83 | + - name: Parse and annotate Doxygen warnings |
| 84 | + run: | |
| 85 | + echo "WARNING_LOG_FILE [$WARNING_LOG_FILE]" |
| 86 | + if [[ -f $WARNING_LOG_FILE ]]; then |
| 87 | + buffer="" |
| 88 | + while IFS= read -r line || [[ -n "$line" ]]; do |
| 89 | + # If a buffer exists, prepend the buffered line to this line |
| 90 | + if [[ -n "$buffer" ]]; then |
| 91 | + line="$buffer$line" |
| 92 | + buffer="" |
| 93 | + fi |
| 94 | +
|
| 95 | + # Extract file, line number, and warning message |
| 96 | + FILE=$(echo "$line" | grep -oP "^[^:]+" || true) |
| 97 | + LINE=$(echo "$line" | grep -oP ":(\d+):" | tr -d ":" || true) |
| 98 | + MESSAGE=$(echo "$line" | grep -oP "warning:.*" || true) |
| 99 | +
|
| 100 | + # If MESSAGE is found, process further |
| 101 | + if [[ -n "$MESSAGE" ]]; then |
| 102 | + MESSAGE=${MESSAGE#warning: } # Strip "warning: " prefix |
| 103 | +
|
| 104 | + # Aggregate all subsequent lines starting with at least a space |
| 105 | + while IFS= read -r continuation || [[ -n "$continuation" ]]; do |
| 106 | + if [[ "$continuation" =~ ^[[:space:]] ]]; then |
| 107 | + MESSAGE="${MESSAGE}%0A${continuation}" |
| 108 | + else |
| 109 | + # Buffer the line to be processed in the main loop |
| 110 | + buffer="$continuation" |
| 111 | + break |
| 112 | + fi |
| 113 | + done |
| 114 | + fi |
| 115 | +
|
| 116 | + # Annotate in GitHub Actions |
| 117 | + if [[ -n "$FILE" && -n "$LINE" && -n "$MESSAGE" ]]; then |
| 118 | + echo "::warning file=$FILE,line=$LINE::$MESSAGE" |
| 119 | + elif [[ -n "$MESSAGE" ]]; then |
| 120 | + echo "::warning ::$MESSAGE" |
| 121 | + else |
| 122 | + echo "Skipped unmatched line: $line" |
| 123 | + fi |
| 124 | +
|
| 125 | + done < "$WARNING_LOG_FILE" |
| 126 | + else |
| 127 | + echo "No Doxygen warnings log found." |
| 128 | + fi |
| 129 | + env: |
| 130 | + WARNING_LOG_FILE: ${{ steps.generate.outputs.warning_log_file }} |
| 131 | + |
| 132 | + - uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1 |
| 133 | + id: app-token |
| 134 | + with: |
| 135 | + app-id: ${{ vars.SLICER_APP_ID }} |
| 136 | + private-key: ${{ secrets.SLICER_APP_PRIVATE_KEY }} |
| 137 | + |
| 138 | + - name: Publish documentation |
| 139 | + run: | |
| 140 | + slicer-apidocs-builder \ |
| 141 | + --skip-build \ |
| 142 | + --slicer-repo-dir $(pwd)/Slicer \ |
| 143 | + --slicer-repo-name ${SLICER_REPO_NAME} \ |
| 144 | + --slicer-repo-branch "${SLICER_REPO_BRANCH}" \ |
| 145 | + --slicer-repo-tag "${SLICER_REPO_TAG}" \ |
| 146 | + --publish-github-repo-name "Slicer/${PUBLISH_GITHUB_PROJECT_NAME}" \ |
| 147 | + --publish-github-repo-branch gh-pages |
| 148 | + env: |
| 149 | + PUBLISH_GITHUB_PROJECT_NAME: apidocs.slicer.org |
| 150 | + PUBLISH_GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 151 | + SLICER_REPO_NAME: Slicer/Slicer |
| 152 | + SLICER_REPO_BRANCH: ${{ steps.collect_inputs.outputs.version }} |
| 153 | + SLICER_REPO_TAG: "" |
| 154 | + |
0 commit comments