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