|
| 1 | +# Triages newly-opened (and reopened/edited) adk-java pull requests with the ADK |
| 2 | +# PR Triaging Agent sample under contrib/samples/github/adkprtriaging. The agent |
| 3 | +# labels the PR and, when it falls short of the contribution guidelines, posts a |
| 4 | +# single comment asking the author for the missing context. |
| 5 | +# |
| 6 | +# Required repository secrets: |
| 7 | +# - GOOGLE_API_KEY : Gemini API key (or wire up Vertex AI credentials and |
| 8 | +# set GOOGLE_GENAI_USE_VERTEXAI=TRUE). |
| 9 | +# Labeling/commenting uses the built-in GITHUB_TOKEN (no secret to manage); the |
| 10 | +# `permissions:` block below grants it the `pull-requests: write` scope it needs. |
| 11 | +# Swap in a PAT only if you specifically want triage actions attributed to a |
| 12 | +# distinct bot identity. |
| 13 | +# |
| 14 | +# Security note: this workflow uses `pull_request_target`, so it runs with the |
| 15 | +# base repository's token/secrets. It deliberately relies on the DEFAULT checkout |
| 16 | +# (the base branch) and never checks out the PR head, so untrusted PR code is |
| 17 | +# never executed — the agent only reads the PR through the GitHub API. The agent |
| 18 | +# additionally treats the PR title/body/diff as untrusted data, binds its writes |
| 19 | +# to the triggering PR number and a fixed label allowlist, and pins writes to |
| 20 | +# this repository (see the sample's README for the full threat model). |
| 21 | +name: ADK PR Triaging Agent |
| 22 | + |
| 23 | +on: |
| 24 | + pull_request_target: |
| 25 | + types: [opened, reopened, edited] |
| 26 | + workflow_dispatch: |
| 27 | + inputs: |
| 28 | + pr_number: |
| 29 | + description: 'The pull request number to triage' |
| 30 | + required: true |
| 31 | + type: 'string' |
| 32 | + dry_run: |
| 33 | + description: 'Dry run: preview only. Set to false to actually create the issue and PRs.' |
| 34 | + required: false |
| 35 | + default: true |
| 36 | + type: boolean |
| 37 | + |
| 38 | +# Serialize runs that touch the same PR so a re-trigger (e.g. an "edited" event) |
| 39 | +# can't race an in-flight run on the same PR (which, with label appends, could |
| 40 | +# duplicate labels or comments). |
| 41 | +concurrency: |
| 42 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.inputs.pr_number }} |
| 43 | + cancel-in-progress: false |
| 44 | + |
| 45 | +jobs: |
| 46 | + agent-triage-pull-request: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + # Only run on the upstream repo, for newly-opened/reopened/edited PRs or a |
| 49 | + # manual dispatch. |
| 50 | + if: >- |
| 51 | + github.repository == 'google/adk-java' && ( |
| 52 | + github.event_name == 'workflow_dispatch' || |
| 53 | + github.event.action == 'opened' || |
| 54 | + github.event.action == 'reopened' || |
| 55 | + github.event.action == 'edited' |
| 56 | + ) |
| 57 | + permissions: |
| 58 | + pull-requests: write |
| 59 | + contents: read |
| 60 | + |
| 61 | + steps: |
| 62 | + # Default checkout: the base branch (trusted code), NOT the PR head. |
| 63 | + - name: Checkout repository |
| 64 | + uses: actions/checkout@v6 |
| 65 | + |
| 66 | + - name: Set up Java |
| 67 | + uses: actions/setup-java@v5 |
| 68 | + with: |
| 69 | + distribution: temurin |
| 70 | + java-version: '17' |
| 71 | + cache: maven |
| 72 | + |
| 73 | + - name: Run PR Triaging Agent |
| 74 | + env: |
| 75 | + # Built-in token scoped by the `permissions:` block above. Replace with a |
| 76 | + # PAT (e.g. ${{ secrets.ADK_TRIAGE_AGENT }}) only if you need a distinct |
| 77 | + # bot identity for the label/comment actions. |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 80 | + GOOGLE_GENAI_USE_VERTEXAI: '0' |
| 81 | + OWNER: ${{ github.repository_owner }} |
| 82 | + REPO: ${{ github.event.repository.name }} |
| 83 | + INTERACTIVE: '0' |
| 84 | + # Defaults to a dry run (logs intended labels/comments without writing). |
| 85 | + # Verify the pipeline, then set DRY_RUN to '0' to go live. |
| 86 | + DRY_RUN: ${{ github.event.inputs.dry_run || 'true' }} |
| 87 | + EVENT_NAME: ${{ github.event_name }} |
| 88 | + PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr_number }} |
| 89 | + run: | |
| 90 | + # Install the ADK libs + this sample, then run exec:java scoped to this |
| 91 | + # module (exec:java with -am would also run on the parent/core modules, |
| 92 | + # which have no mainClass). |
| 93 | + ./mvnw -B -q -pl contrib/samples/github/adkprtriaging -am install -DskipTests |
| 94 | + ./mvnw -B -q -pl contrib/samples/github/adkprtriaging exec:java |
0 commit comments