-
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 directories
The new Task in `.tekton/tasks/changed-dirs.yaml` produces a list of changed directories for a particular pull request as an array result. Given this result guards can be done, e.g. using CEL 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
84 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,47 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: changed-dirs | ||
labels: | ||
app.kubernetes.io/version: "0.1" | ||
annotations: | ||
tekton.dev/pipelines.minVersion: "0.12.1" | ||
tekton.dev/displayName: "Lists changed files" | ||
tekton.dev/platforms: "linux/amd64" | ||
spec: | ||
description: Produces a list of changed top-level directories | ||
params: | ||
- name: pr_number | ||
type: string | ||
- name: utils_image | ||
type: string | ||
results: | ||
- name: changed_directories | ||
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" | ||
script: | | ||
#!/bin/bash | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
dirs=() | ||
# collect all directories changed in a PR | ||
for path in $(gh pr view "https://github.com/konflux-ci/build-definitions/pull/$(params.pr_number)" --json files --jq '.files.[].path'); do | ||
dirs+=("${path%%/*}") | ||
done | ||
# deduplicate dirs | ||
readarray -t dirs < <(printf '%s\n' "${dirs[@]}" | sort -u) | ||
# join $dirs with '","', e.g. (a b c) -> 'a","b","c","' | ||
escaped_json="$(printf '%s\",\"' "${dirs[@]}")" | ||
# add the square brackets and remove the trailing ',"' | ||
escaped_json="[\"${escaped_json::-2}]" | ||
echo -n "${escaped_json}" > "$(results.changed_directories.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