Skip to content

Commit 82c1595

Browse files
divipillaicoderbyheart
authored andcommitted
doc: Add workflow for the new doc platform
Add workflow for the new doc platform. Signed-off-by: divya pillai <divya.pillai@nordicsemi.no>
1 parent 1f57d3e commit 82c1595

3 files changed

Lines changed: 182 additions & 0 deletions

File tree

.github/workflows/doc-build.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Documentation Build
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
branches:
10+
- main
11+
paths:
12+
- '.github/workflows/doc-build.yml'
13+
- '.github/workflows/doc-publish.yml'
14+
- '**.rst'
15+
- 'docs/**'
16+
- "include/**"
17+
push:
18+
branches:
19+
- main
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-24.04
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31+
with:
32+
ref: ${{ github.event.pull_request.head.sha }}
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
36+
with:
37+
python-version: 3.12
38+
cache: pip
39+
cache-dependency-path: docs/requirements.txt
40+
pip-install: |
41+
-r docs/requirements.txt
42+
43+
- name: Build
44+
working-directory: docs
45+
run: |
46+
sphinx-build -M html . build
47+
48+
- name: Check version
49+
run: |
50+
if [[ ${GITHUB_REF#refs/heads/} == "main" ]]; then
51+
VERSION="latest"
52+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
53+
VERSION="pr-${{ github.event.number }}"
54+
fi
55+
echo "VERSION=${VERSION}"
56+
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
57+
58+
- name: Prepare Azure upload
59+
run: |
60+
PUBLISH="$PWD/publish"
61+
mkdir -p "$PUBLISH"
62+
63+
MONITOR="monitor_${{ github.run_id }}.txt"
64+
65+
# Create documentation upload files
66+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
67+
ARCHIVE="legacy-addon-thingy91x_oob-pr-${{ github.event.number }}.zip"
68+
echo "publish2 dev PR-${{ github.event.number }} ${ARCHIVE}" > "${MONITOR}"
69+
echo "${{ github.event.number }}" > pr.txt
70+
else
71+
ARCHIVE="legacy-addon-thingy91x_oob-${VERSION}.zip"
72+
echo "publish2 main ${VERSION} ${ARCHIVE}" > "${MONITOR}"
73+
fi
74+
75+
pushd "docs/build/html"
76+
zip -rq "${ARCHIVE}" .
77+
mv "${ARCHIVE}" "$PUBLISH"
78+
popd
79+
80+
mv "${MONITOR}" "$PUBLISH"
81+
if [[ -f pr.txt ]]; then mv pr.txt "$PUBLISH"; fi
82+
83+
- name: Store
84+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'external') || contains(github.event.pull_request.labels.*.name, 'CI-trusted-author') }}
85+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
86+
with:
87+
name: docs
88+
retention-days: 5
89+
path: |
90+
publish/*

.github/workflows/doc-publish.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Documentation Publish
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on:
8+
9+
workflow_run:
10+
workflows: ["Documentation Build"]
11+
types:
12+
- completed
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-24.04
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
steps:
19+
- name: Download artifacts
20+
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
21+
with:
22+
workflow: doc-build.yml
23+
run_id: ${{ github.event.workflow_run.id }}
24+
25+
- name: Unzip html archive
26+
working-directory: docs
27+
run: |
28+
OUTDIR=$(awk 'NR==1 { if ($3 ~ /^(latest|PR-[0-9])$/) print $3 }' monitor_*.txt)
29+
echo "OUTDIR=$OUTDIR" >> "$GITHUB_ENV"
30+
unzip legacy-addon-thingy91x_oob*.zip -d $OUTDIR
31+
find "$OUTDIR" -type l -delete
32+
33+
- name: Obtain PR number
34+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
35+
working-directory: docs
36+
run: |
37+
if [ -f pr.txt ]; then
38+
PR=$(head -n 1 pr.txt | tr -cd '0-9')
39+
fi
40+
printf 'PR=%s\n' "$PR" >> "$GITHUB_ENV"
41+
42+
- name: Upload to Azure storage
43+
working-directory: docs
44+
env:
45+
AZCOPY_CONCURRENCY_VALUE: 1024
46+
NCS_DOC_SAS_PRS: ${{ secrets.NCS_DOC_SAS_PRS }}
47+
NCS_DOC_SAS_MAIN: ${{ secrets.NCS_DOC_SAS_MAIN }}
48+
run: |
49+
if [[ "${{ github.event.workflow_run.event }}" == "pull_request" ]]; then
50+
azcopy cp $OUTDIR "${{ vars.NCS_DOC_PR_STORAGE_URL }}addons/addon-thingy91x_oob?$NCS_DOC_SAS_PRS" --recursive=true
51+
else
52+
azcopy cp $OUTDIR "${{ vars.NCS_DOC_STORAGE_URL }}addons/addon-thingy91x_oob?$NCS_DOC_SAS_MAIN" --recursive=true
53+
fi
54+
55+
- name: Find Comment
56+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
57+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
58+
id: fc
59+
with:
60+
issue-number: ${{ env.PR }}
61+
comment-author: 'github-actions[bot]'
62+
body-includes: documentation preview
63+
64+
- name: Create or update comment
65+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
66+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
67+
with:
68+
comment-id: ${{ steps.fc.outputs.comment-id }}
69+
issue-number: ${{ env.PR }}
70+
body: |
71+
You can find the documentation preview for this PR [here](${{ vars.NCS_DOC_PR_HOSTING_URL }}addons/addon-thingy91x_oob/PR-${{ env.PR }}/).
72+
edit-mode: replace

.github/workflows/doc_remove.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Documentation Remove
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request_target:
8+
types: [closed]
9+
branches:
10+
- main
11+
12+
jobs:
13+
remove:
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- name: Try removal of PR-docs
17+
env:
18+
AZCOPY_CONCURRENCY_VALUE: 3000
19+
run: |
20+
azcopy rm "${{ vars.NCS_DOC_PR_STORAGE_URL }}addon-thingy91x_oob/PR-${{ github.event.number }}?${{ secrets.NCS_DOC_SAS_PRS }}" --recursive=true || true

0 commit comments

Comments
 (0)