Skip to content

Commit 93ac391

Browse files
authored
Upgrade gh-aw to v0.79.8 and run agentic workflow in isolated environment (#5604)
* Upgrade gh-aw to v0.79.8 and run agentic workflow in isolated environment - Add a validate-pat-pool workflow to monitor health of PAT pool * Fix indentation
1 parent 2993f35 commit 93ac391

6 files changed

Lines changed: 533 additions & 125 deletions

File tree

.github/aw/actions-lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"version": "v9.0.0",
66
"sha": "3a2844b7e9c422d3c10d287c895573f7108da1b3"
77
},
8-
"github/gh-aw-actions/setup@v0.74.8": {
8+
"github/gh-aw-actions/setup@v0.79.8": {
99
"repo": "github/gh-aw-actions/setup",
10-
"version": "v0.74.8",
11-
"sha": "efa55847f72aadb03490d955263ff911bf758700"
10+
"version": "v0.79.8",
11+
"sha": "c0338fef4749d08c21f8f975fb0e37efa17dda47"
1212
}
1313
}
1414
}

.github/workflows/shared/pat_pool.README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Selects a random Copilot PAT from a numbered pool of secrets. This addresses limitations that arise from having a single PAT shared across all agentic workflows, such as rate-limiting.
44

5-
**This is a stop-gap workaround.** As soon as organization/enterprise billing is offered for agentic workflows, this approach will be removed from our workflows.
5+
**This is a stop-gap workaround.** As soon as organization/enterprise billing is available to the dotnet org, this approach will be removed from our workflows.
66

77
## Repository Onboarding
88

@@ -19,9 +19,19 @@ gh extension install github/gh-aw --force
1919
gh aw --version
2020
```
2121

22+
### Environment
23+
24+
Create an environment for the agentic workflows:
25+
- _Configuring these settings requires repo admin permission_
26+
- https://github.com/dotnet/{repo}/settings/environments
27+
- Recommended Name: **copilot-pat-pool**
28+
- Recommended Deployment branches and tags: **Protected branches only**
29+
30+
This environment is used for all agentic workflows, restricting agentic workflows to the repo's protected branches and preventing the workflows from accessing secrets defined for other environments.
31+
2232
## PAT Management
2333

24-
Team members provide PATs into the pools for the repository by adding them as repository secrets with secret names matching the pattern of `<pool_name>_<0-9>`, such as `COPILOT_PAT_0`.
34+
Team members provide PATs into the pool with secret names matching the pattern of `{pool-name}_{0-9}`, such as `COPILOT_PAT_0`.
2535

2636
[Use this link to prefill the PAT creation form with the required settings][create-pat]:
2737

@@ -32,12 +42,30 @@ Team members provide PATs into the pools for the repository by adding them as re
3242

3343
The **Token Name** _does not_ need to match the secret name and is only visible to the owner of the PAT. It's recommended to use a token name indicating the PAT is used for dotnet org agentic workflows. The **Description** is also only used for your own reference.
3444

35-
Team members providing PATs for workflows should set weekly recurring reminders to regenerate and update their PATs in the repository secrets. With an 8-day expiration, renewal can be done on the same day each week.
45+
Team members providing PATs for workflows should set weekly recurring reminders to regenerate and update their PATs in the PAT pool. With an 8-day expiration, renewal can be done on the same day each week.
46+
47+
## PAT Pool Secrets
3648

37-
PATs are added to repositories through the **Settings > Secrets and variables > Actions** UI, saved as **Repository secrets** and matching the `<pool_name>_<0-9>` naming convention. This can also be done using the GitHub CLI.
49+
For a PAT pool that is specific to an environment, PATs can be added to repositories as **Environment Secrets** for the environment created above. _This requires repo admin permission_.
50+
51+
* **Settings** >
52+
* **Environments** >
53+
* **copilot-pat-pool** (or other environment name) >
54+
* **Add environment secret** (or edit your existing secret)
55+
* Enter your secret name of `COPILOT_PAT_{0-9}` and paste in your PAT
56+
57+
This can also be accomplished using the `gh` CLI, specifying the repo and environment arguments.
3858

3959
```sh
40-
gh aw secrets set "<pool_name>_<0-9>" --value "<your-github-pat>" --repo <org>/<repo>
60+
# Register the PAT secret. This will prompt for you to paste the PAT.
61+
gh secret set "<pool_name>_<0-9>" --repo <org>/<repo> --env "copilot-pat-pool"
62+
```
63+
64+
It's also helpful to record who owns each PAT within the pool. To capture which team member is associated with each PAT, a `<pool_name>_<0-9>_<username>` "sidecar secret" can be added alongside the PAT secret to make the username for the PAT pool entry visible. This sidecar secret must have a non-empty value, but it's never consumed, so any value is sufficient.
65+
66+
```sh
67+
# Record a sidecar secret that presents who owns this PAT.
68+
gh secret set "<pool_name>_<0-9>_<username>" --body "<username>" --repo <org>/<repo> --env "copilot-pat-pool"
4169
```
4270

4371
## Workflow Output Attribution
@@ -51,16 +79,22 @@ The [`pat_pool.md`](./pat_pool.md) workflow import defines a custom job with a `
5179
```yml
5280
# ###############################################################
5381
# Select a PAT from the pool and override COPILOT_GITHUB_TOKEN.
82+
# Run agentic jobs in an isolated `copilot-pat-pool` environment.
83+
#
5484
# When org-level billing is available, this will be removed.
5585
# See `shared/pat_pool.README.md` for more information.
5686
# ###############################################################
5787
imports:
58-
- shared/pat_pool.md
88+
- uses: shared/pat_pool.md
89+
with:
90+
environment: copilot-pat-pool
91+
92+
environment: copilot-pat-pool
5993

6094
engine:
6195
id: copilot
6296
env:
63-
COPILOT_GITHUB_TOKEN: |
97+
COPILOT_GITHUB_TOKEN: |
6498
${{ case(
6599
needs.pat_pool.outputs.pat_number == '0', secrets.COPILOT_PAT_0,
66100
needs.pat_pool.outputs.pat_number == '1', secrets.COPILOT_PAT_1,
@@ -72,16 +106,20 @@ engine:
72106
needs.pat_pool.outputs.pat_number == '7', secrets.COPILOT_PAT_7,
73107
needs.pat_pool.outputs.pat_number == '8', secrets.COPILOT_PAT_8,
74108
needs.pat_pool.outputs.pat_number == '9', secrets.COPILOT_PAT_9,
75-
secrets.COPILOT_GITHUB_TOKEN)
109+
'NO COPILOT PAT AVAILABLE')
76110
}}
77111
```
78112
79-
The expression can be collapsed onto a single line if desired. `gh-aw compile` automatically wires `pat_pool` into the activation and agent jobs' `needs:` graph because of the `needs.pat_pool.` references within the `engine.env` property.
113+
The `COPILOT_GITHUB_TOKEN` expression can be collapsed onto a single line if desired. `gh-aw compile` automatically wires `pat_pool` into the activation and agent jobs' `needs:` graph because of the `needs.pat_pool.` references within the `engine.env` property.
80114

