-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard Task execution via changed files
The new Task in `.tekton/tasks/task-switchboard.yaml` produces a list of bindings that evaluate to true for a particular pull request as an array result. Given this result guards can be done, e.g. using when expressions to limit when a Task on the Pipeline needs to run. This way we can skip expensive Tasks that are unrelated to the change done in the pull request. Similar to work in #1188 and #524, with the distinction that the PipelineRun is executed, only potentially not in full.
- Loading branch information
Showing
3 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: task-switchboard | ||
labels: | ||
app.kubernetes.io/version: "0.1" | ||
annotations: | ||
tekton.dev/pipelines.minVersion: "0.12.1" | ||
tekton.dev/displayName: Task Switchboard | ||
tekton.dev/platforms: "linux/amd64" | ||
spec: | ||
description: "Computes a set of expressions based on the changed files in the | ||
pipeline, used to determine which tasks to run" | ||
params: | ||
- name: pr_number | ||
type: string | ||
- name: utils_image | ||
type: string | ||
- name: expressions | ||
type: array | ||
results: | ||
- name: bindings | ||
type: array | ||
steps: | ||
- name: list-changed-files | ||
image: $(params.utils_image) | ||
env: | ||
- name: GITHUB_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ git_auth_secret }}" | ||
key: "git-provider-token" | ||
args: | ||
- "$(params.expressions[*])" | ||
script: | | ||
#!/bin/bash | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
rules="$(mktemp -d)" | ||
trap 'rm -rf "${rules}"' EXIT | ||
for ((i=1; i<=$#; ++i)); do | ||
printf "package rule\n%s" "${!i}" > "${rules}/$i.rego" | ||
done | ||
ec opa check --v1-compatible "${rules}" | ||
printf '%s\n' "$@" \ | ||
| ec opa eval --v1-compatible --stdin --format bindings --input \ | ||
<(gh pr view "https://github.com/konflux-ci/build-definitions/pull/$(params.pr_number)" --json files --jq '.files.[].path') \ | ||
| jq '[to_entries | .[] | select(.value == true) | .key]' \ | ||
| tee "$(results.bindings.path)" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters