-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
190 lines (179 loc) · 7.89 KB
/
action.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
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
name: Trunk Upload and Test Impacted Targets
author: trunk.io
description: Trunk.io Github Action to Compute, Upload, and Test Impacted Targets
inputs:
trunk-token:
description:
Repo API token used for authentication. Can be found at app.trunk.io. Required if
upload-targets
required: false
target-branch:
description:
The Merge Instance's target branch. If unspecified, defaults to the repository's default
branch.
required: false
bazel-workspace-path:
description:
The path to the bazel WORKSPACE, relative to the root of the git repository. If unspecified,
defaults to the root of the repository.
required: false
verbose:
description: Whether to enable verbose logging. Defaults to false.
required: false
bazel-startup-options:
description:
A comma separated list of startup options to pass to Bazel. See
https://bazel.build/reference/command-line-reference#startup-options for a complete list. If
unspecified, no startup options are specified.
required: false
bazel-path:
description: A path to the Bazel executable. Defaults to PATH.
required: false
default: bazel
impact-all-filters-path:
description:
A path to a list of filters to identify whether `ALL` impacted targets should be considered.
See https://github.com/dorny/paths-filter/blob/master/.github/filters.yml for an example.
required: false
default: ""
upload-targets:
description:
Upload targets to the Trunk MergeGraph. Required for each PR if using the MergeGraph.
required: false
default: "false"
test-targets:
description: Run bazel test on the computed targets. Recommended if running on PRs.
required: false
default: "true"
bazel-test-command:
description: The command to run against bazel when running tests.
required: false
default: test
bazel-diff-command-options:
description: Additional args to append to the bazel diff bazelCommandOptions flag.
required: false
default: ""
test-kind-filter:
description: Kind filter to apply to impacted targets
required: false
default: .+_library|.+_binary|.+_test
test-scope-filter:
description: Scope filter to apply to impacted targets
required: false
test-negative-kind-filter:
description: Negative kind filter to apply to impacted targets
required: false
default: generated file
test-negative-scope-filter:
description: Negative scope filter to apply to impacted targets
required: false
default: //external
test-negative-tag-filter:
description: Negative tag filter to apply to impacted targets
required: false
runs:
using: composite
steps:
- name: Validate inputs
id: validate-inputs
if: inputs.upload-targets != 'true' && inputs.test-targets != 'true'
run: echo "Must upload or test impacted targets" && exit 1
shell: bash
- name: Detect changed paths
id: detect-changed-paths
if: ${{ inputs.impact-all-filters-path != '' }}
# trunk-ignore(semgrep/yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha.third-party-action-not-pinned-to-commit-sha)
uses: dorny/paths-filter@v2
with:
filters: ${{ inputs.impact-all-filters-path }}
- name: Setup jq
# trunk-ignore(semgrep): Trust third-party action to install JQ. Source code: https://github.com/dcarbone/install-jq-action/
uses: dcarbone/[email protected]
- name: Prerequisites
id: prerequisites
run: ${GITHUB_ACTION_PATH}/src/scripts/prerequisites.sh
shell: bash
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
TARGET_BRANCH: ${{ inputs.target-branch }}
PR_BRANCH: ${{ github.head_ref }}
WORKSPACE_PATH: ${{ inputs.bazel-workspace-path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
IMPACTS_FILTERS_CHANGES: ${{ steps.detect-changed-paths.outputs.changes }}
- name: Install Bazel in PATH
if: ${{ steps.prerequisites.outputs.requires_default_bazel_installation == 'true' }}
uses: bazelbuild/setup-bazelisk@v2
- name: Setup bazel-diff
id: bazel-diff
run: ${GITHUB_ACTION_PATH}/src/scripts/setup_bazel_diff.sh
shell: bash
env:
WORKSPACE_PATH: ${{ inputs.bazel-workspace-path }}
- name: Compute Impacted Targets for Uploading
id: compute-impacted-targets-upload
run: ${GITHUB_ACTION_PATH}/src/scripts/compute_impacted_targets.sh
if:
steps.prerequisites.outputs.impacts_all_detected == 'false' && inputs.upload-targets ==
'true'
shell: bash
env:
MERGE_INSTANCE_BRANCH_HEAD_SHA:
${{ steps.prerequisites.outputs.merge_instance_branch_head_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_upload_head_sha }}
VERBOSE: ${{ inputs.verbose }}
WORKSPACE_PATH: ${{ steps.prerequisites.outputs.workspace_path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
BAZEL_DIFF_CMD: ${{ steps.bazel-diff.outputs.bazel_diff_cmd }}
BAZEL_DIFF_COMMAND_OPTIONS: ${{ inputs.bazel-diff-command-options }}
BAZEL_STARTUP_OPTIONS: ${{ inputs.bazel-startup-options }}
- name: Upload Impacted Targets
if: inputs.upload-targets == 'true'
run: ${GITHUB_ACTION_PATH}/src/scripts/upload_impacted_targets.sh
shell: bash
continue-on-error: true
env:
ACTOR: ${{ github.actor }}
API_TOKEN: ${{ inputs.trunk-token }}
REPOSITORY: ${{ github.repository }}
TARGET_BRANCH: ${{ steps.prerequisites.outputs.merge_instance_branch }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_SHA: ${{ steps.prerequisites.outputs.pr_branch_upload_head_sha }}
IMPACTED_TARGETS_FILE:
${{ steps.compute-impacted-targets-upload.outputs.impacted_targets_out }}
IMPACTS_ALL_DETECTED: ${{ steps.prerequisites.outputs.impacts_all_detected }}
# Although they share the same core logic, the computation of the testable targets is dependent on the
# merge-base of the target branch, not on the HEAD of the target branch, so it has the potential to be
# a distinct diff and must be recomputed.
- name: Compute Impacted Targets for Testing
id: compute-impacted-targets-test
run: ${GITHUB_ACTION_PATH}/src/scripts/compute_impacted_targets.sh
if: inputs.test-targets == 'true'
shell: bash
env:
# Use base sha instead of merge instance branch head sha for testing
MERGE_INSTANCE_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.merge_base_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_testing_head_sha }}
VERBOSE: ${{ inputs.verbose }}
WORKSPACE_PATH: ${{ steps.prerequisites.outputs.workspace_path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
BAZEL_DIFF_CMD: ${{ steps.bazel-diff.outputs.bazel_diff_cmd }}
BAZEL_DIFF_COMMAND_OPTIONS: ${{ inputs.bazel-diff-command-options }}
BAZEL_STARTUP_OPTIONS: ${{ inputs.bazel-startup-options }}
- name: Test Impacted Targets
if: inputs.test-targets == 'true'
id: test-impacted-targets
run: ${GITHUB_ACTION_PATH}/src/scripts/test_impacted_targets.sh
working-directory: ${{ steps.prerequisites.outputs.workspace_path }}
shell: bash
env:
IMPACTED_TARGETS_FILE:
${{ steps.compute-impacted-targets-test.outputs.impacted_targets_out }}
BAZEL_PATH: ${{ inputs.bazel-path }}
BAZEL_TEST_COMMAND: ${{ inputs.bazel-test-command }}
BAZEL_STARTUP_OPTIONS: ${{ inputs.bazel-startup-options }}
BAZEL_KIND_FILTER: ${{ inputs.test-kind-filter }}
BAZEL_SCOPE_FILTER: ${{ inputs.test-scope-filter }}
BAZEL_NEGATIVE_KIND_FILTER: ${{ inputs.test-negative-kind-filter }}
BAZEL_NEGATIVE_SCOPE_FILTER: ${{ inputs.test-negative-scope-filter }}
BAZEL_NEGATIVE_TAG_FILTER: ${{ inputs.test-negative-tag-filter }}
CI: "true"