-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yml
233 lines (212 loc) · 8.89 KB
/
action.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
name: docfx-unitypackage
description: DocFX Unity package is a GitHub action for deploying a DocFX website for Unity packages to GitHub Pages.
author: Casey Hofland
branding:
icon: 'file-text'
color: 'white'
inputs:
github_token:
description: 'Set a generated GITHUB_TOKEN for pushing to the remote branch.'
required: false
runs:
using: "composite"
steps:
# This step needs to happen before anything else!
- name: Move everything inside the manual/ folder.
shell: bash
run: |
if [ -d Documentation~ ] && [ "$(ls -A Documentation~)" ]; then
mv -v Documentation~/ manual/
mkdir -p Documentation~
mv -v manual/ Documentation~/manual/
else
mkdir -p Documentation~/manual
fi
# Generate pages, tables of contents, the docfx.json and anything the docfx needs.
- name: Generate index page
shell: bash
run: echo 'This page redirects to the [manual](manual/).' > Documentation~/index.md
- name: Generate main Table of Contents
shell: bash
run: |
echo '- name: Manual
href: manual/
homepage: manual/index.md
- name: Scripting API
href: api/
homepage: api/index.md' > Documentation~/toc.yml
- name: Generate manual Table of Contents
shell: bash
# Replace * and 5 consecutive spaces with # in the Table of Contents to convert Unity's format to DocFX's format.
run: |
if [ -f Documentation~/manual/TableOfContents.md ]; then
mv Documentation~/manual/TableOfContents.md Documentation~/manual/toc.md
fi
if [ -f Documentation~/manual/toc.md ]; then
sed -i -e 's/*/#/g' Documentation~/manual/toc.md
sed -i -e 's/ /#/g' Documentation~/manual/toc.md
fi
- name: Generate manual index page
shell: bash
run: |
if [ ! -f Documentation~/manual/index.md ] && [ -f README.md ]; then
cp README.md Documentation~/manual/index.md
fi
- name: Generate api index page
shell: bash
run: |
mkdir -p Documentation~/api
if [ -f Documentation~/api_index.md ]; then
cp Documentation~/api_index.md Documentation~/api/index.md
rm Documentation~/api_index.md
else
echo 'This is the documentation for the Scripting APIs of this package.' > Documentation~/api/index.md
fi
- name: Generate changelog page
shell: bash
run: |
if [ -f CHANGELOG.md ]; then
mkdir -p Documentation~/changelog
cp CHANGELOG.md Documentation~/changelog/CHANGELOG.md
echo '# [Changes](CHANGELOG.md)' > Documentation~/changelog/toc.md
echo '- name: Changelog' >> Documentation~/toc.yml
echo ' href: changelog/' >> Documentation~/toc.yml
echo ' homepage: changelog/CHANGELOG.md' >> Documentation~/toc.yml
fi
- name: Generate license page
shell: bash
run: |
if [ -f LICENSE ] && [ ! -f LICENSE.md ]; then
mv -v LICENSE LICENSE.md
fi
if [ -f LICENSE.md ]; then
mkdir -p Documentation~/license
cp LICENSE.md Documentation~/license/LICENSE.md
echo '# [License](LICENSE.md)' > Documentation~/license/toc.md
if [ -f 'Third Party Notices.md' ]; then
cp 'Third Party Notices.md' 'Documentation~/license/Third Party Notices.md'
sed -i '1i# [Third Party Notices](Third Party Notices.md)' Documentation~/license/toc.md
fi
echo '- name: License' >> Documentation~/toc.yml
echo ' href: license/' >> Documentation~/toc.yml
echo ' homepage: license/LICENSE.md' >> Documentation~/toc.yml
fi
- name: Read package.json
shell: bash
run: |
if [ -f package.json ]; then
content=`cat package.json`
else
content='{}'
fi
echo 'package<<EOF' >> $GITHUB_ENV
echo $content >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Generate docfx.json
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url')
echo '{
"metadata": [{
"src": [{"src": "..", "files": ["**/*.cs"]}],
"dest": "api",
"globalNamespaceId": "Global",
"allowCompilationErrors": true
}],
"build": {
"globalMetadata": {
"_appTitle": "'${{ fromJson(env.package).displayName }}' | '${{ fromJson(env.package).version }}'",
"_appFooter": "<span>Made by <a href=\"https://github.com/'$GITHUB_REPOSITORY_OWNER'\" target=\"_blank\">'$GITHUB_REPOSITORY_OWNER'</a> using <a href=\"https://dotnet.github.io/docfx\" target=\"_blank\">DocFX</a></span>",
"_enableSearch": true,
"_enableNewTab": false,
"_disableNewTab": true,
"_disableContribution": true,
"_disableNextArticle": true
},
"fileMetadata": {
"_disableContribution": {"manual/**/*.md": false}
},
"globalMetadataFiles": [
],
"content": [
{"files": ["index.md", "toc.yml"]},
{"src": "license", "files": ["*.md"], "dest": "license"},
{"src": "changelog", "files": ["*.md"], "dest": "changelog"},
{"src": "api", "files": ["*.yml", "index.md"], "dest": "api"},
{"src": "manual", "files": ["**/*.md"], "dest": "manual"}
],
"resource": [{"files": ["manual/images/*"]}],
"template": ["default", "modern"],
"sitemap": {"baseUrl": "'$url'"},
"xref": ["'$url'"],
"xrefService": ["https://xref.docs.microsoft.com/query?uid={uid}"],
"dest": "../_site"
}
}' > Documentation~/docfx.json
- name: Set Global Metadata Files if exists
shell: bash
run: |
if [ -f Documentation~/manual/config.json ] && [ -f Documentation~/manual/projectMetadata.json ]; then
sed -i '22i\ "manual/config.json"' Documentation~/docfx.json
sed -i '22i\ "manual/projectMetadata.json",' Documentation~/docfx.json
elif [ -f Documentation~/manual/config.json ]; then
sed -i '22i\ "manual/config.json"' Documentation~/docfx.json
elif [ -f Documentation~/manual/projectMetadata.json ]; then
sed -i '22i\ "manual/projectMetadata.json"' Documentation~/docfx.json
fi
- name: Disable toc if not exists
shell: bash
run: |
if [ ! -f Documentation~/manual/toc.md ]; then
sed -i '19i\ "_disableToc": {"manual/**/*.md": false},' Documentation~/docfx.json
sed -i '19i\ "_layout": {"manual/**/*.md": "landing"},' Documentation~/docfx.json
fi
- name: Set favicon if exists
shell: bash
run: |
faviconPattern="Documentation~/manual/images/favicon.*"
if compgen -G $faviconPattern > /dev/null; then
favicons=( $faviconPattern )
faviconPath=${favicons[0]}
relativeFaviconPath=${faviconPath:15}
sed -i '12i\ "_appFaviconPath": "'${relativeFaviconPath}'",' Documentation~/docfx.json
fi
- name: Set logo if exists
shell: bash
run: |
logoPattern="Documentation~/manual/images/logo.*"
if compgen -G $logoPattern > /dev/null; then
logos=( $logoPattern )
logoPath=${logos[0]}
relativeLogoPath=${logoPath:15}
sed -i '12i\ "_appLogoPath": "'${relativeLogoPath}'",' Documentation~/docfx.json
fi
- name: Set filter if exists
shell: bash
run: |
if [ -f Documentation~/manual/filter.yml ]; then
sed -i '5i\ "filter": "manual/filter.yml",' Documentation~/docfx.json
elif [ -f Documentation~/manual/filter.yaml ]; then
sed -i '5i\ "filter": "manual/filter.yaml",' Documentation~/docfx.json
fi
# Build docfx site through the Documentation~ folder
- name: Dotnet Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.x
- name: Dotnet Update
shell: bash
run: dotnet tool update -g docfx
- name: Build
shell: bash
run: docfx Documentation~/docfx.json
# Generate a redirect to the manual/ page, taking protocol and custom domain names into account.
- name: Generate redirect
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url')
sed -i '/<\/head>/i\ <meta http-equiv="refresh" content="0;URL='"$url"manual/'">' _site/index.html