44 targets :
55 description : " List of ninja targets for Cobalt build."
66 required : true
7+ test_root_target :
8+ description : " The root target from which to deduce what tests to run."
9+ required : true
710 upload_on_host_test_artifacts :
811 description : " Indicates if on-host test artifacts should be uploaded."
912 required : true
@@ -16,27 +19,6 @@ inputs:
1619runs :
1720 using : " composite"
1821 steps :
19- - name : Get depot tools
20- run : git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
21- shell : bash
22- - name : Add depot tools to PATH
23- run : echo "$GITHUB_WORKSPACE/depot_tools" >> $GITHUB_PATH
24- shell : bash
25- - name : Generate gclient file
26- run : gclient config --name=src --custom-var=download_remoteexec_cfg=True --custom-var='rbe_instance="projects/cobalt-actions-prod/instances/default_instance"' https://github.com/${{ github.repository }}
27- shell : bash
28- - name : Set target OS for Android
29- if : ${{ contains(matrix.platform, 'android') }}
30- run : |
31- echo "target_os=['android']" >> .gclient
32- gclient validate
33- shell : bash
34- - name : gclient sync
35- run : gclient sync -v --shallow --no-history -r ${{ github.sha }}
36- shell : bash
37- - name : Disable Chromium client side build telemetry
38- run : build_telemetry opt-out
39- shell : bash
4022 - name : GN gen
4123 run : |
4224 cd src
@@ -47,23 +29,57 @@ runs:
4729 cd src
4830 gn args --list --short --overrides-only out/${{ matrix.platform }}_${{ matrix.config }}
4931 shell : bash
50- - name : Calculate Test Targets
51- # TODO(b/382508397): Replace hardcoded list with dynamically generated one.
52- id : test-targets
53- if : inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true'
32+ - name : Get list of changed files
33+ if : github.event_name == 'pull_request'
34+ id : changed-files
35+ run : |
36+ set -x
37+ cd src
38+ changed_files=($(git diff --name-only -r ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}))
39+ # Convert the bash array to a JSON array.
40+ changed_files_json=$(jq -nc '$ARGS.positional' --args ${changed_files[@]})
41+ echo "changed_files_json=${changed_files_json}" >> $GITHUB_OUTPUT
42+ shell : bash
43+ - name : Calculate test targets
44+ if : matrix.config == 'devel' && inputs.test_root_target != 'null'
45+ id : calculate-test-targets
5446 env :
55- TEST_TARGETS_JSON_FILE : cobalt/build/testing/targets/${{ matrix.platform }}/test_targets.json
47+ CHANGED_FILES_JSON : ${{ steps.changed-files.outputs.changed_files_json }}
48+ ROOT_TARGET : ${{ inputs.test_root_target }}
49+ TEST_TARGETS_JSON_FILE : out/${{ matrix.platform }}_${{ matrix.config }}/test_targets.json
5650 run : |
57- set -ex
51+ set -x
5852 cd src
59- echo "test_targets=$(cat ${TEST_TARGETS_JSON_FILE} | jq -c '.test_targets')" >> $GITHUB_OUTPUT
53+ gn desc out/${{ matrix.platform }}_${{ matrix.config }}/ "*" --format=json > gn_desc.json
54+ # Trim any warning gn printed before the json (all lines above the first curly brace).
55+ sed -n '/^{/,$p' -i gn_desc.json
56+
57+ changed_files_arg=""
58+ if [[ -n "${CHANGED_FILES_JSON}" ]]; then
59+ changed_files_arg="--sources $(echo ${CHANGED_FILES_JSON} | jq -cr '. | join(",")')"
60+ fi
61+
62+ vpython3 cobalt/build/test_targets.py \
63+ --root-target "${ROOT_TARGET}" \
64+ ${changed_files_arg} \
65+ --gn-json gn_desc.json \
66+ --json-output > "${TEST_TARGETS_JSON_FILE}"
67+
68+ echo "test_targets_json_file=${TEST_TARGETS_JSON_FILE}" >> $GITHUB_OUTPUT
69+
70+ test_targets_json=$(cat ${TEST_TARGETS_JSON_FILE} | jq -cr '.test_targets')
71+ echo "test_targets_json=${test_targets_json}" >> $GITHUB_OUTPUT
72+
73+ test_targets_count=$(echo ${test_targets_json} | jq -cr 'length')
74+ echo "test_targets_count=${test_targets_count}" >> $GITHUB_OUTPUT
6075 shell : bash
6176 - name : Ninja build test targets
62- if : inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true'
77+ if : ${{ matrix.config == 'devel' && fromJSON(steps.calculate-test-targets.outputs.test_targets_count || 0) > 0 }}
78+ id : build-test-targets
6379 run : |
6480 set -ex
6581 cd src
66- TEST_TARGETS=$(jq -cr '. | join(" ")' <<< ' ${{ steps.test-targets.outputs.test_targets }}')
82+ TEST_TARGETS=$(cat ${{ steps.calculate- test-targets.outputs.test_targets_json_file }} | jq -cr '.test_targets | join(" ") ')
6783 time autoninja -C out/${{ matrix.platform }}_${{ matrix.config }} ${TEST_TARGETS}
6884 shell : bash
6985 - name : Ninja build
@@ -84,15 +100,20 @@ runs:
84100 src/out/${{ matrix.platform }}_qa/*_apk/*.apk
85101 src/out/${{ matrix.platform }}_qa/gen/build_info.json
86102 - name : Upload Test Artifacts
87- if : inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true '
103+ if : steps.build-test-targets.outcome == 'success '
88104 uses : ./src/.github/actions/upload_test_artifacts
89105 with :
90106 test_artifacts_key : ${{ inputs.test_artifacts_key }}
91107 upload_on_host_test_artifacts : ${{ inputs.upload_on_host_test_artifacts }}
92108 upload_on_device_test_artifacts : ${{ inputs.upload_on_device_test_artifacts }}
93- # TODO(b/382508397): Replace hardcoded list with dynamically generated one.
94- test_targets_json_file : cobalt/build/testing/targets/${{ matrix.platform }}/test_targets.json
109+ test_targets_json_file : ' ${{ steps.calculate-test-targets.outputs.test_targets_json_file }}'
95110outputs :
96- test_targets :
97- description : The test targets that were built
98- value : ${{ steps.test-targets.outputs.test_targets }}
111+ test_targets_count :
112+ description : The number of test targets build.
113+ value : ${{ steps.calculate-test-targets.outputs.test_targets_count || 0 }}
114+ test_targets_json :
115+ description : The test targets in a JSON array.
116+ value : ${{ steps.calculate-test-targets.outputs.test_targets_json }}
117+ test_targets_json_file :
118+ description : The generated test targets json file path.
119+ value : ${{ steps.calculate-test-targets.outputs.test_targets_json_file }}
0 commit comments