-
Notifications
You must be signed in to change notification settings - Fork 57
261 lines (227 loc) · 10.4 KB
/
Copy pathleaderboard.yml
File metadata and controls
261 lines (227 loc) · 10.4 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: Leaderboard Management
on:
# Validate on PR
pull_request:
paths:
- 'submissions/**/*-assessment.json'
# Update after merge to main
push:
branches: [main]
paths:
- 'submissions/**/*-assessment.json'
- 'scripts/generate-leaderboard-data.py'
# Manual trigger for testing
workflow_dispatch:
permissions:
contents: read
jobs:
# Job 1: Validate leaderboard submissions (PR only)
validate:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read # Checkout PR branch
steps:
# Fix for outdated forks: Always use upstream for validation tools/schema
# The PR branch may be from a fork that hasn't synced with upstream,
# causing validation to use outdated schema. We checkout upstream main
# for the agentready tools, then fetch only the submission file from PR.
# See: https://github.com/ambient-code/agentready/pull/312
- name: Checkout upstream for validation tools
uses: actions/checkout@v6
with:
repository: ${{ github.repository }}
ref: main
fetch-depth: 0
- name: Fetch PR submission file
env:
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
# Fetch the PR branch to get the submission file
git fetch "https://github.com/${PR_HEAD_REPO}.git" "${PR_HEAD_SHA}:refs/remotes/pr/head"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install uv
uv venv
source .venv/bin/activate
uv pip install -e .
- name: Extract submission details
id: extract
run: |
# Find changed JSON file between main and PR head
CHANGED_FILE=$(git diff --name-only origin/main...pr/head | grep 'submissions/.*-assessment.json' | head -1)
if [ -z "$CHANGED_FILE" ]; then
echo "No assessment file found in diff"
exit 1
fi
echo "file=$CHANGED_FILE" >> "$GITHUB_OUTPUT"
# Extract the submission file from PR branch to a temp location
# This ensures we validate the actual submitted file, not main branch
git show "pr/head:${CHANGED_FILE}" > /tmp/submission.json
# Parse JSON from PR's submission file - all values stored in outputs, not executed
REPO_URL=$(jq -r '.repository.url' /tmp/submission.json)
CLAIMED_SCORE=$(jq -r '.overall_score' /tmp/submission.json)
REPO_NAME=$(jq -r '.repository.name' /tmp/submission.json)
RESEARCH_VERSION=$(jq -r '.metadata.research_version // "unknown"' /tmp/submission.json)
{
echo "repo_url=$REPO_URL"
echo "claimed_score=$CLAIMED_SCORE"
echo "repo_name=$REPO_NAME"
echo "research_version=$RESEARCH_VERSION"
} >> "$GITHUB_OUTPUT"
- name: Validate JSON schema
run: |
# Validate using upstream's schema against the PR's submission file
# This ensures outdated forks don't cause false validation failures
source .venv/bin/activate
agentready validate-report /tmp/submission.json
- name: Detect repository host
id: detect_host
env:
REPO_URL: ${{ steps.extract.outputs.repo_url }}
run: |
# Determine if this is a GitHub or GitLab repository
if echo "$REPO_URL" | grep -q "github\.com"; then
echo "host=github" >> "$GITHUB_OUTPUT"
elif echo "$REPO_URL" | grep -q "gitlab\.com"; then
echo "host=gitlab" >> "$GITHUB_OUTPUT"
else
echo "::error::Unsupported repository host in URL: $REPO_URL"
exit 1
fi
# Convert SSH/HTTPS URL to an HTTPS clone URL
# git@<host>:<path>.git -> https://<host>/<path>.git
CLONE_URL=$(echo "$REPO_URL" | sed -E 's|^git@([^:]+):|https://\1/|' | sed 's|\.git$||')
echo "clone_url=${CLONE_URL}.git" >> "$GITHUB_OUTPUT"
echo "browse_url=$CLONE_URL" >> "$GITHUB_OUTPUT"
- name: Verify repository exists and is public
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_URL: ${{ steps.extract.outputs.repo_url }}
HOST: ${{ steps.detect_host.outputs.host }}
CLONE_URL: ${{ steps.detect_host.outputs.clone_url }}
run: |
if [ "$HOST" = "github" ]; then
# GitHub: use gh CLI for verification
ORG_REPO=$(echo "$REPO_URL" | sed 's|git@github.com:||' | sed 's|https://github.com/||' | sed 's|\.git$||')
IS_PRIVATE=$(gh repo view "$ORG_REPO" --json isPrivate -q '.isPrivate')
if [ "$IS_PRIVATE" == "true" ]; then
echo "::error::Repository $ORG_REPO is private."
exit 1
fi
echo "✅ Repository $ORG_REPO is public"
else
# GitLab/other: verify repo is publicly accessible via git ls-remote
if git ls-remote --exit-code "$CLONE_URL" HEAD > /dev/null 2>&1; then
echo "✅ Repository is publicly accessible: $CLONE_URL"
else
echo "::error::Repository is not publicly accessible: $CLONE_URL"
exit 1
fi
fi
- name: Verify submitter has access
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_URL: ${{ steps.extract.outputs.repo_url }}
SUBMITTER: ${{ github.event.pull_request.user.login }}
HOST: ${{ steps.detect_host.outputs.host }}
run: |
if [ "$HOST" = "github" ]; then
# GitHub: verify via API
ORG_REPO=$(echo "$REPO_URL" | sed 's|git@github.com:||' | sed 's|https://github.com/||' | sed 's|\.git$||')
if gh api "/repos/$ORG_REPO/collaborators/$SUBMITTER" --silent 2>/dev/null; then
echo "✅ $SUBMITTER is a collaborator on $ORG_REPO"
elif [ "$(gh api "/repos/$ORG_REPO" -q '.owner.login')" == "$SUBMITTER" ]; then
echo "✅ $SUBMITTER is the owner of $ORG_REPO"
else
echo "::warning::Cannot verify submitter access for $ORG_REPO (API check failed). Manual review required."
echo "⚠️ Submitter access must be verified manually by maintainers."
fi
else
# Non-GitHub: cannot verify cross-platform access automatically
echo "::warning::Cannot verify submitter access for non-GitHub repos. Manual review required."
echo "⚠️ Submitter access for non-GitHub repos must be verified manually by maintainers."
fi
- name: Re-run assessment
env:
CLONE_URL: ${{ steps.detect_host.outputs.clone_url }}
run: |
source .venv/bin/activate
echo "Cloning $CLONE_URL..."
git clone "$CLONE_URL" /tmp/repo-to-assess
echo "Running assessment..."
agentready assess /tmp/repo-to-assess --output-dir /tmp/validation
ACTUAL_SCORE=$(jq -r '.overall_score' /tmp/validation/assessment-latest.json)
ACTUAL_RESEARCH_VERSION=$(jq -r '.metadata.research_version // "unknown"' /tmp/validation/assessment-latest.json)
echo "ACTUAL_SCORE=$ACTUAL_SCORE" >> "$GITHUB_ENV"
echo "ACTUAL_RESEARCH_VERSION=$ACTUAL_RESEARCH_VERSION" >> "$GITHUB_ENV"
- name: Compare scores
env:
CLAIMED_SCORE: ${{ steps.extract.outputs.claimed_score }}
CLAIMED_RESEARCH_VERSION: ${{ steps.extract.outputs.research_version }}
run: |
# SAFE: All arithmetic using env vars
DIFF=$(echo "scale=2; if ($ACTUAL_SCORE - $CLAIMED_SCORE < 0) $CLAIMED_SCORE - $ACTUAL_SCORE else $ACTUAL_SCORE - $CLAIMED_SCORE" | bc)
echo "Claimed: $CLAIMED_SCORE (ruleset: $CLAIMED_RESEARCH_VERSION)"
echo "Actual: $ACTUAL_SCORE (ruleset: $ACTUAL_RESEARCH_VERSION)"
if (( $(echo "$DIFF > 2" | bc -l) )); then
echo "::error::Score mismatch: claimed $CLAIMED_SCORE, actual $ACTUAL_SCORE"
exit 1
fi
- name: Save validation results
if: always()
env:
CLAIMED_SCORE: ${{ steps.extract.outputs.claimed_score }}
ACTUAL_SCORE: ${{ env.ACTUAL_SCORE }}
REPO_NAME: ${{ steps.extract.outputs.repo_name }}
CLAIMED_RESEARCH_VERSION: ${{ steps.extract.outputs.research_version }}
ACTUAL_RESEARCH_VERSION: ${{ env.ACTUAL_RESEARCH_VERSION }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
mkdir -p /tmp/validation-data
jq -n \
--arg claimed "$CLAIMED_SCORE" \
--arg actual "$ACTUAL_SCORE" \
--arg repo_name "$REPO_NAME" \
--arg claimed_rv "$CLAIMED_RESEARCH_VERSION" \
--arg actual_rv "$ACTUAL_RESEARCH_VERSION" \
--arg pr_number "$PR_NUMBER" \
'{claimed_score: $claimed, actual_score: $actual, repo_name: $repo_name, claimed_research_version: $claimed_rv, actual_research_version: $actual_rv, pr_number: $pr_number}' \
> /tmp/validation-data/validation.json
- name: Upload validation results
if: always()
uses: actions/upload-artifact@v4
with:
name: leaderboard-validation
path: /tmp/validation-data/validation.json
retention-days: 1
# Job 2: Update leaderboard data (after merge to main, or manual trigger)
update:
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
permissions:
contents: write # Commit and push updated leaderboard data
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Generate leaderboard data
run: |
python3 scripts/generate-leaderboard-data.py
- name: Commit updated data
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [ -n "$(git status --porcelain docs/_data/leaderboard.json)" ]; then
git add docs/_data/leaderboard.json
git commit -m "chore: update leaderboard data [skip ci]"
git push
fi