From c402f0064ff8e759bf400fd7678af2cc1b13f972 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 26 Feb 2025 09:39:44 +0100 Subject: [PATCH] ci: doc: post preview comment after build finishes As of today, preview comment was published just after PR is posted, so if e.g. build fails, the comment may be misleading. Update the CI jobs to perform this in 2 steps, so that the docpublish workflow takes care of posting the comment. Signed-off-by: Gerard Marull-Paretas --- .github/workflows/docbuild.yml | 29 +++++++++++++ .github/workflows/docpreview.yml | 71 -------------------------------- .github/workflows/docpublish.yml | 21 ++++++++++ 3 files changed, 50 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/docpreview.yml diff --git a/.github/workflows/docbuild.yml b/.github/workflows/docbuild.yml index b999ce7a122a..05b3e5d6c608 100644 --- a/.github/workflows/docbuild.yml +++ b/.github/workflows/docbuild.yml @@ -34,6 +34,8 @@ jobs: steps: - name: Checkout sources uses: nrfconnect/action-checkout-west-update@main + with: + git-fetch-depth: 0 - name: cache-pip uses: actions/cache@v4 @@ -178,6 +180,32 @@ jobs: zip -rq "$ARCHIVE" . mv "$ARCHIVE" "$ROOT" popd + + - name: Find nRF Connect SDK Edited Documents + working-directory: ncs/nrf + run: | + COMMENT="comment.txt" + PREFIX="https://ncsdoc.z6.web.core.windows.net/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 + + NRF=$(echo "$CHANGED" | \ + grep -e "doc/nrf/" | \ + grep -e ".rst" | \ + sed -e "s#^doc/nrf\(.*\)\.rst#${PREFIX}nrf\1.html#g") + + NRF_EXT=$(echo "$CHANGED" | \ + grep -e "applications/" -e "samples/" -e "scripts/" -e "tests/" | \ + grep -e ".rst" | \ + sed -e "s#^\(applications\|samples\|scripts\|tests\)\(.*\)\.rst#${PREFIX}nrf\/\1\2.html#g") + + NRF_ALL=$(printf "$NRF\n$NRF_EXT") + + if [ ! -z "$NRF_ALL" ]; then + printf "\nPreview links for modified nRF Connect SDK documents:\n\n$NRF_ALL" >> $COMMENT + 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@v4 @@ -187,3 +215,4 @@ jobs: ncs/nrf/*.zip ncs/nrf/monitor*.txt ncs/nrf/pr.txt + ncs/nrf/comment.txt diff --git a/.github/workflows/docpreview.yml b/.github/workflows/docpreview.yml deleted file mode 100644 index 89048fae113e..000000000000 --- a/.github/workflows/docpreview.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Documentation Preview - -on: - pull_request_target: - paths: - - '.github/workflows/docbuild.yml' - - '**.rst' - - '**/Kconfig' - - '**/sample.yaml' - - 'doc/**' - - 'applications/**' - - 'include/**' - - 'lib/**' - - 'doc/requirements.txt' - - 'scripts/tools-versions-*.yml' - - 'west.yml' - -jobs: - doc-preview: - runs-on: ubuntu-24.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 0 - persist-credentials: false - - - name: Find nRF Connect SDK Edited Documents - id: nrf-edited-documents - run: | - PREFIX="${{ vars.NCS_DOC_HOSTING_URL }}PR-${{ github.event.pull_request.number }}/" - CHANGED=$(git diff --name-only --diff-filter=d "${{ github.event.pull_request.base.sha }}..HEAD") - - NRF=$(echo "$CHANGED" | \ - grep -e "doc/nrf/" | \ - grep -e ".rst" | \ - sed -e "s#^doc/nrf\(.*\)\.rst#${PREFIX}nrf\1.html#g") - - NRF_EXT=$(echo "$CHANGED" | \ - grep -e "applications/" -e "samples/" -e "scripts/" -e "tests/" | \ - grep -e ".rst" | \ - sed -e "s#^\(applications\|samples\|scripts\|tests\)\(.*\)\.rst#${PREFIX}nrf\/\1\2.html#g") - - NRF_ALL=$(printf "$NRF\n$NRF_EXT") - - if [ ! -z "$NRF_ALL" ]; then - COMMENT=$(printf "\nPreview links for modified nRF Connect SDK documents:\n\n$NRF_ALL") - - echo "COMMENT<> $GITHUB_OUTPUT - echo "$COMMENT" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - fi - - - name: Find Comment - uses: peter-evans/find-comment@v3 - id: fc - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: 'github-actions[bot]' - body-includes: preview for this PR - - - name: Create or update comment - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - After documentation is built, you will find the preview for this PR [here](${{ vars.NCS_DOC_HOSTING_URL }}PR-${{ github.event.pull_request.number }}). - ${{ steps.nrf-edited-documents.outputs.COMMENT }} - edit-mode: replace diff --git a/.github/workflows/docpublish.yml b/.github/workflows/docpublish.yml index cb082b8dac98..228b14664cef 100644 --- a/.github/workflows/docpublish.yml +++ b/.github/workflows/docpublish.yml @@ -24,6 +24,11 @@ jobs: echo "OUTDIR=$OUTDIR" >> "$GITHUB_ENV" unzip legacy-ncs*.zip -d $OUTDIR + - name: Obtain PR number + working-directory: docs + run: | + echo "PR=$(cat pr.txt)" >> "$GITHUB_ENV" + - name: Upload to Azure storage working-directory: docs env: @@ -68,3 +73,19 @@ jobs: quit EOF done + + - name: Find Comment + uses: peter-evans/find-comment@v3 + id: fc + with: + issue-number: ${{ env.PR }} + comment-author: 'github-actions[bot]' + body-includes: documentation preview + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ env.PR }} + body-path: docs/comment.txt + edit-mode: replace