Skip to content

Commit 08fd75f

Browse files
committed
Improve listing changed files in a commit
We ended up with revision 3b21550 for several Tasks in the acceptable bundles, seems that the `git log` method was also listing the files that were brought in by merging the main branch onto the pull request branch. This switches to using GitHub CLI to search for a merged pull request that contains the top commit (`$REVISION`), and then lists the changed files in that pull request. This should contain only the list of files that were changed in the pull request and not any changed files in a merge commit. Reference: https://issues.redhat.com/browse/EC-1015
1 parent fd3d434 commit 08fd75f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

.tekton/scripts/build-acceptable-bundles.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ set -o pipefail
77
DATA_BUNDLE_REPO="${DATA_BUNDLE_REPO:-quay.io/konflux-ci/tekton-catalog/data-acceptable-bundles}"
88
mapfile -t BUNDLES < <(cat "$@")
99

10+
pr_number=$(gh search prs --repo konflux-ci/build-definitions --merged "${REVISION}" --json number --jq '.[].number')
11+
12+
# changed files in a PR
13+
mapfile -t changed_files < <(gh pr view "https://github.com/konflux-ci/build-definitions/pull/${pr_number}" --json files --jq '.files.[].path')
1014
# store a list of changed task files
1115
task_records=()
1216
# loop over all changed files
13-
for path in $(git log -m -1 --name-only --pretty="format:" "${REVISION}"); do
17+
for path in "${changed_files[@]}"; do
1418
# check that the file modified is the task file
1519
if [[ "${path}" == task/*/*/*.yaml ]]; then
1620
IFS='/' read -r -a path_array <<< "${path}"
@@ -30,6 +34,11 @@ printf '%s\n' "${task_records[@]}"
3034
echo "Bundles to be added:"
3135
printf '%s\n' "${BUNDLES[@]}"
3236

37+
if [[ -z ${task_records[*]} && -z ${BUNDLES[*]} ]]; then
38+
echo Nothing to do...
39+
exit 0
40+
fi
41+
3342
# The OPA data bundle is tagged with the current timestamp. This has two main
3443
# advantages. First, it prevents the image from accidentally not having any tags,
3544
# and getting garbage collected. Second, it helps us create a timeline of the

0 commit comments

Comments
 (0)