-
Notifications
You must be signed in to change notification settings - Fork 4
96 lines (85 loc) · 3.27 KB
/
preview-build.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
name: preview-build
on:
pull_request: ~
workflow_call:
inputs:
strict:
description: 'Treat warnings as errors'
type: string
default: 'true'
continue-on-error:
description: 'Do not fail to publish if build fails'
type: string
required: false
default: 'true'
path-pattern:
description: 'Path pattern to filter files. Only if changed files match the pattern, the workflow will continue.'
type: string
default: '**'
required: false
permissions:
contents: read
pull-requests: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get changed files
id: check-files
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6
with:
files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}
- name: Checkout
if: steps.check-files.outputs.any_changed == 'true'
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Store PR data
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_REF: ${{ github.event.pull_request.head.sha }}
ANY_CHANGED: ${{ steps.check-files.outputs.any_changed }}
run: |
cat << EOF > pull_request.json
{
"number": ${PR_NUMBER},
"ref": "${PR_REF}",
"any_changed": ${ANY_CHANGED}
}
EOF
- name: Upload PR data
uses: actions/upload-artifact@v4
with:
name: pull-request-data
path: pull_request.json
if-no-files-found: error
retention-days: 1
compression-level: 1
- name: Bootstrap Action Workspace
if: github.repository == 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
uses: ./.github/actions/bootstrap
# we run our artifact directly please use the prebuild
# elastic/docs-builder@main GitHub Action for all other repositories!
- name: Build documentation
if: github.repository == 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
dotnet run --project src/docs-builder -- --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"
- name: Build documentation
if: github.repository != 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
uses: elastic/docs-builder@main
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
with:
prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
- uses: actions/upload-artifact@v4
if: steps.check-files.outputs.any_changed == 'true'
with:
name: docs
path: .artifacts/docs/html/
if-no-files-found: error
retention-days: 1
# The lower the compression-level, the faster the artifact will be uploaded.
# But the size of the artifact will be larger.
compression-level: 1