-
Notifications
You must be signed in to change notification settings - Fork 35
206 lines (183 loc) · 6.61 KB
/
build_main_documentation.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
name: Build PR Documentation
env:
DIFFUSERS_SLOW_IMPORT: yes
on:
workflow_call:
inputs:
commit_sha:
required: true
type: string
package:
required: true
type: string
description: "Name of the GitHub repo."
package_name:
type: string
description: "Name of the Python package if it differs from repo name."
path_to_docs:
type: string
notebook_folder:
type: string
# supply --not_python_module for HF Course
additional_args:
type: string
languages:
# supply space-separated language codes
type: string
package_path:
type: string
install_rust:
type: boolean
install_libgl1:
type: boolean
# Command to execute before building the documentation
pre_command:
type: string
repo_owner:
type: string
default: 'huggingface'
description: "Owner of the repo to build documentation for. Defaults to 'huggingface'."
version_tag_suffix:
type: string
default: "src/"
description: "Suffix to add after the version tag (e.g. 1.3.0 or main) in the documentation links."
secrets:
hf_token:
required: true
token:
required: false
jobs:
build_main_documentation:
runs-on: ubuntu-latest
container:
huggingface/transformers-doc-builder
steps:
- uses: actions/checkout@v2
with:
repository: 'huggingface/doc-builder'
path: doc-builder
- uses: actions/checkout@v2
with:
repository: '${{ inputs.repo_owner }}/${{ inputs.package }}'
path: ${{ inputs.package }}
- uses: actions/checkout@v2
if: inputs.notebook_folder != ''
with:
repository: 'huggingface/notebooks'
path: notebooks
token: ${{ secrets.token }}
- uses: actions/setup-node@v3
with:
node-version: '20'
cache-dependency-path: "kit/package-lock.json"
- name: Set env variables
run: |
if [ -z "${{ inputs.path_to_docs }}" ]
then
echo "doc_folder=${{ inputs.package }}/docs/source" >> $GITHUB_ENV
echo "path_to_docs not provided, defaulting to ${{ inputs.package }}/docs/source"
else
echo "doc_folder=${{ inputs.path_to_docs }}" >> $GITHUB_ENV
fi
if [ -z "${{ inputs.package_name }}" ];
then
echo "package_name=${{ inputs.package }}" >> $GITHUB_ENV
else
echo "package_name=${{ inputs.package_name }}" >> $GITHUB_ENV
fi
# Needed to upload zips to hf.co
- name: Install zip
run: apt-get install -y zip
- name: Install libgl1
if: inputs.install_libgl1
run: apt-get install -y libgl1
- name: Install Rust
uses: actions-rs/toolchain@v1
if: inputs.install_rust
with:
toolchain: stable
- name: Setup environment
shell: bash
run: |
pip uninstall -y doc-builder
cd doc-builder
git pull origin main
pip install .
cd ..
if [[ -n "${{ inputs.package_path }}" ]]
then
cd ${{ inputs.package_path }}
pip install .[dev]
elif [[ "${{ inputs.additional_args }}" != *"--not_python_module"* ]];
then
cd ${{ inputs.package }}
pip install .[dev]
fi
cd ..
- name: Setup git
run: |
git config --global user.name "Hugging Face Doc Builder"
git config --global user.email docs@huggingface.co
- name: Create build directory
run: |
mkdir build_dir
mkdir build_dir/${{ env.package_name }}
cd build_dir/${{ env.package_name }}
wget https://huggingface.co/datasets/hf-doc-build/doc-build/raw/main/${{ env.package_name }}/_versions.yml
- name: Run pre-command
shell: bash
run: |
if [ ! -z "${{ inputs.pre_command }}" ]
then
bash -c "${{ inputs.pre_command }}"
fi
- name: Make documentation
shell: bash
env:
NODE_OPTIONS: --max-old-space-size=6656
run: |
echo "doc_folder has been set to ${{ env.doc_folder }}"
cd doc-builder
args="--build_dir ../build_dir --clean --html ${{ inputs.additional_args }} --repo_owner ${{ inputs.repo_owner }} --repo_name ${{ inputs.package }} --version_tag_suffix=${{ inputs.version_tag_suffix }}"
if [ ! -z "${{ inputs.notebook_folder }}" ];
then
args="$args --notebook_dir ../notebook_dir"
fi
if [ -z "${{ inputs.languages }}" ];
then
echo "languages not provided, defaulting to English"
doc-builder build ${{ env.package_name }} ../${{ env.doc_folder }} $args
else
IFS=', ' read -r -a langs <<< "${{ inputs.languages }}"
for lang in "${langs[@]}"
do
echo "Generating docs for language $lang"
doc-builder build ${{ env.package_name }} ../${{ env.doc_folder }}/$lang $args --language $lang
done
fi
cd ..
- name: Push to repositories
run: |
cd build_dir
doc-builder push ${{ env.package_name }} --doc_build_repo_id "hf-doc-build/doc-build" --token "${{ secrets.hf_token }}" --commit_msg "Updated with commit ${{ inputs.commit_sha }} See: https://github.com/${{ inputs.repo_owner }}/${{ inputs.package }}/commit/${{ inputs.commit_sha }}" --n_retries 5 --upload_version_yml
cd ..
if [ -d "notebook_dir" ]
then
cd notebooks
git pull
cp -r ../notebook_dir/. ${{ inputs.notebook_folder }}
git status
if [[ `git status --porcelain` ]]; then
git add ${{ inputs.notebook_folder }}
git commit -m "Updated ${{ inputs.package }} doc notebooks with commit ${{ inputs.commit_sha }} \n\nSee: https://github.com/huggingface/${{ inputs.package }}/commit/${{ inputs.commit_sha }}"
git push origin main ||
(echo "Failed on the first try, rebasing and pushing again" && git pull --rebase && git push origin main) ||
(echo "Failed on the second try, rebasing and pushing again" && git pull --rebase && git push origin main)
else
echo "No diff in the notebooks."
fi
cd ..
else
echo "Notebooks creation was not enabled."
fi
shell: bash