Skip to content

Commit 201724c

Browse files
committed
open PR in Pinata when new cagent-version is released
Signed-off-by: Derek Misler <derek.misler@docker.com>
1 parent 9a695fb commit 201724c

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.github/workflows/release.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
outputs:
2828
version: ${{ steps.version.outputs.version }}
29+
sha: ${{ steps.release-commit.outputs.sha }}
2930

3031
steps:
3132
- name: Checkout code
@@ -164,6 +165,110 @@ jobs:
164165
165166
echo "Updated 'latest' tag to point to ${VERSION} ($RELEASE_SHA)"
166167
168+
update-pinata:
169+
name: Update pinata pr-review workflow
170+
needs: release
171+
if: success()
172+
runs-on: ubuntu-latest
173+
steps:
174+
- name: Generate GitHub App token
175+
id: app-token
176+
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
177+
with:
178+
app_id: ${{ secrets.CAGENT_REVIEWER_APP_ID }}
179+
private_key: ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }}
180+
repository: docker/pinata
181+
182+
- name: Checkout pinata
183+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
184+
with:
185+
repository: docker/pinata
186+
token: ${{ steps.app-token.outputs.token }}
187+
188+
- name: Update cagent-action reference
189+
id: update
190+
env:
191+
SHA: ${{ needs.release.outputs.sha }}
192+
VERSION: ${{ needs.release.outputs.version }}
193+
run: |
194+
FILE=".github/workflows/pr-review.yml"
195+
if [ ! -f "$FILE" ]; then
196+
echo "::error::$FILE not found in pinata"
197+
exit 1
198+
fi
199+
200+
if [ -z "$SHA" ] || [ -z "$VERSION" ]; then
201+
echo "::error::SHA or VERSION is empty (SHA='$SHA', VERSION='$VERSION')"
202+
exit 1
203+
fi
204+
205+
PATTERN='cagent-action/\.github/workflows/review-pr\.yml@[a-f0-9]\{40\} # v[0-9.]*'
206+
if ! grep -q "$PATTERN" "$FILE"; then
207+
echo "::error::Expected cagent-action reference pattern not found in $FILE — format may have changed"
208+
exit 1
209+
fi
210+
211+
sed -i "s|${PATTERN}|cagent-action/.github/workflows/review-pr.yml@${SHA} # ${VERSION}|" "$FILE"
212+
213+
if git diff --quiet "$FILE"; then
214+
echo "File already up to date, skipping."
215+
echo "skip=true" >> "$GITHUB_OUTPUT"
216+
else
217+
echo "Updated reference to ${SHA} # ${VERSION}"
218+
echo "skip=false" >> "$GITHUB_OUTPUT"
219+
fi
220+
221+
- name: Create or update PR
222+
if: steps.update.outputs.skip != 'true'
223+
env:
224+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
225+
VERSION: ${{ needs.release.outputs.version }}
226+
SHA: ${{ needs.release.outputs.sha }}
227+
run: |
228+
BRANCH="auto/update-cagent-action"
229+
RELEASE_URL="https://github.com/docker/cagent-action/releases/tag/$VERSION"
230+
231+
git config user.name "docker-agent[bot]"
232+
git config user.email "259137750+docker-agent[bot]@users.noreply.github.com"
233+
234+
git checkout -B "$BRANCH"
235+
git add .github/workflows/pr-review.yml
236+
git commit -m "chore: update cagent-action to $VERSION"
237+
238+
# Force-push to handle both new and existing branches.
239+
# This branch is exclusively managed by this workflow, so --force is safe.
240+
git push --force origin "$BRANCH"
241+
242+
EXISTING_PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
243+
244+
PR_BODY="$(cat <<EOF
245+
## Summary
246+
Updates \`cagent-action\` reference in \`pr-review.yml\` to [$VERSION]($RELEASE_URL).
247+
- **Commit**: \`${SHA}\`
248+
- **Version**: \`${VERSION}\`
249+
> Auto-generated by the [release](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.
250+
251+
/skip-builds
252+
/skip-tests
253+
EOF
254+
)"
255+
256+
if [ -n "$EXISTING_PR" ]; then
257+
echo "Updating existing PR #$EXISTING_PR"
258+
gh pr edit "$EXISTING_PR" \
259+
--title "chore: update cagent-action to $VERSION" \
260+
--body "$PR_BODY" \
261+
--add-reviewer "derekmisler"
262+
else
263+
echo "Creating new PR"
264+
gh pr create \
265+
--title "chore: update cagent-action to $VERSION" \
266+
--body "$PR_BODY" \
267+
--label "team/gordon" \
268+
--label "merge/auto" \
269+
--reviewer "derekmisler"
270+
fi
271+
167272
publish-agent:
168273
name: Push review-pr agent to Docker Hub
169274
needs: release

0 commit comments

Comments
 (0)