-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (106 loc) · 5.06 KB
/
test_impacted_targets.yaml
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
name: Pull Request
on: pull_request
permissions: read-all
jobs:
tests_impacted_targets:
runs-on: ubuntu-latest
name: ${{ matrix.test-name }}
strategy:
fail-fast: false
matrix:
include:
# 1. Test when some targets are modified
- test-name: basic-modified
target-branch: do_not_delete/basic-target
setup-branch: do_not_delete/basic-setup-modified
expected-targets-file: basic_modified.txt
# 2. Test when some targets are modified and startup options are specified
- test-name: basic-upload-startup
target-branch: do_not_delete/basic-target
setup-branch: do_not_delete/basic-setup-upload
bazel-startup-options: --host_jvm_args=-Xmx12G,--block_for_lock,--client_debug
expected-targets-file: basic_upload_startup.txt
# The upload is expected to fail with exit code 7
upload-targets: "true"
# 3. Test when some targets are modified and impact-all-filters-path is specified
- test-name: basic-upload-impacts-all
target-branch: do_not_delete/basic-target
setup-branch: do_not_delete/basic-setup-upload
impact-all-filters-path: local-action/tests/impact_all_filters.yaml
expected-targets-file: basic_upload_impacts_all.txt
# The upload is expected to fail with exit code 7
upload-targets: "true"
# 4. Test when some targets are added
- test-name: basic-added
target-branch: do_not_delete/basic-target
setup-branch: do_not_delete/basic-setup-added
expected-targets-file: basic_added.txt
# 5. Test when some targets are removed
- test-name: basic-removed
target-branch: do_not_delete/basic-target
setup-branch: do_not_delete/basic-setup-removed
expected-targets-file: basic_removed.txt
# 6. Test when some targets are added but the target branch is out of date (this is where upload and test diffs vary)
- test-name: outdated-added
target-branch: do_not_delete/outdated-target
setup-branch: do_not_delete/outdated-setup-add
expected-targets-file: outdated_added.txt
# 7. Test a stress test of targets
- test-name: many-mixed
target-branch: do_not_delete/outdated-target
setup-branch: do_not_delete/mixed-setup-add
expected-targets-file: many_mixed.txt
# 8. Test a stress test of targets
- test-name: many-filtered
target-branch: do_not_delete/outdated-target
setup-branch: do_not_delete/mixed-setup-add
kind-filter: source file
negative-scope-filter: .txt$
expected-targets-file: many_filtered.txt
steps:
- name: Checkout ${{ matrix.setup-branch }}
uses: actions/checkout@v3
with:
ref: ${{ matrix.setup-branch }}
fetch-depth: 0
# Check out this repo separately in order to use its action independent of the state of the test inputs
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
path: local-action
# We will override bazel for purposes of asserting that tests are run, but we still need to invoke it and have it in the PATH for computing targets
- name: Setup Bazel
# trunk-ignore(semgrep): Trust third-party `bazelbuild` GH Action
uses: bazelbuild/setup-bazelisk@v2
- name: Test impacted targets
id: test
uses: ./local-action/
with:
trunk-token: test-token
target-branch: ${{ matrix.target-branch }}
bazel-workspace-path: ${{ github.workspace }}/tests/simple_bazel_workspace
verbose: "true"
bazel-startup-options: ${{ matrix.bazel-startup-options }}
bazel-path: ${{ github.workspace }}/local-action/tests/bazel_stub.sh
impact-all-filters-path: ${{ matrix.impact-all-filters-path }}
upload-targets: ${{ matrix.upload-targets }}
test-targets: "true"
test-kind-filter: ${{ matrix.kind-filter }}
test-negative-kind-filter: ""
test-negative-scope-filter: ${{ matrix.negative-scope-filter }}
env:
TEST_TARGETS_EXPECTED_FILE:
${{ github.workspace }}/local-action/tests/expected/${{ matrix.expected-targets-file }}
API_URL: localhost
PR_SETUP_BRANCH: ${{ matrix.setup-branch }}
- name: Assert number targets
shell: bash
run: |
expected_file="${{ github.workspace }}/local-action/tests/expected/${{ matrix.expected-targets-file }}"
expected_targets=$(wc -l "${expected_file}")
if [[ "${{ steps.test.outputs.detected_test_targets }}" -ne "${expected_targets}" ]]; then
echo "Incorrect number of tests run, expected ${expected_targets}, got ${{ steps.test.outputs.detected_test_targets }}"
exit 1
fi
echo "Tests identified successfully"