Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
230 lines (212 loc) · 8.75 KB
/
Copy pathaction.yml
File metadata and controls
230 lines (212 loc) · 8.75 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: "Augur cost gate"
description: "Project an AI agent's production cost from a recorded trace and fail the PR if it's over budget."
branding:
icon: "dollar-sign"
color: "purple"
inputs:
trace:
description: "Path to the cost trace (JSONL). Ignored if `cassette` is set."
default: "trace.jsonl"
pricing:
description: "Path to the pricing snapshot."
default: "pricing.yaml"
tco:
description: "Path to a self-hosted TCO config. Overrides `pricing` when set."
default: ""
traffic:
description: "Path to the traffic profile."
default: "traffic.yaml"
budget:
description: "Path to the budget thresholds."
default: "budget.yaml"
scenarios:
description: "Path to scenarios.yaml. Only used when replaying a cassette."
default: "scenarios.yaml"
cassette:
description: "If set, replay this cassette to regenerate the trace (no tokens spent). Requires the agent command to be runnable in CI."
default: ""
extra-args:
description: "Extra flags passed to `augur gate` (e.g. what-if knobs: --context-growth 1.5)."
default: ""
comment:
description: "Post (or update) the report as a PR comment."
default: "true"
working-directory:
description: "Directory the config files live in."
default: "."
version:
description: "Which augur release to use. 'auto' downloads the prebuilt binary matching the tag you pinned the action to (e.g. @v1.2.0); a specific tag (v1.2.0) forces that release; 'source' always builds from source."
default: "auto"
go-version:
description: "Go version for the from-source fallback build (used when no prebuilt binary is available)."
default: "1.25"
outputs:
pass:
description: "'true' if within budget, 'false' if over."
value: ${{ steps.gate.outputs.pass }}
report-path:
description: "Absolute path to the generated Markdown report."
value: ${{ steps.gate.outputs.report-path }}
runs:
using: "composite"
steps:
# Prefer a prebuilt binary from the GitHub release so agent repos (Python/TS/
# Node) don't need a Go toolchain in CI. Falls back to a source build when no
# matching release asset exists (a branch/SHA pin, an unbuilt platform, or a
# download failure) — need-build drives the two steps that follow.
- name: Resolve augur binary
id: resolve
shell: bash
run: |
set -euo pipefail
want='${{ inputs.version }}'
ref='${{ github.action_ref }}'
# Decide which release tag to fetch (empty => build from source).
version=""
if [ "$want" = "source" ]; then
version=""
elif [ "$want" = "auto" ] || [ -z "$want" ]; then
case "$ref" in
v[0-9]*) version="$ref" ;; # pinned to a release tag
*) version="" ;; # branch/SHA => no release asset
esac
else
version="$want" # explicit tag
fi
if [ -z "$version" ]; then
echo "augur: no prebuilt release for ref='$ref' (version input '$want'); building from source."
echo "need-build=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Map the runner to the os/arch naming GoReleaser used for the assets.
case "${RUNNER_OS}" in
Linux) os=linux ;;
macOS) os=darwin ;;
Windows) os=windows ;;
*) echo "augur: unsupported RUNNER_OS=$RUNNER_OS; building from source."; echo "need-build=true" >> "$GITHUB_OUTPUT"; exit 0 ;;
esac
case "${RUNNER_ARCH}" in
X64) arch=amd64 ;;
ARM64) arch=arm64 ;;
*) echo "augur: unsupported RUNNER_ARCH=$RUNNER_ARCH; building from source."; echo "need-build=true" >> "$GITHUB_OUTPUT"; exit 0 ;;
esac
base="https://github.com/Cro22/Augur/releases/download/${version}"
archive="augur_${os}_${arch}.tar.gz"
dest="${RUNNER_TEMP}/augur-dl"
mkdir -p "$dest"
echo "augur: fetching ${archive} from release ${version}"
if ! curl -fsSL "${base}/${archive}" -o "${dest}/${archive}" \
|| ! curl -fsSL "${base}/checksums.txt" -o "${dest}/checksums.txt"; then
echo "augur: prebuilt download failed; falling back to a source build."
echo "need-build=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Verify the checksum before trusting the binary. Extract the expected
# hash with awk (tolerating a leading '*' binary-mode marker) and compare
# to the computed one, so it works with either sha256sum or shasum and is
# insensitive to the one-/two-space separator variants.
cd "$dest"
want_sum="$(awk -v f="${archive}" '{ n=$2; sub(/^\*/,"",n); if (n==f) print $1 }' checksums.txt)"
if command -v sha256sum >/dev/null 2>&1; then
got_sum="$(sha256sum "${archive}" | awk '{print $1}')"
else
got_sum="$(shasum -a 256 "${archive}" | awk '{print $1}')"
fi
if [ -z "$want_sum" ] || [ "$want_sum" != "$got_sum" ]; then
echo "::error::augur: checksum mismatch for ${archive} (expected '${want_sum}', got '${got_sum}')"
exit 1
fi
tar -xzf "${archive}"
bin="${dest}/augur"
[ -f "${dest}/augur.exe" ] && bin="${dest}/augur.exe"
chmod +x "$bin" 2>/dev/null || true
echo "AUGUR=${bin}" >> "$GITHUB_ENV"
echo "need-build=false" >> "$GITHUB_OUTPUT"
echo "augur: using prebuilt $("$bin" version | head -1)"
- name: Set up Go
if: ${{ steps.resolve.outputs.need-build == 'true' }}
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: Build augur (source fallback)
if: ${{ steps.resolve.outputs.need-build == 'true' }}
shell: bash
run: |
cd "${{ github.action_path }}"
go build -o "${RUNNER_TEMP}/augur" .
echo "AUGUR=${RUNNER_TEMP}/augur" >> "$GITHUB_ENV"
- name: Replay cassette
if: ${{ inputs.cassette != '' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
"$AUGUR" run \
--scenarios "${{ inputs.scenarios }}" \
--replay "${{ inputs.cassette }}" \
--trace "${{ inputs.trace }}"
- name: Augur gate
id: gate
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
pricing_args="--pricing ${{ inputs.pricing }}"
if [ -n "${{ inputs.tco }}" ]; then
pricing_args="--tco ${{ inputs.tco }}"
fi
set +e
"$AUGUR" gate \
--trace "${{ inputs.trace }}" \
$pricing_args \
--traffic "${{ inputs.traffic }}" \
--budget "${{ inputs.budget }}" \
--report-md augur-report.md \
--report-json augur-report.json \
${{ inputs.extra-args }}
code=$?
set -e
if [ "$code" -eq 0 ]; then
echo "pass=true" >> "$GITHUB_OUTPUT"
elif [ -f augur-report.md ]; then
# Report exists => a genuine over-budget verdict (not an internal error).
echo "pass=false" >> "$GITHUB_OUTPUT"
else
echo "::error::augur gate failed before producing a report (exit $code)"
exit "$code"
fi
echo "exit-code=$code" >> "$GITHUB_OUTPUT"
echo "report-path=$(pwd)/augur-report.md" >> "$GITHUB_OUTPUT"
- name: Post report comment
if: ${{ always() && inputs.comment == 'true' && github.event_name == 'pull_request' && steps.gate.outputs.report-path != '' }}
uses: actions/github-script@v7
env:
AUGUR_REPORT_PATH: ${{ steps.gate.outputs.report-path }}
with:
script: |
const fs = require('fs');
const marker = '<!-- augur-cost-report -->';
let report;
try {
report = fs.readFileSync(process.env.AUGUR_REPORT_PATH, 'utf8');
} catch (e) {
report = '_Augur produced no report._';
}
const body = `${marker}\n${report}`;
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number,
});
const existing = comments.find(c => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number, body });
}
- name: Enforce budget
shell: bash
run: |
if [ "${{ steps.gate.outputs.pass }}" != "true" ]; then
echo "::error::Augur: projected cost is over budget — see the report comment."
exit 1
fi
echo "Augur: within budget."