Repository navigation
162 lines (135 loc) · 4.5 KB
/
Copy pathdocumentation.yml
File metadata and controls
162 lines (135 loc) · 4.5 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
name: Documentation Generation And Publishing
on:
schedule:
- cron: "0 5 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
build:
timeout-minutes: 20
name: 'Generate & upload documentation'
runs-on: ubuntu-latest
continue-on-error: true
env:
NIMBLE_COMMIT: aa8e6ea09ecac774b6fad42552569ce07bef37ec # v0.24.1
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
submodules: true
- name: Setup Nim
uses: "./.github/actions/install_nim"
with:
os: linux
cpu: amd64
shell: bash
nim_ref: v2.2.14
- name: Generate doc
run: |
nim --version
nimble --version
NIM_VERSION=$(nim --version | sed -n 's/^Nim Compiler Version \([^ ]*\).*/\1/p')
nimble --noLockfile --requires:"nim == $NIM_VERSION" --resolver:minver -l setup -y
# nim doc can "fail", but the doc is still generated
nim doc --git.url:${{ github.server_url }}/${{ github.repository }} --git.commit:${GITHUB_REF##*/} --outdir:${GITHUB_REF##*/} --project libp2p || true
# check that the folder exists
ls ${GITHUB_REF##*/}
- name: Clone the gh-pages branch
uses: actions/checkout@v6
with:
repository: ${{ github.repository }}
ref: gh-pages
path: subdoc
submodules: true
fetch-depth: 0
- name: Commit & push
run: |
cd subdoc
# Update / create this branch doc
rm -rf ${GITHUB_REF##*/}
mv ../${GITHUB_REF##*/} .
# Remove .idx files
# NOTE: git also uses idx files in his
# internal folder, hence the `*` instead of `.`
find * -name "*.idx" -delete
git add .
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name = "${{ github.actor }}"
if git diff-index --quiet HEAD --; then
echo "No documentation changes detected; skipping push."
else
git commit -a -m "update docs for ${GITHUB_REF##*/}"
git push origin gh-pages
fi
update_site:
name: 'Rebuild website'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-python@v6
with:
python-version: 3.x
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: 'stable'
- name: Generate website
run: pip install mkdocs-material && cd examples && nimble -y website
- name: Clone the gh-pages branch
uses: actions/checkout@v6
with:
repository: ${{ github.repository }}
ref: gh-pages
path: subdoc
fetch-depth: 0
- name: Commit & push
run: |
cd subdoc
# Ensure the latest changes are fetched and reset to the remote branch
git fetch origin gh-pages
git reset --hard origin/gh-pages
# Preserve API reference folders generated by the `build` job
# (for example `master/`, `vX.Y.Z/`), while fully replacing
# the mkdocs website content at the root.
api_doc_dirs=()
for dir in */; do
if [ -f "${dir}libp2p.html" ]; then
api_doc_dirs+=("${dir%/}")
fi
done
shopt -s dotglob nullglob
for path in ./*; do
base=${path#./}
if [ "$base" = ".git" ]; then
continue
fi
keep=false
for dir in "${api_doc_dirs[@]}"; do
if [ "$base" = "$dir" ]; then
keep=true
break
fi
done
if [ "$keep" = false ]; then
rm -rf "$path"
fi
done
shopt -u dotglob nullglob
cp -a ../site/. .
# Maintain backward compatibility for `/docs/...` links.
rm -rf docs
mkdir -p docs
cp -a ../site/. docs/
git add .
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git commit -m "update website"
git push origin gh-pages
fi