mirror of
https://github.com/khuedoan/homelab.git
synced 2025-03-09 20:30:04 +07:00
ci: add task to check changed files
This commit is contained in:
parent
c9e4278114
commit
fc23a700e3
46
.tekton/tasks/check-git-files-changed.yaml
Normal file
46
.tekton/tasks/check-git-files-changed.yaml
Normal file
@ -0,0 +1,46 @@
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: check-git-files-changed
|
||||
annotations:
|
||||
description: |
|
||||
Returns "passed" in the "check" result if any of the files changed
|
||||
in the source on the workspace matches the regular expression.
|
||||
Returns a "files" result as a list of files modified by the PR that
|
||||
match the regex in the parameters.
|
||||
ci.tekton.dev/condition: |
|
||||
The result of this task is used to evaluate a condition.
|
||||
Events from this task are ignored downstream, when it comes to update the CI job status.
|
||||
spec:
|
||||
params:
|
||||
- name: gitCloneDepth
|
||||
description: Number of commits + 1
|
||||
- name: regex
|
||||
description: Regular expression to match files changed
|
||||
workspaces:
|
||||
- name: input
|
||||
results:
|
||||
- name: check
|
||||
description: passed or failed
|
||||
- name: files
|
||||
description: list of files modified that match
|
||||
steps:
|
||||
- name: check-files-changed
|
||||
image: alpine/git
|
||||
env:
|
||||
- name: GIT_CLONE_DEPTH
|
||||
value: $(params.gitCloneDepth)
|
||||
- name: REGEX
|
||||
value: $(params.regex)
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -ex
|
||||
set -o pipefail
|
||||
BACK="HEAD~$(( ${GIT_CLONE_DEPTH} - 1 ))"
|
||||
CHECK="failed"
|
||||
cd $(workspaces.input.path)
|
||||
git diff-tree --no-commit-id --name-only -r HEAD $BACK | \
|
||||
grep -E "${REGEX}" > $(results.files.path) || true
|
||||
git diff-tree --no-commit-id --name-only -r HEAD $BACK | \
|
||||
grep -E "${REGEX}" && CHECK="passed"
|
||||
printf $CHECK > $(results.check.path)
|
@ -4,3 +4,4 @@ kind: Kustomization
|
||||
resources:
|
||||
- external.yaml
|
||||
- lint.yaml
|
||||
- check-git-files-changed.yaml
|
||||
|
Loading…
Reference in New Issue
Block a user