-
Notifications
You must be signed in to change notification settings - Fork 188
192 lines (168 loc) · 7.01 KB
/
build-pr.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
name: Build Website
on:
pull_request:
concurrency:
group: build-docs-${{ github.ref }}
cancel-in-progress: true
jobs:
set_build_params:
runs-on: ubuntu-latest
steps:
- name: Check if all Demos Should be built
id: build_all_demos
env:
BUILD_ALL_DEMOS_LABEL_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'ci:build-all-qml-demos') }}
run: |
build_all_demos='false'
echo 'Checking if all demos need to be built'
if [ '${{ github.event_name }}' == 'push' ]; then
echo 'Job triggered by push event ... setting flag to build all demos ...'
build_all_demos='true'
elif [ '${{ github.event_name }}' == 'pull_request' ]; then
echo 'Job triggered by pull_request ... checking to see if "ci:build-all-qml-demos" label is present'
if [ "$BUILD_ALL_DEMOS_LABEL_PRESENT" == 'true' ]; then
echo 'Label "ci:build-all-qml-demos" is present on pull_request .. setting flag to build all demos ...'
build_all_demos='true'
else
echo 'Label "ci:build-all-qml-demos" was not detected for pull_request ...'
fi
fi
echo "build_all_demos=$build_all_demos" >> $GITHUB_OUTPUT
- name: Fail for Pull Request in Draft without ci:build-all-qml-demos label
if: steps.build_all_demos.outputs.build_all_demos == 'false' && github.event.pull_request.draft == true
run: |
message="By default, CI checks will not run on draft PRs.
If you need the CI checks to run, you can mark the PR ready for review, or add the label 'ci:build-all-qml-demos'
"
echo "::error title=Failing CI for Draft Pull Request::$message"
exit 1
- name: Checkout
if: steps.build_all_demos.outputs.build_all_demos == 'false'
uses: actions/checkout@v3
- name: Get Changed Demos
id: changed_demos
if: steps.build_all_demos.outputs.build_all_demos == 'false'
uses: tj-actions/changed-files@v35
with:
files: demonstrations/*.py
# Though steps.changed_demos has the output of the files we need, it has the full file path,
# And we need only the actual filename itself
- name: Format Changed Demos
id: formatted_changed_demos
env:
DEMOS_CHANGED: ${{ steps.changed_demos.outputs.all_changed_files }}
run: |
demo_filenames=()
for demo_path in $DEMOS_CHANGED; do
demo_filenames+=($(basename $demo_path))
done
echo "files=${demo_filenames[@]}" >> $GITHUB_OUTPUT
- name: Detect Metadata Files that need to be changed
id: metadata_files_to_check
env:
DEMOS_TO_BUILD: ${{ steps.formatted_changed_demos.outputs.files }}
run: |
metadata_files=()
input_demos_to_build="$DEMOS_TO_BUILD"
if [ -z "$input_demos_to_build" ]; then
readarray -d '' metadata_files < <(find demonstrations -name "*.metadata.json" -not -path "demonstrations/demonstrations_categories.metadata.json" -print0)
else
for metadata_file in $input_demos_to_build
do
metadata_files+=("demonstrations/${metadata_file%.py}.metadata.json")
done
fi
metadata_files_str="${metadata_files[@]}"
echo "file_names=$metadata_files_str" >> $GITHUB_OUTPUT
- name: Set number of workers needed
id: num_workers
env:
BUILD_ALL_DEMOS: ${{ steps.build_all_demos.outputs.build_all_demos }}
run: |
if [[ "$BUILD_ALL_DEMOS" == 'true' ]]; then
echo "num_workers=10" >> $GITHUB_OUTPUT
else
echo "num_workers=1" >> $GITHUB_OUTPUT
fi
# These outputs are used by dependent build job parameters
outputs:
num_workers: ${{ steps.num_workers.outputs.num_workers }}
build_all_demos: ${{ steps.build_all_demos.outputs.build_all_demos }}
demos_to_build: ${{ steps.formatted_changed_demos.outputs.files }}
metadata_file_names: ${{ steps.metadata_files_to_check.outputs.file_names }}
validate_metadata:
uses: ./.github/workflows/validate-demo-metadata.yml
needs:
- set_build_params
with:
branch: ${{ github.ref }}
metadata_files: ${{ needs.set_build_params.outputs.metadata_file_names }}
skip_metadata_preview_image_value_validation: true # TODO: This can be reverted once the static assets are centralized
build:
uses: ./.github/workflows/build-branch.yml
needs:
- set_build_params
- validate_metadata
# Only run if we need to build all the demos or a subset of demos.
# If build_all_demos is false AND demos_to_build_is blank, this means
# that the pull_request that triggered the build did not update any demo files
# and does not have the `ci:build-all-qml-demos` label attached.
# Therefore, the build can be skipped entirely
if: >-
${{
needs.set_build_params.outputs.build_all_demos == 'true' ||
needs.set_build_params.outputs.demos_to_build != ''
}}
with:
branch: ${{ github.ref }}
num_workers: ${{ needs.set_build_params.outputs.num_workers }}
enable_python_cache: false
enable_sphinx_cache: true
refresh_sphinx_cache: ${{ contains(github.event.pull_request.labels.*.name, 'ci:build-all-qml-demos') }}
enable_qml_execution_times_cache: true
skip_execution_times_aggregation: true
skip_sphinx_build_file_aggregation: true
sphinx_build_output_format: html
sphinx_examples_to_build: ${{ needs.set_build_params.outputs.demos_to_build }}
save-build-context:
runs-on: ubuntu-22.04
needs:
- build
- validate_metadata
steps:
- name: Save Pull Request Event Context
if: github.event_name == 'pull_request'
run: |
mkdir -p /tmp/pr
cat >/tmp/pr/pr_info.json <<EOL
{
"id": "${{ github.event.pull_request.number }}",
"ref": "${{ github.event.pull_request.head.sha }}",
"ref_name": "${{ github.event.pull_request.head.ref }}"
}
EOL
- name: Upload Pull Request Event Context as Artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
with:
name: pr_info.zip
path: /tmp/pr
retention-days: 30
# Will run to create an artifact containing key push event information
- name: Save Push Event Context
if: github.event_name == 'push'
run: |
mkdir -p /tmp/push
cat >/tmp/push/push_info.json <<EOL
{
"ref": "${{ github.sha }}",
"ref_name": "${{ github.ref_name }}"
}
EOL
- name: Upload Push Event Context as Artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v3
with:
name: push_info.zip
path: /tmp/push
retention-days: 30