81115
```sh
82116
gh aw compile <workflow-name> --schedule-seed <org>/<repo>
83117
```
84118

119+
### Specifying the environment
120+
121+
The `environment` must be specified both to the `pat_pool.md` import and to the containing workflow to ensure both jobs access the PAT pool from the same environment. The `copilot-pat-pool` environment name is recommended as the isolated environment for agentic workflows that use the PAT pool.
122+
85123
### Customizing the pool
86124

87125
The import declares 10 optional inputs (`COPILOT_PAT_0` through `COPILOT_PAT_9`), each defaulting to `secrets.COPILOT_PAT_#` of the matching number. To point a workflow at a different pool of repository secrets, use the parameterized `uses`/`with` form when importing and pass the substitute secrets as the `COPILOT_PAT_#` inputs:
@@ -101,7 +139,7 @@ The secrets passed via `with:` must match the secrets referenced in the consumin
101139
engine:
102140
id: copilot
103141
env:
104-
COPILOT_GITHUB_TOKEN: ${{ case(needs.pat_pool.outputs.pat_number == '0', secrets.MY_TEAM_PAT_0, needs.pat_pool.outputs.pat_number == '1', secrets.MY_TEAM_PAT_1, ..., secrets.COPILOT_GITHUB_TOKEN) }}
142+
COPILOT_GITHUB_TOKEN: ${{ case(needs.pat_pool.outputs.pat_number == '0', secrets.MY_TEAM_PAT_0, needs.pat_pool.outputs.pat_number == '1', secrets.MY_TEAM_PAT_1, ..., 'NO COPILOT PAT AVAILABLE') }}
105143
```
106144
107145
This approach aligns with GitHub's documented guidance for [passing secrets][passing-secrets] between workflows, where the `pat_pool` job returns a PAT number and the `case` statement acts as a secret store to look the PAT secret up based on the selected number.

.github/workflows/shared/pat_pool.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ description: Agentic workflow import to integrate the Copilot PAT Pool
33

44
jobs:
55
pat_pool:
6+
environment: ${{ github.aw.import-inputs.environment }}
67
needs: [pre_activation]
78
runs-on: ubuntu-slim
89
outputs:
@@ -68,6 +69,9 @@ jobs:
6869
echo "copilot_pat_number=${PAT_NUMBER}" >> "$GITHUB_OUTPUT"
6970
7071
import-schema:
72+
environment:
73+
type: string
74+
required: true
7175
COPILOT_PAT_0:
7276
type: string
7377
required: false

0 commit comments

Comments
 (0)