doc: Fix doc publish failure #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Documentation Build | |
| permissions: | |
| contents: read | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| branches: | |
| - main | |
| - 'v*-branch' | |
| paths: | |
| - '.github/doc-addon.env' | |
| - '.github/actions/load-doc-config/**' | |
| - '.github/workflows/doc_build.yml' | |
| - 'docs/**' | |
| push: | |
| branches: | |
| - main | |
| - 'v*-branch' | |
| tags: | |
| - v* | |
| paths: | |
| - '.github/doc-addon.env' | |
| - '.github/actions/load-doc-config/**' | |
| - '.github/workflows/doc_build.yml' | |
| - 'docs/**' | |
| - 'samples/**/*.rst' | |
| - 'samples/**/Kconfig' | |
| - 'samples/**/sample.yaml' | |
| env: | |
| DOXYGEN_VERSION: 1.12.0 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | |
| fetch-depth: 0 | |
| - name: Load doc add-on config | |
| uses: ./.github/actions/load-doc-config | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt update | |
| sudo apt-get install -y graphviz plantuml | |
| wget --no-verbose "https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz" | |
| sudo tar xf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz -C /opt | |
| echo "/opt/doxygen-${DOXYGEN_VERSION}/bin" >> $GITHUB_PATH | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: 3.12 | |
| cache: pip | |
| cache-dependency-path: docs/requirements-doc.txt | |
| pip-install: | | |
| -r docs/requirements-doc.txt | |
| - name: Build | |
| working-directory: docs | |
| run: | | |
| make html | |
| - name: Check version | |
| run: | | |
| VERSION_REGEX="^v([0-9a-zA-Z\.\-]+)$" | |
| if [[ ${GITHUB_REF#refs/tags/} =~ $VERSION_REGEX ]]; then | |
| VERSION=${BASH_REMATCH[1]} | |
| elif [[ ${GITHUB_REF#refs/heads/} == "main" ]]; then | |
| VERSION="latest" | |
| elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| VERSION="pr-${{ github.event.number }}" | |
| fi | |
| echo "VERSION=${VERSION}" | |
| echo "VERSION=${VERSION}" >> "$GITHUB_ENV" | |
| - name: Prepare Azure upload | |
| working-directory: docs | |
| run: | | |
| PUBLISH="$PWD/publish" | |
| mkdir -p "$PUBLISH" | |
| MONITOR="monitor_${{ github.run_id }}.txt" | |
| # Create documentation upload files | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| ARCHIVE="${{ env.DOC_ADDON_NAME }}-pr-${{ github.event.number }}.zip" | |
| echo "publish2 dev PR-${{ github.event.number }} ${ARCHIVE}" > "${MONITOR}" | |
| echo "${{ github.event.number }}" > pr.txt | |
| else | |
| ARCHIVE="${{ env.DOC_ADDON_NAME }}-${VERSION}.zip" | |
| echo "publish2 main ${VERSION} ${ARCHIVE}" > "${MONITOR}" | |
| fi | |
| pushd "_build_sphinx/html" | |
| zip -rq "${ARCHIVE}" . | |
| mv "${ARCHIVE}" "$PUBLISH" | |
| popd | |
| mv "${MONITOR}" "$PUBLISH" | |
| if [[ -f pr.txt ]]; then mv pr.txt "$PUBLISH"; fi | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| COMMENT="${PUBLISH}/comment.txt" | |
| PREFIX="${{ vars.NCS_DOC_PR_HOSTING_URL }}addons/${{ env.DOC_ADDON_NAME }}/PR-${{ github.event.pull_request.number }}/" | |
| CHANGED=$(git diff --name-only --diff-filter=d "${{ github.event.pull_request.base.sha }}..HEAD") | |
| echo "You can find the documentation preview for this PR [here](${PREFIX})." > "${COMMENT}" | |
| DOCS=$(echo "$CHANGED" | \ | |
| grep -e "^docs/" | \ | |
| grep -e ".rst$" | \ | |
| sed -e "s#^docs\(.*\)\.rst#${PREFIX}\1.html#g" || true) | |
| SAMPLES=$(echo "$CHANGED" | \ | |
| grep -e "^samples/" | \ | |
| grep -e ".rst$" | \ | |
| sed -e "s#^samples\(.*\)\.rst#${PREFIX}samples\1.html#g" || true) | |
| DOCS_ALL=$(printf "%s\n%s" "$DOCS" "$SAMPLES" | sed '/^$/d') | |
| if [ -n "$DOCS_ALL" ]; then | |
| printf "\nPreview links for modified Matter add-on documents:\n\n%s" "$DOCS_ALL" >> "${COMMENT}" | |
| fi | |
| fi | |
| - name: Store | |
| if: ${{ !contains(github.event.pull_request.labels.*.name, 'external') || contains(github.event.pull_request.labels.*.name, 'CI-trusted-author') }} | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: docs | |
| retention-days: 5 | |
| path: | | |
| docs/publish/* |