Repository navigation
91 lines (87 loc) · 3.13 KB
/
Copy pathagent-image.yml
File metadata and controls
91 lines (87 loc) · 3.13 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
name: Agent image
on:
push:
branches:
- main
paths:
- "docker/agent/**"
- ".github/workflows/agent-image.yml"
pull_request:
paths:
- "docker/agent/**"
- ".github/workflows/agent-image.yml"
workflow_dispatch:
permissions:
contents: read
jobs:
image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
strategy:
matrix:
agent:
- claude
- codex
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- uses: docker/setup-qemu-action@v4.4.0
- uses: docker/setup-buildx-action@v4.4.1
- uses: docker/login-action@v4.8.0
if: ${{ github.event_name != 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v7.4.0
id: push
with:
context: docker/agent
target: ${{ matrix.agent }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
provenance: false
tags: |
ghcr.io/${{ github.repository }}-agent:${{ matrix.agent }}
ghcr.io/${{ github.repository }}-agent:${{ matrix.agent }}-${{ github.sha }}
- uses: actions/attest-build-provenance@v4.2.2
if: ${{ github.event_name != 'pull_request' }}
with:
subject-name: ghcr.io/${{ github.repository }}-agent
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
# Releases pin images by digest in internal/sandbox/images.json, so new images only reach users
# through a reviewed pull request.
pin:
needs: image
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# The job pushes the branch of its pull request with these credentials.
- uses: actions/checkout@v7.0.1 # zizmor: ignore[artipacked]
- name: Open a pull request pinning the new digests
env:
GH_TOKEN: ${{ github.token }}
IMAGE: ghcr.io/${{ github.repository }}-agent
run: |
set -euo pipefail
digest() { docker buildx imagetools inspect "$IMAGE:$1-$GITHUB_SHA" --format '{{json .Manifest.Digest}}' | tr -d '"'; }
jq -n --arg claude "$IMAGE@$(digest claude)" --arg codex "$IMAGE@$(digest codex)" '{claude: $claude, codex: $codex}' > internal/sandbox/images.json
if git diff --quiet; then
exit 0
fi
branch="agent-images/$GITHUB_SHA"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$branch"
git commit -am "Pin the agent images built from $GITHUB_SHA"
git push origin "$branch"
gh pr create --head "$branch" --title "Pin the agent images built from ${GITHUB_SHA:0:7}" --body "Pins the agent images the Agent image workflow published from $GITHUB_SHA."