Repository navigation
231 lines (202 loc) · 7.77 KB
/
Copy pathtechdocs-docs.yml
File metadata and controls
231 lines (202 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Techdocs - Docs
# Builds the docs/ directory, which documents the project itself, and
# publishes it as the TechDocs of the entity in the root catalog-info.yaml.
on:
workflow_dispatch:
push:
paths:
- 'docs/**'
- 'mkdocs.yml'
- '.github/workflows/techdocs-docs.yml'
concurrency:
group: techdocs-docs-${{ github.ref }}
# Let a publish finish instead of cancelling it part way through.
cancel-in-progress: false
jobs:
check:
name: Check for docs
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
found: ${{ steps.docs.outputs.found }}
steps:
- name: Setup job workspace
uses: ServerlessOpsIO/gha-setup-workspace@v2
# A project may have no docs, in which case there is nothing to build.
- name: Look for Markdown
id: docs
run: |
if [ -n "$(find docs -name '*.md' -print -quit 2>/dev/null)" ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
echo "::notice::No Markdown files in docs/, nothing to build"
fi
build:
name: Build docs
needs:
- check
if: needs.check.outputs.found == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
env:
CATALOG_FILE: catalog-info.yaml
steps:
- name: Setup job workspace
uses: ServerlessOpsIO/gha-setup-workspace@v2
- name: Setup NodeJS
id: install-node
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Setup Python
id: install-python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install MkDocs
run: pip install 'mkdocs-techdocs-core==1.*' 'markdown-inline-mermaid==1.*'
# Mermaid diagrams are rendered to inline SVG at build time by
# markdown-inline-mermaid, which runs the Mermaid CLI (mmdc) for each
# diagram. The CLI drives a headless browser, which is installed
# explicitly because npm may not run the install script that fetches it.
- name: Install Mermaid CLI
env:
MERMAID_DIR: ${{ runner.temp }}/mermaid
run: |
npm install --prefix "${MERMAID_DIR}" '@mermaid-js/mermaid-cli@12'
"${MERMAID_DIR}/node_modules/.bin/puppeteer" browsers install chrome-headless-shell
echo "${MERMAID_DIR}/node_modules/.bin" >> "$GITHUB_PATH"
# Lay docs/ out as a MkDocs project in $RUNNER_TEMP/build, outside the git
# checkout. A mkdocs.yml is generated unless the project supplies its own.
- name: Stage MkDocs project
env:
WORK_DIR: ${{ runner.temp }}/build/source
run: |
mkdir -p "${WORK_DIR}/docs"
cp -R docs/. "${WORK_DIR}/docs/"
title=''
description=''
if [ -f "${CATALOG_FILE}" ]; then
title=$(yq 'select(document_index == 0) | .metadata.title // .metadata.name // ""' "${CATALOG_FILE}")
description=$(yq 'select(document_index == 0) | .metadata.description // ""' "${CATALOG_FILE}")
fi
export TITLE="${title:-docs}"
export DESCRIPTION="${description}"
if [ -f mkdocs.yml ]; then
cp mkdocs.yml "${WORK_DIR}/mkdocs.yml"
else
yq -n '
.site_name = strenv(TITLE) |
.site_description = strenv(DESCRIPTION) |
.docs_dir = "docs" |
.plugins = ["techdocs-core"]
' > "${WORK_DIR}/mkdocs.yml"
fi
# Enable Mermaid rendering, including in a mkdocs.yml the project
# supplied, unless it is already enabled there.
yq -i '
.markdown_extensions = (.markdown_extensions // []) |
with(select(.markdown_extensions | any_c(. == "markdown_inline_mermaid") | not);
.markdown_extensions += ["markdown_inline_mermaid"])
' "${WORK_DIR}/mkdocs.yml"
# TechDocs needs a landing page at the site root.
if [ ! -f "${WORK_DIR}/docs/index.md" ]; then
{
printf '# %s\n\n' "${TITLE}"
if [ -n "${DESCRIPTION}" ]; then
printf '%s\n\n' "${DESCRIPTION}"
fi
} > "${WORK_DIR}/docs/index.md"
fi
cat "${WORK_DIR}/mkdocs.yml"
- name: Build TechDocs
env:
WORK_DIR: ${{ runner.temp }}/build/source
SITE_DIR: ${{ runner.temp }}/build/artifact/site
run: |
npx --yes @techdocs/cli generate \
--no-docker \
--verbose \
--source-dir "${WORK_DIR}" \
--output-dir "${SITE_DIR}" \
--dangerouslyAllowAdditionalExtensions markdown_inline_mermaid
# A diagram that fails to render is written into the page as an error
# instead of failing the build, so look for it.
if grep -rl --include='*.html' '<pre>Error : ' "${SITE_DIR}"; then
echo "::error::A Mermaid diagram failed to render in the pages listed above"
exit 1
fi
# The deploy job has no checkout, so the catalog-info.yaml that names the
# entity to publish to travels with the site. It sits beside site/, not
# in it, so it is not published.
- name: Bundle catalog-info.yaml
env:
ARTIFACT_DIR: ${{ runner.temp }}/build/artifact
run: |
if [ ! -f "${CATALOG_FILE}" ]; then
echo "::error::${CATALOG_FILE} is required to publish TechDocs"
exit 1
fi
cp "${CATALOG_FILE}" "${ARTIFACT_DIR}/catalog-info.yaml"
- name: Upload TechDocs site
uses: actions/upload-artifact@v7
with:
name: techdocs-docs
path: ${{ runner.temp }}/build/artifact
if-no-files-found: error
deploy:
name: Deploy docs
needs:
- build
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Setup job workspace
uses: ServerlessOpsIO/gha-setup-workspace@v2
with:
checkout_artifact: true
- name: Setup NodeJS
id: install-node
uses: actions/setup-node@v6
with:
node-version: '24'
# The artifact holds the site in site/ and, beside it, the
# catalog-info.yaml that names the entity to publish to.
- name: Download TechDocs site
uses: actions/download-artifact@v8
with:
name: techdocs-docs
path: ${{ runner.temp }}/techdocs
- name: Assume AWS Credentials
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1
with:
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
deploy_aws_account_id: ${{ secrets.DEPLOYMENT_ACCOUNT_ID }}
# TechDocs are stored under the entity's namespace/kind/name, which comes
# from the project's catalog-info.yaml.
- name: Publish TechDocs
env:
SITE_DIR: ${{ runner.temp }}/techdocs/site
CATALOG_FILE: ${{ runner.temp }}/techdocs/catalog-info.yaml
TECHDOCS_BUCKET: ${{ vars.TECHDOCS_BUCKET }}
run: |
if [ -z "${TECHDOCS_BUCKET}" ]; then
echo "::error::The TECHDOCS_BUCKET variable is not set"
exit 1
fi
if [ ! -f "${CATALOG_FILE}" ]; then
echo "::error::${CATALOG_FILE} is required to publish TechDocs"
exit 1
fi
entity=$(yq 'select(document_index == 0) | (.metadata.namespace // "default") + "/" + .kind + "/" + .metadata.name' "${CATALOG_FILE}")
echo "Publishing ${entity} to ${TECHDOCS_BUCKET}"
npx --yes @techdocs/cli publish \
--publisher-type awsS3 \
--storage-name "${TECHDOCS_BUCKET}" \
--entity "${entity}" \
--directory "${SITE_DIR}"