Skip to content

Commit baecd62

Browse files
committed
refactor: convert aw-upgrade CI example to gh-aw native workflow
- Replace plain YAML workflow with gh-aw markdown workflow format - Add compilation instructions for producing .lock.yml - Update GPM provisioning notes for .md-based deployment - Add auto-merge guidance using post-steps with App token
1 parent 5993dff commit baecd62

1 file changed

Lines changed: 93 additions & 56 deletions

File tree

commands/aw-upgrade.md

Lines changed: 93 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ After all phases complete (or on early exit), print a summary:
159159
│ gh-aw: {before} → {after} │
160160
│ Workflows: {N} compiled │
161161
│ Validation: ✓ passed │
162-
│ PR: {url}
162+
│ PR: {url} │
163163
│ Merged: yes/no/skipped │
164164
└─────────────────────────────────────┘
165165
```
@@ -173,67 +173,100 @@ The `gh aw upgrade --create-pull-request` flag already handles the upgrade + PR
173173
creation natively within gh-aw. This is the recommended path for CI automation
174174
rather than reimplementing the logic.
175175
176-
#### Recommended workflow: `.github/workflows/gh-aw-upgrade.lock.yml`
176+
#### Recommended workflow: `.github/workflows/gh-aw-upgrade.md`
177177
178-
Source as a gh-aw markdown workflow or a plain YAML workflow:
178+
This is a gh-aw markdown workflow. Compile it with `gh aw compile` to produce
179+
the `.lock.yml` that GitHub Actions executes.
180+
181+
````markdown
182+
---
183+
name: "gh-aw Auto-Upgrade"
184+
description: "Upgrade gh-aw extension, recompile workflows, and open a PR with changes"
185+
timeout-minutes: 10
179186
180-
```yaml
181-
name: gh-aw Upgrade Check
182187
on:
183-
schedule:
184-
- cron: '0 8 * * 1' # Weekly Monday 8am UTC
188+
schedule: "weekly on monday around 08:00"
185189
workflow_dispatch:
186190
inputs:
187191
force:
188-
description: 'Force upgrade even if on latest'
192+
description: "Force upgrade even if on latest version"
193+
required: false
189194
type: boolean
190-
default: false
191195
192196
permissions:
193197
contents: write
194-
pull-requests: write
195-
196-
jobs:
197-
upgrade:
198-
runs-on: ubuntu-latest
199-
steps:
200-
- uses: actions/checkout@v4
201-
202-
- name: Install gh-aw
203-
run: gh extension install github/gh-aw
204-
env:
205-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206-
207-
- name: Record version before
208-
id: before
209-
run: echo "version=$(gh aw version | awk '{print $NF}')" >> "$GITHUB_OUTPUT"
210-
211-
- name: Upgrade gh-aw extension
212-
run: gh extension upgrade github/gh-aw --force
213-
env:
214-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
215-
216-
- name: Record version after
217-
id: after
218-
run: echo "version=$(gh aw version | awk '{print $NF}')" >> "$GITHUB_OUTPUT"
219-
220-
- name: Upgrade repository workflows and create PR
221-
if: steps.before.outputs.version != steps.after.outputs.version || inputs.force
222-
run: gh aw upgrade --create-pull-request --verbose
223-
env:
224-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
225-
226-
- name: Auto-merge PR
227-
if: steps.before.outputs.version != steps.after.outputs.version || inputs.force
228-
run: |
229-
PR_URL=$(gh pr list --head "gh-aw-upgrade" --json url --jq '.[0].url' 2>/dev/null)
230-
if [ -n "$PR_URL" ]; then
231-
gh pr merge "$PR_URL" --squash --auto --delete-branch
232-
fi
233-
env:
234-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
198+
pull-requests: read
199+
200+
engine:
201+
id: copilot
202+
203+
tools:
204+
bash: ["gh:*", "echo", "awk"]
205+
206+
safe-outputs:
207+
create-pull-request:
208+
max: 1
209+
labels: [dependencies, ci]
210+
---
211+
212+
# gh-aw Auto-Upgrade Agent
213+
214+
## Context
215+
216+
You are performing an automated gh-aw extension upgrade on ${{ github.repository }}.
217+
This workflow runs weekly on Monday mornings, or on-demand via workflow dispatch.
218+
219+
The force input is: `${{ github.event.inputs.force }}`. Use this as `$FORCE_INPUT` in commands.
220+
221+
## Instructions
222+
223+
1. Install the gh-aw extension if not present:
224+
225+
```bash
226+
gh extension install github/gh-aw 2>/dev/null || true
227+
```
228+
229+
2. Record the **before** version:
230+
231+
```bash
232+
BEFORE_VERSION=$(gh aw version | awk '{print $NF}')
233+
echo "Before version: $BEFORE_VERSION"
235234
```
236235
236+
3. Upgrade the gh-aw extension:
237+
238+
```bash
239+
gh extension upgrade github/gh-aw --force
240+
```
241+
242+
4. Record the **after** version:
243+
244+
```bash
245+
AFTER_VERSION=$(gh aw version | awk '{print $NF}')
246+
echo "After version: $AFTER_VERSION"
247+
```
248+
249+
5. Compare versions:
250+
- If versions are identical **and** `$FORCE_INPUT` is not `true`: report "gh-aw is already on the latest version. No upgrade needed." and **stop**.
251+
- If versions differ or force is `true`: continue to step 6.
252+
253+
6. Run the upgrade and create a PR using the native gh-aw flag:
254+
255+
```bash
256+
gh aw upgrade --create-pull-request --verbose
257+
```
258+
259+
This handles branch creation, recompilation, commit, and PR creation in one command.
260+
261+
7. Report the result: before version, after version, and the PR URL if one was created.
262+
263+
## Edge Cases
264+
265+
- If `gh aw upgrade --create-pull-request` reports no changes, it will not create a PR. Report "No workflow changes after upgrade. Repo is already current." and stop.
266+
- If the upgrade fails, report the error output clearly and stop.
267+
- If a PR already exists from a previous run, gh-aw will update it or skip — this is safe to re-run.
268+
````
269+
237270
#### Key considerations:
238271
239272
1. **`gh aw upgrade --create-pull-request`** is the native flag — it handles
@@ -244,14 +277,14 @@ jobs:
244277
provisioning via GPM, use a GitHub App token with `contents: write` and
245278
`pull-requests: write` on target repos.
246279
247-
3. **GPM provisioning**: This workflow YAML can be deployed across repos using
280+
3. **GPM provisioning**: This workflow `.md` can be deployed across repos using
248281
the GPM `gpm-workflows-deploy` skill. Add it to gpm-config.yml under
249-
`workflows:` and GPM will push it to all managed repos.
282+
`workflows:` and GPM will push it to all managed repos. Then run
283+
`gh aw compile` in each repo to produce the `.lock.yml`.
250284
251-
4. **Alternative: gh-aw native workflow**: Write this as a gh-aw `.md`
252-
workflow that triggers on schedule, uses bash tools to run `gh extension
253-
upgrade` and `gh aw upgrade --create-pull-request`. This keeps the
254-
automation within the gh-aw ecosystem.
285+
4. **Compilation**: After writing the `.md` file, run `gh aw compile` to
286+
produce `.github/workflows/gh-aw-upgrade.lock.yml`. The `.lock.yml` is
287+
what GitHub Actions executes — never edit it directly.
255288
256289
5. **Branch naming**: `gh aw upgrade --create-pull-request` creates its own
257290
branch name. Check `gh aw upgrade --help` for any `--branch` flag in
@@ -260,4 +293,8 @@ jobs:
260293
6. **Idempotency**: The workflow is safe to re-run. If no changes result
261294
from `gh aw upgrade`, no PR is created. If a PR already exists, gh-aw
262295
will update it or skip.
296+
297+
7. **Auto-merge**: There is no `merge-pull-request` safe-output in gh-aw.
298+
If auto-merge is needed, add `post-steps` with an App token to merge
299+
the PR after the agent completes.
263300
-->

0 commit comments

Comments
 (0)