-
Notifications
You must be signed in to change notification settings - Fork 579
138 lines (122 loc) · 4.89 KB
/
Copy pathagentic-auto-upgrade-pr.yml
File metadata and controls
138 lines (122 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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