Skip to content

Commit

Permalink
Switch to pull_request_target in labeler workflow (#4101)
Browse files Browse the repository at this point in the history
* Switch to `pull_request_target` in labeler workflow

* handle split-checkout scenario

* set base branch name

* fix merge commit race
  • Loading branch information
mastercactapus authored Oct 7, 2024
1 parent 8a7b4fa commit 9118acf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: labeler

on:
pull_request:
pull_request_target:
types: ['opened', 'ready_for_review', 'reopened', 'synchronize']

jobs:
Expand All @@ -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
3 changes: 2 additions & 1 deletion devtools/scripts/github-set-pr-label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9118acf

Please sign in to comment.