-
Notifications
You must be signed in to change notification settings - Fork 112
387 lines (323 loc) · 14.9 KB
/
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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: documentation
on:
workflow_dispatch:
pull_request:
push:
branches:
- staging
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
get-versions:
runs-on: ubuntu-24.04
name: Get versions
outputs:
build_environments: ${{ steps.filters.outputs.build_environments }}
build_versions: ${{ steps.filters.outputs.build_versions }}
build_next_version: ${{ steps.filters.outputs.build_next_version }}
build_pp: ${{ steps.filters.outputs.build_pp }}
build_cloud: ${{ steps.filters.outputs.build_cloud }}
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
token: ${{ github.token }}
list-files: 'json'
filters: |
global:
- babel.config.js
- docusaurus.config.js
- package.json
- versions.json
- nextVersion.json
- yarn.lock
- 'src/**'
- 'static/**'
- 'i18n/**/(code|footer|navbar).json'
- 'i18n/**/index.js'
cloud:
- 'cloud/**'
- 'i18n/**/docusaurus-plugin-content-docs-cloud/**'
pp:
- 'pp/**'
- 'i18n/**/docusaurus-plugin-content-docs-pp/**'
versions:
- 'i18n/**/docusaurus-plugin-content-docs/**'
- 'versioned_docs/**'
- 'versioned_sidebars/**'
- name: Manage versions to build
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ steps.changes.outputs.global == 'false' && steps.changes.outputs.versions_count < 100 }}
with:
script: |
const available_versions = require('./versions.json');
let build_next_version = require('./nextVersion.json').version;
let build_versions = [...available_versions];
if (build_versions.includes(build_next_version)) {
build_versions.splice(build_versions.indexOf(build_next_version), 1);
}
let build_pp = '1';
let build_cloud = '1';
if ('${{ github.event_name }}' === 'pull_request' && ${{ steps.changes.outputs.global }} === false) {
if (${{ steps.changes.outputs.versions }} === false && ${{ steps.changes.outputs.pp }} === false) {
build_pp = '0';
}
if (${{ steps.changes.outputs.versions }} === false && ${{ steps.changes.outputs.cloud }} === false) {
build_cloud = '0';
}
build_versions = [];
build_next_version = null;
if (${{ steps.changes.outputs.versions }} === true) {
const next_version = require('./nextVersion.json').version;
${{ steps.changes.outputs.versions_files }}.map((file) => {
[...file.matchAll(/(\d{2}\.(04|10))/g)].map((result) => {
console.log(`Version ${result[1]} updated : ${file}`);
if (next_version === result[1]) {
build_next_version = next_version;
} else if (available_versions.includes(result[1])) {
build_versions.push(result[1]);
}
});
});
build_versions = [...new Set(build_versions)].sort().reverse(); // remove duplicates and sort desc
}
if (build_versions.length === 0 && (build_pp === '1' || build_cloud === '1')) {
build_versions.push(available_versions[0]);
}
}
console.log(`Following versions will be built: ${build_versions.join(',')}`);
console.log(`next version will${build_next_version === null ? ' not' : ''} be built`);
console.log(`pp section will${build_pp === '0' ? ' not' : ''} be built`);
console.log(`cloud section will${build_cloud === '0' ? ' not' : ''} be built`);
const build_environments = [];
if (build_versions.length) {
build_environments.push('staging');
}
if (build_next_version !== null && available_versions.includes(build_next_version)) {
build_environments.push('next');
}
core.exportVariable('build_environments', JSON.stringify(build_environments));
core.exportVariable('build_versions', build_versions.join(','));
core.exportVariable('build_next_version', build_next_version);
core.exportVariable('build_pp', build_pp);
core.exportVariable('build_cloud', build_cloud);
- name: Manage versions to build
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ steps.changes.outputs.global == 'true' || steps.changes.outputs.versions_count >= 100 || (github.ref_name == 'staging' && github.event_name != 'pull_request') }}
with:
script: |
let build_versions = require('./versions.json');
let build_next_version = require('./nextVersion.json').version;
const build_environments = ['staging'];
if (build_versions.includes(build_next_version)) {
build_environments.push('next');
build_versions.splice(build_versions.indexOf(build_next_version), 1);
}
core.exportVariable('build_environments', JSON.stringify(build_environments));
core.exportVariable('build_versions', build_versions.join(','));
core.exportVariable('build_next_version', require('./nextVersion.json').version);
core.exportVariable('build_pp', '1');
core.exportVariable('build_cloud', '1');
- name: Manage versions to build
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: filters
with:
script: |
core.setOutput('build_environments', '${{ env.build_environments }}');
core.setOutput('build_versions', '${{ env.build_versions }}');
core.setOutput('build_next_version', '${{ env.build_next_version }}');
core.setOutput('build_pp', '${{ env.build_pp }}');
core.setOutput('build_cloud', '${{ env.build_cloud }}');
build:
if: ${{ needs.get-versions.outputs.build_environments != '[]' }}
runs-on: ubuntu-24.04
needs: [get-versions]
strategy:
fail-fast: false
matrix:
environment: ${{ fromJson(needs.get-versions.outputs.build_environments) }}
include:
- versions: ${{ needs.get-versions.outputs.build_versions }}
next_version: ${{ needs.get-versions.outputs.build_next_version }}
pp: ${{ needs.get-versions.outputs.build_pp }}
cloud: ${{ needs.get-versions.outputs.build_cloud }}
name: Build ${{ matrix.environment }}
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 9
run_install: false
- name: Set up Node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 22
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
- name: Restore docusaurus build from cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
.docusaurus
build
key: docusaurus-build-${{ matrix.environment }}-${{ github.head_ref || github.ref_name }}
restore-keys: |
docusaurus-build-${{ matrix.environment }}-staging
- name: Build documentation
run: pnpm build
env:
PP: ${{ matrix.pp }}
CLOUD: ${{ matrix.cloud }}
VERSIONS: ${{ matrix.environment == 'staging' && matrix.versions || matrix.next_version }}
BASE_URL: ${{ github.event_name == 'pull_request' && format('/previews/pr-{0}/{1}', github.event.pull_request.number, matrix.environment) || '' }}
- name: Clear previous docker image from cache
run: |
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/centreon/centreon-documentation/actions/caches?key=docusaurus-build-${{ matrix.environment }}-${{ github.head_ref || github.ref_name }}
shell: bash
- name: Store docusaurus build cache in cache
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
.docusaurus
build
key: docusaurus-build-${{ matrix.environment }}-${{ github.head_ref || github.ref_name }}
deploy-preview:
if: ${{ github.event_name == 'pull_request' }}
needs: [get-versions, build]
runs-on: [self-hosted, infra]
strategy:
fail-fast: false
matrix:
environment: ${{ fromJson(needs.get-versions.outputs.build_environments) }}
name: Deploy preview ${{ matrix.environment }}
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Restore build from cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
.docusaurus
build
key: docusaurus-build-${{ matrix.environment }}-${{ github.head_ref || github.ref_name }}
fail-on-cache-miss: true
- name: Setup awscli
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo unzip -q awscliv2.zip
sudo ./aws/install
shell: bash
- name: Deploy to https://docs-preview-int.centreon.com
run: |
echo "datetime=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
$(aws sts assume-role \
--role-arn ${{ secrets.CLOUDFRONT_ROLE_DOC_PRODUCTION }} \
--role-session-name InvalidDocCache \
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
--output text))
aws s3 sync --delete build s3://centreon-documentation-preview-pr/previews/pr-${{ github.event.pull_request.number }}/${{ matrix.environment }}/
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_ID_DOC_PREVIEW }} --paths "/previews/pr-${{ github.event.pull_request.number }}/${{ matrix.environment }}/*"
shell: bash
comment-preview:
needs: [get-versions, deploy-preview]
runs-on: ubuntu-24.04
name: Add comment for preview
steps:
- name: Prepare environment variables for comment
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const preview_urls = ${{ needs.get-versions.outputs.build_environments }}.map((environment) => {
return `:rocket: Deployed preview to https://docs-preview-int.centreon.com/previews/pr-${{ github.event.pull_request.number }}/${environment}/`;
})
core.exportVariable('datetime', new Date().toUTCString());
core.exportVariable('preview_urls',preview_urls.join('\n'));
- name: Leave a comment after deployment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: "\
**PR Previews**
:---:
${{ env.preview_urls }}
at ${{ env.datetime }}
> **_NOTE:_** Previews are deleted after 30 days of inactivity
"
deploy-staging:
if: ${{ github.ref_name == 'staging' && github.event_name != 'pull_request' && contains(fromJson(needs.get-versions.outputs.build_environments), 'staging') }}
needs: [get-versions, build]
runs-on: [self-hosted, infra]
name: Deploy to staging
environment:
name: staging
url: https://docs-staging.int.centreon.com
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Restore build from cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
.docusaurus
build
key: docusaurus-build-staging-${{ github.head_ref || github.ref_name }}
fail-on-cache-miss: true
- name: Deploy to https://docs-staging.int.centreon.com
run: |
# Prepare ssh-key
eval `ssh-agent`
ssh-add - <<< "${{ secrets.INT_SSH_KEY }}"
rsync -e "ssh -o StrictHostKeyChecking=no" -arzvh --delete build/* [email protected]:/var/www/html/ \
|| rsync -e "ssh -o StrictHostKeyChecking=no" -arzvh --delete build/* admin@${{ secrets.DOC_DEV_IP_ADDRESS }}:/var/www/html/
shell: bash
deploy-next:
if: ${{ github.ref_name == 'staging' && github.event_name != 'pull_request' && contains(fromJson(needs.get-versions.outputs.build_environments), 'next') }}
needs: [get-versions, build]
runs-on: [self-hosted, infra]
name: Deploy to next
environment:
name: next
url: https://docs-next-int.centreon.com
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Restore build from cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
.docusaurus
build
key: docusaurus-build-next-${{ github.head_ref || github.ref_name }}
fail-on-cache-miss: true
- name: Setup awscli
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo unzip -q awscliv2.zip
sudo ./aws/install
shell: bash
- name: Deploy to https://docs-next-int.centreon.com
run: |
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
$(aws sts assume-role \
--role-arn ${{ secrets.CLOUDFRONT_ROLE_DOC_PRODUCTION }} \
--role-session-name InvalidDocCache \
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
--output text))
aws s3 sync --delete build s3://centreon-documentation-next/
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_ID_DOC_NEXT }} --paths "/*"
shell: bash