|
| 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 |
0 commit comments