-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (165 loc) · 6.68 KB
/
Copy pathpublish_docs.yml
File metadata and controls
206 lines (165 loc) · 6.68 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
# TorchMeter, AGPL-3.0 license
# Author: Ahzyuan
# Repo: https://github.com/TorchMeter/torchmeter
name: 📤 Deploy TorchMeter Docs 📜
on:
workflow_dispatch:
inputs:
repo_name:
description: 'The name of the repo inside TorchMeter that contains the docs files'
default: 'torchmeter'
required: true
type: string
schedule:
# Runs every day at 00:00 UTC
- cron: "0 0 * * *"
permissions:
contents: write
pages: write
id-token: write
jobs:
Get-Latest-Version:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.latest-tag.outputs.tag }}
steps:
- name: Fetch Code
uses: actions/checkout@v4
with:
repository: TorchMeter/${{ github.event.inputs.repo_name || 'torchmeter' }}
fetch-depth: 0
- name: Check Docs files
run: |
if [ ! -d docs ]; then
echo -e "\n❌ Docs directory does not exist" >&2
exit 1
elif [ ! -f mkdocs.yml ]; then
echo -e "\n❌ mkdocs.yml does not exist" >&2
exit 1
else
echo -e "\n✅ All necessary files for building documentation are ready"
fi
- name: Get Latest Tag
id: latest-tag
run: |
tags=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags)
LATEST_TAG=""
found=0
for tag in $tags; do
if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
LATEST_TAG=$tag
found=1
break
fi
done
if [ $found -ne 1 ]; then
echo -e "\n❌ No valid tag found matching format vA.B.C" >&2
exit 1
fi
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo -e "\n✅ Docs will be built for version $LATEST_TAG"
Deploy:
runs-on: ubuntu-latest
needs: Get-Latest-Version
if: github.repository == 'TorchMeter/torchmeter.github.io'
steps:
- name: Fetch Code
uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Cache Mkdocs
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-
# - name: Setup Drawio
# run: |
# set -eo pipefail
# drawio_arch=amd64
# drawio_version=18.1.3
# drawio_sha256sum=39a50f25ad52d6909c5c18d89a7cfc193e8e31fb98458a390c0a0709d22e9e10
# drawio_deb="drawio-${drawio_arch}-${drawio_version}.deb"
# drawio_url="https://github.com/jgraph/drawio-desktop/releases/download/v${drawio_version}/${drawio_deb}"
# curl -L -o "$drawio_deb" "$drawio_url" &
# sudo apt-get install -y libasound2t64 xvfb &
# wait
# sha256sum --check <<<"${drawio_sha256sum} $drawio_deb"
# sudo apt-get install -y ./"$drawio_deb"
- name: Prepare for Building Docs
run: |
WORKING_PATH=$(pwd)
set -eo pipefail
# clone torchmeter's assets and source code in parallel
git clone https://github.com/TorchMeter/assets.git /tmp/torchmeter-assets &
git clone https://github.com/TorchMeter/${{ github.event.inputs.repo_name || 'torchmeter' }}.git /tmp/torchmeter-src &
wait
# checkout the correct version
(cd /tmp/torchmeter-assets && git checkout ${{ needs.Get-Latest-Version.outputs.tag }} || git checkout master) &
(cd /tmp/torchmeter-src && git checkout ${{ needs.Get-Latest-Version.outputs.tag }}) &
wait
# copy docs-related files to working directory in parallel
cp -rfL /tmp/torchmeter-src/docs $WORKING_PATH/docs &
cp -rfL /tmp/torchmeter-src/torchmeter $WORKING_PATH/torchmeter &
cp -f /tmp/torchmeter-src/mkdocs.yml $WORKING_PATH/mkdocs.yml &
cp -f /tmp/torchmeter-src/default_cfg.yaml $WORKING_PATH/default_cfg.yaml &
wait
# link to assets for all locales directories
cd $WORKING_PATH/docs/src/
for dir in ./*/; do
if [ -d "$dir" ]; then
ln -sf /tmp/torchmeter-assets "$dir/assets" &
fi
done
wait
# install dependencies
python3 -m pip install --upgrade pip
DEPS=$(python -c "import configparser; c=configparser.ConfigParser(); c.read('/tmp/torchmeter-src/setup.cfg'); print(' '.join(c['options.extras_require']['docs'].split('\n')))")
python3 -m pip install $DEPS
# pin mkdocs-jupyter version to avoid breaking changes (independent of tag)
python3 -m pip install mkdocs-jupyter==0.25.1
cd $WORKING_PATH
- name: Deploy Stable
run: |
# mkdocs gh-deploy --force
git checkout gh-pages || git checkout --orphan gh-pages
git pull origin gh-pages --depth=1 || echo "No remote changes to pull"
git checkout master
# xvfb-run -a mike deploy -pu ${{ needs.Get-Latest-Version.outputs.tag }} latest
mike deploy -pu ${{ needs.Get-Latest-Version.outputs.tag }} latest
mike set-default -p latest
- name: Deploy Dev
run: |
WORKING_PATH=$(pwd)
rm -rf ./*
set -eo pipefail
# switch to master branch
(cd /tmp/torchmeter-assets && git checkout master) &
(cd /tmp/torchmeter-src && git checkout master) &
wait
# copy docs-related files to working directory in parallel
cp -rfL /tmp/torchmeter-src/docs $WORKING_PATH/docs &
cp -rfL /tmp/torchmeter-src/torchmeter $WORKING_PATH/torchmeter &
cp -f /tmp/torchmeter-src/mkdocs.yml $WORKING_PATH/mkdocs.yml &
cp -f /tmp/torchmeter-src/default_cfg.yaml $WORKING_PATH/default_cfg.yaml &
wait
# link to assets for all locales directories
cd $WORKING_PATH/docs/src/
for dir in ./*/; do
if [ -d "$dir" ]; then
ln -sf /tmp/torchmeter-assets "$dir/assets" &
fi
done
wait
git checkout gh-pages || git checkout --orphan gh-pages
git pull origin gh-pages --depth=1 || echo "No remote changes to pull"
git checkout master
cd $WORKING_PATH
# xvfb-run -a mike deploy -pu dev
mike deploy -pu dev