-
Notifications
You must be signed in to change notification settings - Fork 0
236 lines (230 loc) · 8.18 KB
/
docs.yml
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
232
233
234
235
236
name: Publish Documentation
on:
release:
types:
- published
- edited
push:
branches: [ main ]
jobs:
release-context:
runs-on: ubuntu-latest
outputs:
version-name: ${{ github.ref_name }}
is-latest: ${{ steps.compare-tags.outputs.is-latest }}
steps:
- uses: joutvhu/get-release@v1
id: latest-release
with:
latest: true
throwing: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Compare tags
id: compare-tags
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
LATEST_TAG: ${{ steps.latest-release.outputs.tag_name }}
run: |
if [ "${REF_TYPE}" == 'tag' ] && [ "${REF_NAME}" == "${LATEST_TAG}" ]; then
echo 'is-latest=true' >> "${GITHUB_OUTPUT}"
else
echo 'is-latest=false' >> "${GITHUB_OUTPUT}"
fi
spm-context:
runs-on: ubuntu-latest
outputs:
package-dump: ${{ steps.dump-package.outputs.package-dump }}
steps:
- uses: swift-actions/[email protected]
with:
swift-version: '5.7'
- uses: actions/checkout@v4
# We don't use a cache here, because SPM doesn't resolve dependencies when dumping packages.
- name: Dump package
id: dump-package
run: |
delimiter="$(openssl rand -hex 8)"
echo "package-dump<<${delimiter}" >> "${GITHUB_OUTPUT}"
swift package dump-package >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
generate-docs:
needs:
- release-context
- spm-context
runs-on: macos-12
strategy:
matrix:
target: ${{ fromJson(needs.spm-context.outputs.package-dump).products.*.targets.* }}
steps:
- uses: swift-actions/[email protected]
id: swift-setup
with:
swift-version: '5.7'
- name: Read OS Version
uses: sersoft-gmbh/os-version-action@v2
id: os-version
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-${{ steps.os-version.outputs.version }}-spm-${{ steps.swift-setup.outputs.version }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-${{ steps.os-version.outputs.version }}-spm-${{ steps.swift-setup.outputs.version }}-
- uses: sersoft-gmbh/swifty-docs-action@v2
env:
ENABLE_DOCC_SUPPORT: '1'
DOCC_JSON_PRETTYPRINT: 'YES'
with:
package-version: ${{ needs.release-context.outputs.version-name }}
targets: ${{ matrix.target }}
enable-inherited-docs: true
enable-index-building: false
transform-for-static-hosting: true
hosting-base-path: ${{ github.event.repository.name }}/${{ needs.release-context.outputs.version-name }}
output: ${{ matrix.target }}-docs
- name: Package docs
env:
TARGET: ${{ matrix.target }}
run: tar -cvf "${TARGET}-docs.tar" "${TARGET}-docs"
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}-docs
path: ${{ matrix.target }}-docs.tar
publish-docs:
needs:
- release-context
- spm-context
- generate-docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
path: repository
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Extract tars
run: find artifacts -name '*.tar' -execdir tar -xvf '{}' --strip-components 1 \; -delete
- name: Merge documentations
env:
TARGETS: ${{ join(fromJson(needs.spm-context.outputs.package-dump).products.*.targets.*, ' ') }}
DOCS_BASE_DIR: repository/${{ needs.release-context.outputs.version-name }}
run: |
rm -rf "${DOCS_BASE_DIR}"
is_first=1
for target in $TARGETS; do
if [ $is_first -eq 1 ]; then
echo "Copying initial documentation for ${target}"
cp -R "artifacts/${target}-docs" "${DOCS_BASE_DIR}"
is_first=0
else
echo "Merging documentation for ${target}"
cp -R "artifacts/${target}-docs/data/documentation/"* "${DOCS_BASE_DIR}/data/documentation/"
cp -R "artifacts/${target}-docs/documentation/"* "${DOCS_BASE_DIR}/documentation/"
fi
done
echo "Deleting non-mergable metadata.json"
rm -f "${DOCS_BASE_DIR}/metadata.json"
- name: Create version index
working-directory: repository
env:
TARGET_DOCS_DIR: ${{ needs.release-context.outputs.version-name }}/documentation
INDEX_FILE: ${{ needs.release-context.outputs.version-name }}/index.html
BASE_URL: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ needs.release-context.outputs.version-name }}/documentation'
REPO_NAME: ${{ github.event.repository.name }}
run: |
target_count=0
target_list=""
single_target_name=""
for target in $(ls "${TARGET_DOCS_DIR}"); do
if [ -d "${TARGET_DOCS_DIR}/${target}" ]; then
single_target_name="${target}"
target_count=$((target_count+1))
target_list="${target_list}<li><a href=\"${BASE_URL}/${target}\"><code>${target}</code> Documentation</a></li>"
fi
done
if [ ${target_count} -gt 1 ]; then
echo "Found ${target_count} targets. Generating list..."
cat > "${INDEX_FILE}" <<EOF
<!DOCTYPE html>
<html>
<head>
<title>${REPO_NAME} Documentation</title>
</head>
<body>
<ul>
${target_list}
</ul>
</body>
</html>
EOF
else
echo "Found one target. Generating redirect file to target ${single_target_name}"
cat > "${INDEX_FILE}" <<EOF
<!DOCTYPE html>
<html>
<head>
<title>${REPO_NAME} Documentation</title>
<meta http-equiv="refresh" content="0; url=${BASE_URL}/${single_target_name}" />
</head>
<body>
<p>Redirecting...</p>
</body>
</html>
EOF
fi
- name: Create root index
working-directory: repository
env:
REDIRECT_URL: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/latest'
REPO_NAME: ${{ github.event.repository.name }}
run: |
cat > 'index.html' <<EOF
<!DOCTYPE html>
<html>
<head>
<title>${REPO_NAME} Documentation</title>
<meta http-equiv="refresh" content="0; url=${REDIRECT_URL}" />
</head>
<body>
<p>Redirecting...</p>
</body>
</html>
EOF
- name: Create latest symlink
if: ${{ needs.release-context.outputs.is-latest }}
working-directory: repository
env:
VERSION_NAME: ${{ needs.release-context.outputs.version-name }}
run: |
rm -f 'latest'
ln -s "${VERSION_NAME}" 'latest'
- name: Determine changes
id: check-changes
working-directory: repository
run: |
if [ -n "$(git status --porcelain)" ]; then
echo 'has-changes=true' >> "${GITHUB_OUTPUT}"
else
echo 'has-changes=false' >> "${GITHUB_OUTPUT}"
fi
- uses: crazy-max/ghaction-github-pages@v4
if: ${{ steps.check-changes.outputs.has-changes }}
with:
keep_history: true
build_dir: repository
commit_message: Deploy documentation for '${{ needs.release-context.outputs.version-name }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cleanup:
needs:
- generate-docs
- publish-docs
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Cleanup Artifacts
uses: joutvhu/delete-artifact@v1