Skip to content

Commit

Permalink
Improve listing changed files in a commit
Browse files Browse the repository at this point in the history
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 version uses the GitHub Token from the `{{git_auth_secret}}` secret
created by Pipelines as code.

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
  • Loading branch information
zregvart committed Dec 20, 2024
1 parent 734d196 commit 887ad1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .tekton/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ spec:
value: "$(params.revision)"
- name: GIT_URL
value: "$(params.git-url)"
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: "{{ git_auth_secret }}"
key: "git-provider-token"
script: |
#!/bin/bash
set -euo pipefail
Expand Down
11 changes: 10 additions & 1 deletion .tekton/scripts/build-acceptable-bundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ set -o pipefail
DATA_BUNDLE_REPO="${DATA_BUNDLE_REPO:-quay.io/konflux-ci/tekton-catalog/data-acceptable-bundles}"
mapfile -t BUNDLES < <(cat "$@")

pr_number=$(gh search prs --repo konflux-ci/build-definitions --merged "${REVISION}" --json number --jq '.[].number')

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

if [[ -z ${task_records[*]} && -z ${BUNDLES[*]} ]]; then
echo Nothing to do...
exit 0
fi

# The OPA data bundle is tagged with the current timestamp. This has two main
# advantages. First, it prevents the image from accidentally not having any tags,
# and getting garbage collected. Second, it helps us create a timeline of the
Expand Down

0 comments on commit 887ad1c

Please sign in to comment.