From ae78f1441eee1e6cd241f2f5f63e9ff9d1fee96e Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Mon, 7 Oct 2024 10:55:06 -0500 Subject: [PATCH 1/4] Switch to `pull_request_target` in labeler workflow --- .github/workflows/labeler.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index fcf1ab1d5c..b768d0f914 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,7 +1,6 @@ name: labeler - on: - pull_request: + pull_request_target: types: ['opened', 'ready_for_review', 'reopened', 'synchronize'] jobs: From d897c4ecb9f1611c4bd49e67bc6c4ae6e1b84103 Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Mon, 7 Oct 2024 11:26:05 -0500 Subject: [PATCH 2/4] handle split-checkout scenario --- .github/workflows/labeler.yml | 12 +++++++++--- devtools/scripts/github-set-pr-label.sh | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index b768d0f914..7466481933 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -13,11 +13,17 @@ jobs: name: Label the PR size steps: - uses: actions/checkout@v4 - with: + with: # checkout the base branch, where we run the script from + path: base + - uses: actions/checkout@v4 + with: # checkout the merge commit, where the PR changes are + ref: ${{ github.event.pull_request.merge_commit_sha }} + path: merge + # we need full history fetch-depth: 0 - - name: Run labeler script + - name: Run labeler script from base env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.number }} FAIL_IF_XL: '1' - run: ./devtools/scripts/github-set-pr-label.sh + run: cd merge && ../base/devtools/scripts/github-set-pr-label.sh diff --git a/devtools/scripts/github-set-pr-label.sh b/devtools/scripts/github-set-pr-label.sh index 7c1f1c3249..3d7c12f677 100755 --- a/devtools/scripts/github-set-pr-label.sh +++ b/devtools/scripts/github-set-pr-label.sh @@ -6,7 +6,8 @@ if [ -z "PR_NUMBER" ]; then exit 1 fi -LABEL=$(./devtools/scripts/git-diff-label-calc.sh --debug) +MY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LABEL=$("$MY_DIR/git-diff-label-calc.sh" --debug) # Remove any existing test/* labels for label in $(gh pr view "$PR_NUMBER" --json labels --jq '.labels[] | select(.name | startswith("size/")) | .name'); do From 2d6456a8088c07f55ce1ec130ae0a5485700d08c Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Mon, 7 Oct 2024 11:28:32 -0500 Subject: [PATCH 3/4] set base branch name --- .github/workflows/labeler.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 7466481933..b529c23503 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -26,4 +26,5 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.number }} FAIL_IF_XL: '1' + MAIN_BRANCH: ${{ github.event.pull_request.base.ref }} run: cd merge && ../base/devtools/scripts/github-set-pr-label.sh From 8514a8e64c9b1da8332ff8eeba738db190b89171 Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Mon, 7 Oct 2024 11:39:22 -0500 Subject: [PATCH 4/4] fix merge commit race --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index b529c23503..9c69355ad1 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -17,7 +17,7 @@ jobs: path: base - uses: actions/checkout@v4 with: # checkout the merge commit, where the PR changes are - ref: ${{ github.event.pull_request.merge_commit_sha }} + ref: refs/pull/${{ github.event.number }}/merge path: merge # we need full history fetch-depth: 0