Skip to content

Commit

Permalink
ci: update files diff method in pipeline (solana-labs#2075)
Browse files Browse the repository at this point in the history
* ci: update files diff method in pipeline

* feedback

* parse owner and repo from url
  • Loading branch information
yihau authored Jul 12, 2024
1 parent 8db4f56 commit 2961b9b
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions ci/buildkite-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,48 @@ if [[ -n $CI_PULL_REQUEST ]]; then
pr_number=${BASH_REMATCH[1]}
echo "get affected files from PR: $pr_number"

# Fetch the number of commits in the PR
commits_no=$(gh pr view "$pr_number" --json commits --jq '.commits | length')
echo "number of commits in this PR: $commits_no"
if [[ $BUILDKITE_REPO =~ ^https:\/\/github\.com\/([^\/]+)\/([^\/\.]+) ]]; then
owner="${BASH_REMATCH[1]}"
repo="${BASH_REMATCH[2]}"
elif [[ $BUILDKITE_REPO =~ ^git@github\.com:([^\/]+)\/([^\/\.]+) ]]; then
owner="${BASH_REMATCH[1]}"
repo="${BASH_REMATCH[2]}"
else
echo "couldn't parse owner and repo. use defaults"
owner="anza-xyz"
repo="agave"
fi

# ref: https://github.com/cli/cli/issues/5368#issuecomment-1087515074
#
# Variable value contains dollar prefixed words that look like bash variable
# references. This is intentional.
# shellcheck disable=SC2016
query='
query($owner: String!, $repo: String!, $pr: Int!, $endCursor: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
files(first: 100, after: $endCursor) {
pageInfo{ hasNextPage, endCursor }
nodes {
path
}
}
}
}
}'

# get affected files
readarray -t affected_files < <(git diff HEAD~"$commits_no"..HEAD --name-status | cut -f2)
readarray -t affected_files < <(
gh api graphql \
-f query="$query" \
-F pr="$pr_number" \
-F owner="$owner" \
-F repo="$repo" \
--paginate \
--jq '.data.repository.pullRequest.files.nodes.[].path'
)

if [[ ${#affected_files[*]} -eq 0 ]]; then
echo "Unable to determine the files affected by this PR"
exit 1
Expand Down

0 comments on commit 2961b9b

Please sign in to comment.