Skip to content

Commit 06c0f8c

Browse files
authored
Merge pull request #319 from Staffbase/CIV-813-Add-Reusable-Workflow-for-TechDocs-in-Monorepos
CIV-813 Add Reusable Workflow for TechDocs in Monorepos
2 parents 98c45ae + f4b4eb6 commit 06c0f8c

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: TechDocs
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
azure-account-name:
7+
required: true
8+
azure-account-key:
9+
required: true
10+
jobs:
11+
techdocs:
12+
name: TechDocs
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4.2.2
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v4.2.0
21+
22+
- name: Setup Python
23+
uses: actions/setup-python@v5.5.0
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Install techdocs-cli
28+
run: sudo npm install -g @techdocs/cli
29+
30+
- name: Install mkdocs and mkdocs plugins
31+
run: |
32+
python -m pip install mkdocs-techdocs-core==1.* mkdocs-awesome-pages-plugin==2.* mkdocs-awesome-nav==3.0.0
33+
34+
- name: Generate and Publish TechDocs
35+
run: |
36+
find . -name "catalog-info.yaml" -print0 | while read -r -d $'\0' file
37+
do
38+
echo ""
39+
echo "Working on $file"
40+
i="0"
41+
while true; do
42+
idx=$i
43+
i=$((i+1))
44+
45+
# .kind is mandatory and can be used to check whether there is another document
46+
kind=$(yq e "select(documentIndex == $idx) | .kind" "$file")
47+
if [ -z "$kind" ]; then
48+
break
49+
fi
50+
51+
name=$(yq e "select(documentIndex == $idx) | .metadata.name" "$file")
52+
# Only process documents with techdocs-ref annotation
53+
techDocsConfigured=$(yq e "select(documentIndex == $idx) | .metadata.annotations | has(\"backstage.io/techdocs-ref\")" "$file")
54+
if [ "$techDocsConfigured" == false ]; then
55+
echo " 😥 Skip $kind/$name - TechDocs not configured"
56+
continue
57+
fi
58+
59+
echo " 📝 Publish TechDocs for $kind/$name"
60+
61+
fileDir=$(find "$file" -printf '%h' -quit)
62+
techdocs-cli generate \
63+
--no-docker \
64+
--verbose \
65+
--source-dir=$fileDir \
66+
--output-dir=$fileDir/site/ 1>/dev/null
67+
68+
techdocs-cli publish \
69+
--directory=$fileDir/site/ \
70+
--publisher-type azureBlobStorage \
71+
--storage-name techdocs \
72+
--azureAccountName ${{ secrets.azure-account-name }} \
73+
--azureAccountKey ${{ secrets.azure-account-key }} \
74+
--entity default/$kind/$name 1>/dev/null
75+
done
76+
done

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,35 @@ jobs:
456456

457457
</details>
458458

459+
### TechDocs Monorepo (Azure)
460+
461+
<details>
462+
<summary>This GitHub Action can be used for generating and publishing Backstage TechDocs for a monorepo. It is limited to an Azure Storage account.</summary>
463+
464+
```yml
465+
name: TechDocs
466+
467+
on:
468+
push:
469+
branches:
470+
- 'main'
471+
paths:
472+
- "docs/**"
473+
- "mkdocs.yml"
474+
- ".github/workflows/techdocs.yaml"
475+
476+
jobs:
477+
techdocs:
478+
uses: Staffbase/gha-workflows/.github/workflows/template_techdocs_monorepo.yml@v7.2.0
479+
secrets:
480+
# required: specifies an Azure Storage account name
481+
azure-account-name: ${{ secrets.TECHDOCS_AZURE_ACCOUNT_NAME }}
482+
# required: specifies the access key associated with the storage account
483+
azure-account-key: ${{ secrets.TECHDOCS_AZURE_ACCESS_KEY }}
484+
```
485+
486+
</details>
487+
459488
### TechDocs
460489

461490
<details>

0 commit comments

Comments
 (0)