From 9118acf95bbb4c5637910fbbb51a9eddd651b69c Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Mon, 7 Oct 2024 13:56:44 -0500 Subject: [PATCH] Switch to `pull_request_target` in labeler workflow (#4101) * Switch to `pull_request_target` in labeler workflow * handle split-checkout scenario * set base branch name * fix merge commit race --- .github/workflows/labeler.yml | 16 +++++++++++----- devtools/scripts/github-set-pr-label.sh | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index fcf1ab1d5c..9c69355ad1 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: @@ -14,11 +13,18 @@ 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: refs/pull/${{ github.event.number }}/merge + 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 + MAIN_BRANCH: ${{ github.event.pull_request.base.ref }} + 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