Skip to content

Commit 7d33634

Browse files
committed
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 7d33634

5 files changed

Lines changed: 255 additions & 187 deletions

File tree

.github/workflows/doc-build.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Documentation Build
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
documentation_tag:
10+
type: string
11+
required: false
12+
default: "latest"
13+
description: "Label of the documentation"
14+
publish_to_prod:
15+
type: boolean
16+
default: true
17+
publish_to_dev:
18+
type: boolean
19+
default: true
20+
pull_request:
21+
types: [opened, synchronize, reopened]
22+
branches:
23+
- main
24+
paths:
25+
- '.github/workflows/doc-build.yml'
26+
- '.github/workflows/doc-publish.yml'
27+
- '**.rst'
28+
- 'docs/**'
29+
- "include/**"
30+
push:
31+
branches:
32+
- main
33+
34+
workflow_call:
35+
inputs:
36+
documentation_tag:
37+
type: string
38+
required: true
39+
default: "latest"
40+
publish_to_prod:
41+
type: boolean
42+
default: true
43+
publish_to_dev:
44+
type: boolean
45+
default: true
46+
47+
concurrency:
48+
group: ${{ github.workflow }}-${{ github.ref }}
49+
cancel-in-progress: true
50+
51+
jobs:
52+
build:
53+
runs-on: ubuntu-24.04
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
57+
with:
58+
ref: ${{ github.event.pull_request.head.sha }}
59+
60+
- name: Set up Python
61+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
62+
with:
63+
python-version: 3.12
64+
cache: pip
65+
cache-dependency-path: docs/requirements.txt
66+
pip-install: |
67+
-r docs/requirements.txt
68+
69+
- name: Build
70+
working-directory: docs
71+
run: |
72+
sphinx-build -M html . build
73+
74+
- name: Check version
75+
run: |
76+
if [[ ${GITHUB_REF#refs/heads/} == "main" ]]; then
77+
VERSION="latest"
78+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
79+
VERSION="pr-${{ github.event.number }}"
80+
fi
81+
echo "VERSION=${VERSION}"
82+
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
83+
84+
- name: Prepare Azure upload
85+
run: |
86+
PUBLISH="$PWD/publish"
87+
mkdir -p "$PUBLISH"
88+
89+
MONITOR="monitor_${{ github.run_id }}.txt"
90+
91+
# Create documentation upload files
92+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
93+
ARCHIVE="legacy-addon-thingy91x_oob-pr-${{ github.event.number }}.zip"
94+
echo "publish2 dev PR-${{ github.event.number }} ${ARCHIVE}" > "${MONITOR}"
95+
echo "${{ github.event.number }}" > pr.txt
96+
else
97+
ARCHIVE="legacy-addon-thingy91x_oob-${VERSION}.zip"
98+
echo "publish2 main ${VERSION} ${ARCHIVE}" > "${MONITOR}"
99+
fi
100+
101+
pushd "docs/build/html"
102+
zip -rq "${ARCHIVE}" .
103+
mv "${ARCHIVE}" "$PUBLISH"
104+
popd
105+
106+
mv "${MONITOR}" "$PUBLISH"
107+
if [[ -f pr.txt ]]; then mv pr.txt "$PUBLISH"; fi
108+
109+
- name: Prepare Zoomin upload
110+
if: ${{ github.event_name == 'push' }}
111+
run: |
112+
PUBLISH="$PWD/publish"
113+
mkdir -p "$PUBLISH"
114+
115+
OUTDIR=docs/build/html
116+
ARCHIVE="addon-thingy91x_oob_$VERSION.zip"
117+
118+
cp docs/custom.properties "$OUTDIR/custom.properties"
119+
sed -i 's/__VERSION__/'"$VERSION"'/g' "$OUTDIR/custom.properties"
120+
121+
cp docs/tags.yml "$OUTDIR/tags.yml"
122+
sed -i 's/__VERSION__/'"$VERSION"'/g' "$OUTDIR/tags.yml"
123+
124+
pushd "$OUTDIR"
125+
zip -rq "$ARCHIVE" .
126+
mv "$ARCHIVE" "$PUBLISH"
127+
popd
128+
129+
- name: Store
130+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'external') || contains(github.event.pull_request.labels.*.name, 'CI-trusted-author') }}
131+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
132+
with:
133+
name: docs
134+
retention-days: 5
135+
path: |
136+
publish/*

.github/workflows/doc-publish.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 Zoomin documentation
43+
if: >
44+
github.event.workflow_run.head_branch == 'main' &&
45+
github.event.workflow_run.head_repository.full_name == github.repository
46+
env:
47+
NCS_ZOOMIN_KEY: ${{ secrets.ZOOMIN_KEY }}
48+
run: |
49+
# trust server
50+
mkdir -p ~/.ssh
51+
ssh-keyscan upload-v1.zoominsoftware.io >> ~/.ssh/known_hosts
52+
53+
# prepare key
54+
touch zoomin_key
55+
chmod 600 zoomin_key
56+
echo "${{ secrets.ZOOMIN_KEY }}" > zoomin_key
57+
58+
# upload files
59+
for file in docs/addon-thingy91x_oob*.zip; do
60+
sftp -v -i zoomin_key nordic@upload-v1.zoominsoftware.io <<EOF
61+
cd docs-be.nordicsemi.com/sphinx-html/incoming
62+
put ${file}
63+
cd ../../../nordic-be-dev.zoominsoftware.io/sphinx-html/incoming
64+
put ${file}
65+
quit
66+
EOF
67+
done
68+
69+
- name: Upload to Azure storage
70+
working-directory: docs
71+
env:
72+
AZCOPY_CONCURRENCY_VALUE: 1024
73+
NCS_DOC_SAS_PRS: ${{ secrets.NCS_DOC_SAS_PRS }}
74+
NCS_DOC_SAS_MAIN: ${{ secrets.NCS_DOC_SAS_MAIN }}
75+
run: |
76+
if [[ "${{ github.event.workflow_run.event }}" == "pull_request" ]]; then
77+
azcopy cp $OUTDIR "${{ vars.NCS_DOC_PR_STORAGE_URL }}addon-thingy91x_oob?$NCS_DOC_SAS_PRS" --recursive=true
78+
else
79+
azcopy cp $OUTDIR "${{ vars.NCS_DOC_STORAGE_URL }}addon-thingy91x_oob?$NCS_DOC_SAS_MAIN" --recursive=true
80+
fi
81+
82+
- name: Find Comment
83+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
84+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
85+
id: fc
86+
with:
87+
issue-number: ${{ env.PR }}
88+
comment-author: 'github-actions[bot]'
89+
body-includes: documentation preview
90+
91+
- name: Create or update comment
92+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
93+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
94+
with:
95+
comment-id: ${{ steps.fc.outputs.comment-id }}
96+
issue-number: ${{ env.PR }}
97+
body: |
98+
You can find the documentation preview for this PR [here](${{ vars.NCS_DOC_PR_HOSTING_URL }}addon-thingy91x_oob/PR-${{ env.PR }}/).
99+
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

.github/workflows/docs-build-and-publish-zooomin.yml

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)