-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (213 loc) · 7.69 KB
/
ci.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
237
238
239
240
241
242
243
244
245
246
247
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
- name: Get Yarn Cache Directory Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Get Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn
- name: Build Code
run: yarn build:only
format:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
- name: Get Yarn Cache Directory Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Get Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn
- name: Check Format
run: yarn format:check
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
- name: Get Yarn Cache Directory Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Get Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn
- name: Lint Code
run: yarn lint
# test:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
# - name: Use Node.js v16
# uses: actions/setup-node@v2
# with:
# node-version: '16.x'
# registry-url: 'https://registry.npmjs.org'
# - name: Cache Dependencies
# uses: actions/cache@v1
# with:
# path: |
# ~/.npm
# ./node_modules
# key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.OS }}-cache-
# - name: Install dependencies
# run: yarn
# - name: Run Tests
# run: yarn test
generate-docs:
runs-on: ubuntu-latest
permissions:
contents: write
if: success() && github.event_name == 'push' && github.ref == 'refs/heads/stable'
needs: [build, format, lint]
steps:
- name: Use NodeJS v16
uses: actions/setup-node@v2
with:
node-version: "16"
- name: Setup
id: setup
run: |
echo "::group::Generating temporary directories..."
gitdir=`mktemp -d`
moddir=`mktemp -d`
docsdir=`mktemp -d`
echo "::endgroup::"
echo "::group::Cloning repository"
echo "::debug::Cloning repository to $gitdir"
git clone "https://github.com/$GITHUB_REPOSITORY.git" "$gitdir" --depth=1 --progress --branch=stable --single-branch --verbose
echo "::debug::Cloning repository to $docsdir"
git clone "https://github.com/$GITHUB_REPOSITORY.git" "$docsdir" --depth=1 --progress --branch=docs --single-branch --verbose
echo "::endgroup::"
echo "::group::Setting up cloned repositories"
cd "$gitdir"
git config advice.detachedHead false
if ! git checkout --force "$GITHUB_SHA"; then
echo "::error::Failed to checkout $GITHUB_SHA"
exit 1
fi
cd "$docsdir"
if ! git checkout --force "origin/docs"; then
echo "::error::Failed to checkout origin/docs"
exit 1
fi
rm -rfv .git README
echo "::endgroup::"
echo ""
echo "::set-output name=gitdir::$gitdir"
echo "::set-output name=moddir::$moddir"
echo "::set-output name=docsdir::$docsdir"
- name: Generate
env:
DIRECTORY: "./docs"
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
cd "$gitdir"
echo "::group::Installing dependencies"
yarn
echo "::endgroup::"
echo "::group::Generating documentation"
yarn docs
echo "::endgroup::"
echo "::group::Copying documentation to temporary directory"
mv -vf "$gitdir/$DIRECTORY"/* $moddir
echo "::endgroup::"
- name: Publish
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
gitmessage="$GITHUB_SHA
This is an automated commit by a GitHub workflow.
It contains generated documentation from the main branch of this repository.
Action: https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
moddirhash=`find "$moddir" -type f | xargs sha512sum | cut -d ' ' -f 1`
docsdirhash=`find "$docsdir" -type f | xargs sha512sum | cut -d ' ' -f 1`
if [[ "$moddirhash" != "$docsdirhash" ]]; then
echo "Documentation changed, publishing..."
cd "$moddir"
echo "::group::Preparing commit"
git init
git remote add origin "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git"
echo "This is an automated branch. Please do not commit to or change any files in it." >> README
git add . -v
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git branch -m docs
echo "::endgroup::"
echo "::group::Committing changes"
git commit --verbose -m "$gitmessage"
echo "::endgroup::"
echo "::group::Pushing changes"
git push origin docs --force --verbose
echo "::endgroup::"
else
echo "Documentation hasn't changed, skipping publish."
fi
- name: Cleanup
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
cd ~
echo "::group::Removing $gitdir"
rm -rfv "$gitdir"
echo "::endgroup::"
echo "::group::Removing $moddir"
rm -rfv "$moddir"
echo "::endgroup::"
echo "::group::Removing $docsdir"
rm -rfv "$docsdir"
echo "::endgroup::"
deploy:
if: success() && github.event_name == 'push' && github.ref == 'refs/heads/stable'
needs: [build, format, lint]
uses: ./.github/workflows/deploy.yml
secrets: inherit