-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (167 loc) · 6.69 KB
/
publish-documentation.yml
File metadata and controls
191 lines (167 loc) · 6.69 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
name: 'Publish documentation'
on:
workflow_dispatch:
workflow_call:
permissions:
actions: read
pages: write
id-token: write
concurrency:
group: publish-docs-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
dotnet-sdk-version: '10.x'
jobs:
validate-branch:
name: 'Validate branch'
runs-on: ubuntu-latest
steps:
- name: 'Ensure documentation is published from a release branch'
if: ${{ !startsWith(github.ref_name, 'release/') }}
run: |
echo "Documentation should only be published from 'release/**' branches."
echo "Current branch: '${{ github.ref_name }}'"
exit 1
workflow-variables:
name: 'Workflow variables'
needs: [validate-branch]
runs-on: ubuntu-latest
outputs:
github-run-number: ${{ github.run_number }}
steps:
- name: 'Workflow variables'
id: github
run: |
echo "github-run-number:${{ github.run_number }}"
versioning:
name: 'Extract version'
needs: [workflow-variables]
runs-on: ubuntu-latest
outputs:
friendly-version: ${{ steps.versioning.outputs.version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
with:
fetch-depth: 0 # Ensure the full git history is available for versioning
- name: 'Setup .NET ${{ env.dotnet-sdk-version }}'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Extract version from branch name'
id: versioning
uses: './.github/actions/versioning/extract-version'
with:
branch-name: ${{ github.ref_name }}
generate-docs:
name: 'Generate documentation'
needs: [workflow-variables, versioning]
runs-on: ubuntu-latest
env:
friendly-version: ${{ needs.versioning.outputs.friendly-version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: 'Setup .NET ${{ env.dotnet-sdk-version }}'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Install docfx'
shell: bash
run: dotnet tool update -g docfx
- name: 'Regenerate API metadata for v${{ env.friendly-version }}'
shell: bash
run: |
rm -rf api-reference/${{ env.friendly-version }}
cd api-reference
docfx metadata assembly-metadata.json
mv temp ${{ env.friendly-version }}
- name: 'Snapshot guide for v${{ env.friendly-version }}'
shell: bash
run: |
cp -r api-reference/guide api-reference/${{ env.friendly-version }}/guide
- name: 'Discover all versions'
id: discover-versions
shell: bash
run: |
versions=$(ls api-reference/ | grep -E '^[0-9]+\.[0-9]+$' | sort -V | paste -sd ',' -)
latest=$(ls api-reference/ | grep -E '^[0-9]+\.[0-9]+$' | sort -V | tail -1)
echo "versions=$versions" >> $GITHUB_OUTPUT
echo "latest=$latest" >> $GITHUB_OUTPUT
- name: 'Update versions.json'
shell: bash
run: |
versions_array=$(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' '\n' | jq -R . | jq -s .)
jq --arg latest "${{ steps.discover-versions.outputs.latest }}" \
--argjson versions "$versions_array" \
'.latest = $latest | .versions = $versions' \
api-reference/versions.json > /tmp/versions.json
mv /tmp/versions.json api-reference/versions.json
- name: 'Update api-reference.json with version groups'
shell: bash
run: |
cp api-reference/api-reference.json /tmp/api-reference.json
for ver in $(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' ' '); do
jq --arg ver "$ver" --arg group "v${ver}" \
'.build.content += [
{"dest": "", "files": ["*.yml"], "group": $group, "src": $ver, "rootTocPath": "~/toc.html"},
{"dest": "guide", "files": ["*.{md,yml}"], "group": $group, "src": ($ver + "/guide"), "rootTocPath": "~/toc.html"}
] |
.build.groups = (.build.groups // {}) |
.build.groups[$group] = {"dest": $ver}' \
/tmp/api-reference.json > /tmp/api-reference-new.json
mv /tmp/api-reference-new.json /tmp/api-reference.json
done
mv /tmp/api-reference.json api-reference/api-reference.json
- name: 'Update toc.yml with navigation links'
shell: bash
run: |
latest="${{ steps.discover-versions.outputs.latest }}"
{
echo "### YamlMime:TableOfContent"
echo "- name: Guide"
echo " href: ${latest}/guide/getting-started.html"
echo "- name: API Reference"
echo " href: ${latest}/PolylineAlgorithm.html"
} > api-reference/toc.yml
- name: 'Inject latest version and released versions table into index.md'
shell: bash
run: |
latest="${{ steps.discover-versions.outputs.latest }}"
{
echo "## Released Versions"
echo ""
echo "| Version | Guide | API Reference |"
echo "|---------|-------|---------------|"
for ver in $(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' '\n' | sort -Vr); do
if [ "$ver" = "$latest" ]; then
label="v${ver} (latest)"
else
label="v${ver}"
fi
echo "| ${label} | [Guide](${ver}/guide/getting-started.html) | [API Reference](${ver}/PolylineAlgorithm.html) |"
done
} > /tmp/versions_section.md
awk '/{versions_section}/{while((getline line < "/tmp/versions_section.md") > 0) print line; close("/tmp/versions_section.md"); next} {print}' \
api-reference/index.md > /tmp/index.md
mv /tmp/index.md api-reference/index.md
sed -i "s|{version}|${latest}|g" api-reference/index.md
- name: 'Build documentation'
shell: bash
run: docfx build api-reference/api-reference.json
- name: 'Upload artifact'
uses: actions/upload-pages-artifact@v5
with:
name: github-pages
path: './api-reference/_docs'
publish-docs:
name: 'Publish documentation'
needs: [workflow-variables, versioning, generate-docs]
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: 'Deploy to GitHub Pages'
id: deployment
uses: actions/deploy-pages@v5