diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 64c7c44d..6fb72c7e 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -1,22 +1,39 @@ -# This workflow will triage pull requests and apply a label based on the -# paths that are modified in the pull request. -# -# To use this workflow, you will need to set up a .github/labeler.yml -# file with configuration. For more information, see: -# https://github.com/actions/labeler +# This workflow triages pull requests and applies labels based on changed paths. +# It is resilient when labeler config is missing on the base branch. name: Labeler -on: [pull_request_target] + +on: + pull_request_target: + types: [opened, synchronize, reopened, ready_for_review] jobs: label: - runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - - uses: actions/labeler@v5.0.0 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" + - name: Checkout base branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.ref }} + + - name: Verify labeler config exists + id: labeler_config + shell: bash + run: | + if [[ -f ".github/labeler.yml" ]]; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + echo "::warning title=Labeler config missing::.github/labeler.yml not found on base branch; skipping labeler." + fi + + - name: Apply labels + if: steps.labeler_config.outputs.exists == 'true' + uses: actions/labeler@v5 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/labeler.yml