labeler-predict-pulls.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Workflow template imported and updated from:
  2. # https://github.com/dotnet/issue-labeler/wiki/Onboarding
  3. #
  4. # See labeler.md for more information
  5. #
  6. # Predict labels for Pull Requests using a trained model
  7. name: "Labeler: Predict (Pulls)"
  8. on:
  9. # Per to the following documentation:
  10. # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target
  11. #
  12. # The `pull_request_target` event runs in the context of the base of the pull request, rather
  13. # than in the context of the merge commit, as the `pull_request` event does. This prevents
  14. # execution of unsafe code from the head of the pull request that could alter the repository
  15. # or steal any secrets you use in your workflow. This event allows your workflow to do things
  16. # like label or comment on pull requests from forks.
  17. #
  18. # Only automatically predict area labels when pull requests are first opened
  19. pull_request_target:
  20. types: opened
  21. # Configure the branches that need to have PRs labeled
  22. branches:
  23. - main
  24. # Allow dispatching the workflow via the Actions UI, specifying ranges of numbers
  25. workflow_dispatch:
  26. inputs:
  27. pulls:
  28. description: "Pull Request Numbers (comma-separated list of ranges)."
  29. required: true
  30. cache_key:
  31. description: "The cache key suffix to use for restoring the model. Defaults to 'ACTIVE'."
  32. required: true
  33. default: "ACTIVE"
  34. env:
  35. # Do not allow failure for jobs triggered automatically (this can block PR merge)
  36. ALLOW_FAILURE: ${{ github.event_name == 'workflow_dispatch' }}
  37. LABEL_PREFIX: "area-"
  38. THRESHOLD: 0.40
  39. DEFAULT_LABEL: "needs-area-label"
  40. jobs:
  41. predict-pull-label:
  42. # Do not automatically run the workflow on forks outside the 'dotnet' org
  43. if: ${{ github.event_name == 'workflow_dispatch' || github.repository_owner == 'dotnet' }}
  44. runs-on: ubuntu-latest
  45. permissions:
  46. pull-requests: write
  47. steps:
  48. - name: "Restore pulls model from cache"
  49. id: restore-model
  50. uses: dotnet/issue-labeler/restore@46125e85e6a568dc712f358c39f35317366f5eed # v2.0.0
  51. with:
  52. type: pulls
  53. fail-on-cache-miss: ${{ env.ALLOW_FAILURE }}
  54. quiet: true
  55. - name: "Predict pull labels"
  56. id: prediction
  57. if: ${{ steps.restore-model.outputs.cache-hit == 'true' }}
  58. uses: dotnet/issue-labeler/predict@46125e85e6a568dc712f358c39f35317366f5eed # v2.0.0
  59. with:
  60. pulls: ${{ inputs.pulls || github.event.number }}
  61. label_prefix: ${{ env.LABEL_PREFIX }}
  62. threshold: ${{ env.THRESHOLD }}
  63. default_label: ${{ env.DEFAULT_LABEL }}
  64. env:
  65. GITHUB_TOKEN: ${{ github.token }}
  66. continue-on-error: ${{ !env.ALLOW_FAILURE }}