-
Notifications
You must be signed in to change notification settings - Fork 577
[ci] Upgrade and automate gh-aw workflows #12460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonathanpeppers
wants to merge
1
commit into
main
Choose a base branch
from
jonathanpeppers-upgrade-gh-aw-workflows-2e7
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| name: Agentic Auto-Upgrade PR | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '17 4 * * 1' # Mondays at 04:17 UTC | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: agentic-auto-upgrade-pr | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| upgrade: | ||
| if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !github.event.repository.fork | ||
| runs-on: ubuntu-latest | ||
| environment: copilot-pat-pool | ||
| steps: | ||
| - name: Checkout default branch | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.event.repository.default_branch }} | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Resolve latest stable gh-aw version | ||
| id: latest | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| version=$(gh api repos/github/gh-aw/releases/latest --jq .tag_name) | ||
| echo "version=$version" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Install latest stable gh-aw | ||
| uses: github/gh-aw-actions/setup-cli@6aab9e5b5c91c615506061f09bedd81a23babe3c # v0.86.2 | ||
| with: | ||
| version: ${{ steps.latest.outputs.version }} | ||
|
|
||
| - name: Upgrade workflows and update pull request | ||
| env: | ||
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
| GH_TOKEN: ${{ secrets.GH_AW_GITHUB_TOKEN }} | ||
| GH_AW_VERSION: ${{ steps.latest.outputs.version }} | ||
| UPGRADE_BRANCH: automation/gh-aw-upgrade | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| if [[ -z "${GH_TOKEN:-}" ]]; then | ||
| echo "GH_AW_GITHUB_TOKEN must be a token that can update workflow files." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| gh aw upgrade | ||
| gh aw compile .github/workflows --validate | ||
|
|
||
| changed_files=$( | ||
| { | ||
| git diff --name-only | ||
| git ls-files --others --exclude-standard | ||
| } | sort -u | ||
| ) | ||
| if [[ -z "$changed_files" ]]; then | ||
| echo "All agentic workflows already use $GH_AW_VERSION." | ||
| exit 0 | ||
| fi | ||
|
|
||
| invalid_files=$( | ||
| while IFS= read -r file; do | ||
| case "$file" in | ||
| .github/agents/*|.github/aw/*|.github/skills/*|.github/workflows/*) ;; | ||
| *) echo "$file" ;; | ||
| esac | ||
| done <<< "$changed_files" | ||
| ) | ||
| if [[ -n "$invalid_files" ]]; then | ||
| echo "gh aw upgrade changed files outside the approved .github paths:" >&2 | ||
| echo "$invalid_files" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git config user.name "github-actions[bot]" | ||
| git switch -c "$UPGRADE_BRANCH" | ||
| git add -A -- .github/agents .github/aw .github/skills .github/workflows | ||
| git commit -m "[ci] Upgrade gh-aw to $GH_AW_VERSION" | ||
|
|
||
| git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | ||
| remote_sha=$(git ls-remote --heads origin "refs/heads/$UPGRADE_BRANCH" | cut -f1) | ||
| if [[ -n "$remote_sha" ]]; then | ||
| git push \ | ||
| --force-with-lease="refs/heads/$UPGRADE_BRANCH:$remote_sha" \ | ||
| origin "HEAD:refs/heads/$UPGRADE_BRANCH" | ||
| else | ||
| git push origin "HEAD:refs/heads/$UPGRADE_BRANCH" | ||
| fi | ||
|
|
||
| body_file="$RUNNER_TEMP/gh-aw-upgrade-pr.md" | ||
| { | ||
| echo "## Summary" | ||
| echo | ||
| echo "Upgrade agentic workflows to gh-aw $GH_AW_VERSION." | ||
| echo | ||
| echo "## Changed files" | ||
| echo | ||
| git show --pretty="" --name-only HEAD | sed 's/^/- `/' | sed 's/$/`/' | ||
| echo | ||
| echo "## Validation" | ||
| echo | ||
| echo "- \`gh aw upgrade\`" | ||
| echo "- \`gh aw compile .github/workflows --validate\`" | ||
| } > "$body_file" | ||
|
|
||
| owner="${GITHUB_REPOSITORY%%/*}" | ||
| pr_number=$( | ||
| gh api --method GET "repos/$GITHUB_REPOSITORY/pulls" \ | ||
| -f state=open \ | ||
| -f "head=$owner:$UPGRADE_BRANCH" \ | ||
| --jq '.[0].number // empty' | ||
| ) | ||
|
|
||
| request_file="$RUNNER_TEMP/gh-aw-upgrade-pr.json" | ||
| if [[ -n "$pr_number" ]]; then | ||
| jq -n \ | ||
| --arg title "[ci] Upgrade gh-aw to $GH_AW_VERSION" \ | ||
| --rawfile body "$body_file" \ | ||
| '{title: $title, body: $body}' > "$request_file" | ||
| gh api --method PATCH "repos/$GITHUB_REPOSITORY/pulls/$pr_number" --input "$request_file" | ||
| else | ||
| jq -n \ | ||
| --arg title "[ci] Upgrade gh-aw to $GH_AW_VERSION" \ | ||
| --arg head "$UPGRADE_BRANCH" \ | ||
| --arg base "$DEFAULT_BRANCH" \ | ||
| --rawfile body "$body_file" \ | ||
| '{title: $title, head: $head, base: $base, body: $body}' > "$request_file" | ||
| gh api --method POST "repos/$GITHUB_REPOSITORY/pulls" --input "$request_file" | ||
| fi | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.