|
| 1 | +name: 'PR Classifiers' |
| 2 | +description: 'Classifies a pull request with the internal getsentry/classifiers action, without checking out or running the pull request' |
| 3 | +author: 'Sentry' |
| 4 | + |
| 5 | +inputs: |
| 6 | + app-client-id: |
| 7 | + description: 'Client ID of the GitHub App that can read getsentry/classifiers (the client ID, not the numeric App ID).' |
| 8 | + required: true |
| 9 | + app-private-key: |
| 10 | + description: 'Private key of that GitHub App.' |
| 11 | + required: true |
| 12 | + ai-gateway-api-key: |
| 13 | + description: 'AI Gateway key for the model call. Use a dedicated key with a spend cap.' |
| 14 | + required: true |
| 15 | + classifiers-ref: |
| 16 | + description: 'Commit of getsentry/classifiers to run. Leave unset to use the commit this action was released with.' |
| 17 | + required: false |
| 18 | + default: '3f2158c236f47bfb7e918a7350399769a59569ec' |
| 19 | + publish-label: |
| 20 | + description: "'true' lets the action own the labels it publishes on the pull request. Needs `pull-requests: write`." |
| 21 | + required: false |
| 22 | + default: 'true' |
| 23 | + publish-comment: |
| 24 | + description: "'true' keeps one summary comment on the pull request. Needs `pull-requests: write`." |
| 25 | + required: false |
| 26 | + default: 'false' |
| 27 | + upload-result: |
| 28 | + description: "'true' uploads the public result JSON as a workflow artifact." |
| 29 | + required: false |
| 30 | + default: 'true' |
| 31 | + |
| 32 | +outputs: |
| 33 | + status: |
| 34 | + description: 'How the run ended; `ok` when the pull request was classified.' |
| 35 | + value: ${{ steps.classify.outputs.status }} |
| 36 | + risk-label: |
| 37 | + description: 'The final label (low, medium or high), or empty when the status is not ok.' |
| 38 | + value: ${{ steps.classify.outputs.risk-label }} |
| 39 | + model-label: |
| 40 | + description: "The model's label before the rules that block low; empty unless the status is ok." |
| 41 | + value: ${{ steps.classify.outputs.model-label }} |
| 42 | + head-sha: |
| 43 | + description: 'Head commit that was scored; empty unless the status is ok.' |
| 44 | + value: ${{ steps.classify.outputs.head-sha }} |
| 45 | + base-sha: |
| 46 | + description: 'Base commit that was scored; empty unless the status is ok.' |
| 47 | + value: ${{ steps.classify.outputs.base-sha }} |
| 48 | + label-published: |
| 49 | + description: "'true' only when the label was added to the unchanged pull request." |
| 50 | + value: ${{ steps.classify.outputs.label-published }} |
| 51 | + summary: |
| 52 | + description: 'Markdown summary of the result. It holds text derived from the pull request (file paths): pass it through an environment variable, never inline it in a script.' |
| 53 | + value: ${{ steps.classify.outputs.summary }} |
| 54 | + |
| 55 | +runs: |
| 56 | + using: 'composite' |
| 57 | + steps: |
| 58 | + # No step here checks out or runs code from the pull request. The only checkout is |
| 59 | + # getsentry/classifiers at a pinned commit; the classifier reads the pull request's |
| 60 | + # commits itself, into an isolated bare repository. |
| 61 | + - name: Get a token for the classifiers repository |
| 62 | + id: app |
| 63 | + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 |
| 64 | + with: |
| 65 | + client-id: ${{ inputs.app-client-id }} |
| 66 | + private-key: ${{ inputs.app-private-key }} |
| 67 | + repositories: classifiers |
| 68 | + # The token can read this one repository's contents and nothing else. |
| 69 | + permission-contents: read |
| 70 | + |
| 71 | + - name: Fetch the classifiers |
| 72 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 73 | + with: |
| 74 | + repository: getsentry/classifiers |
| 75 | + ref: ${{ inputs.classifiers-ref }} |
| 76 | + token: ${{ steps.app.outputs.token }} |
| 77 | + path: .classifiers |
| 78 | + persist-credentials: false |
| 79 | + |
| 80 | + - name: Classify the pull request |
| 81 | + id: classify |
| 82 | + # A local path in a composite action resolves against the workspace, where the |
| 83 | + # previous step put the checkout. |
| 84 | + uses: ./.classifiers/actions/pr |
| 85 | + env: |
| 86 | + # On this step only. |
| 87 | + AI_GATEWAY_API_KEY: ${{ inputs.ai-gateway-api-key }} |
| 88 | + with: |
| 89 | + repo: ${{ github.repository }} |
| 90 | + pr-number: ${{ github.event.pull_request.number }} |
| 91 | + expected-head-sha: ${{ github.event.pull_request.head.sha }} |
| 92 | + result-path: pr-classifiers-result.json |
| 93 | + publish-label: ${{ inputs.publish-label }} |
| 94 | + publish-comment: ${{ inputs.publish-comment }} |
| 95 | + |
| 96 | + - name: Upload the result |
| 97 | + if: ${{ always() && inputs.upload-result == 'true' }} |
| 98 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 |
| 99 | + with: |
| 100 | + name: pr-classifiers-${{ github.event.pull_request.number }} |
| 101 | + path: pr-classifiers-result.json |
| 102 | + if-no-files-found: warn |
| 103 | + retention-days: 30 |
0 commit comments