From 40ad85f681eb7bfeebf2a6900c448a34ef239315 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Sep 2024 14:11:50 +0200 Subject: [PATCH 1/4] If build is not associated with a pull request, Buildkite puts value `false` for `$BUILDKITE_PULL_REQUEST` Initially, I thought it just doesn't create such variable. --- bin/upload_sarif_to_github | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/upload_sarif_to_github b/bin/upload_sarif_to_github index 90d3201..c42efd8 100755 --- a/bin/upload_sarif_to_github +++ b/bin/upload_sarif_to_github @@ -31,7 +31,7 @@ sarif_base64_temp_file=$(mktemp) gzip -c "$sarif_file" | base64 > "$sarif_base64_temp_file" -if [[ -n $BUILDKITE_PULL_REQUEST ]]; then +if [[ $BUILDKITE_PULL_REQUEST != "false" ]]; then json=$(jq -n \ --arg commit_sha "$BUILDKITE_COMMIT" \ --arg pr_number "$BUILDKITE_PULL_REQUEST" \ From 0f4c9ed4dc796a9b1e6ed2767c63ca1811ea433c Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Sep 2024 14:15:05 +0200 Subject: [PATCH 2/4] Add CHANGELOG.md entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b08fed..f51cfd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ _None._ ### Bug Fixes -_None._ +Check for $BUILDKITE_PULL_REQUEST = false when uploading sarif file [#116] ### Internal Changes From bb11f23a8487a15069b2213b8efa2065438fe8ad Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Sep 2024 15:12:00 +0200 Subject: [PATCH 3/4] If build is not for PR or main branch, do not send sarif file. --- bin/upload_sarif_to_github | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/upload_sarif_to_github b/bin/upload_sarif_to_github index c42efd8..fb303df 100755 --- a/bin/upload_sarif_to_github +++ b/bin/upload_sarif_to_github @@ -51,6 +51,8 @@ elif [[ "$BUILDKITE_BRANCH" == "$BUILDKITE_PIPELINE_DEFAULT_BRANCH" ]]; then "ref": ("refs/heads/$branch"), "sarif": $sarif }') +else + exit 0 fi sarif_json_temp_file=$(mktemp) From a818d05e5fbf265c92cf1fe438ae2f795e2bdf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Zi=C4=99ba?= Date: Thu, 12 Sep 2024 15:27:12 +0200 Subject: [PATCH 4/4] Update bin/upload_sarif_to_github Co-authored-by: Olivier Halligon --- bin/upload_sarif_to_github | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/upload_sarif_to_github b/bin/upload_sarif_to_github index fb303df..f981d3a 100755 --- a/bin/upload_sarif_to_github +++ b/bin/upload_sarif_to_github @@ -31,7 +31,7 @@ sarif_base64_temp_file=$(mktemp) gzip -c "$sarif_file" | base64 > "$sarif_base64_temp_file" -if [[ $BUILDKITE_PULL_REQUEST != "false" ]]; then +if [[ "${BUILDKITE_PULL_REQUEST:-false}" != "false" ]]; then json=$(jq -n \ --arg commit_sha "$BUILDKITE_COMMIT" \ --arg pr_number "$BUILDKITE_PULL_REQUEST" \