-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (97 loc) · 3.93 KB
/
record-run.yml
File metadata and controls
112 lines (97 loc) · 3.93 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
name: Record pipeline run
on:
pull_request:
types: [closed]
jobs:
record:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Locate and download pipeline artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
shell: bash
run: |
set -euo pipefail
python <<'PY'
import json
import os
import urllib.request
from pathlib import Path
token = os.environ["GH_TOKEN"]
repository = os.environ["REPOSITORY"]
head_sha = os.environ["HEAD_SHA"]
def request(path: str) -> dict:
req = urllib.request.Request(
f"https://api.github.com{path}",
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
},
)
with urllib.request.urlopen(req, timeout=60) as resp:
return json.loads(resp.read().decode("utf-8"))
runs = request(f"/repos/{repository}/actions/runs?head_sha={head_sha}&per_page=30")
workflow_runs = runs.get("workflow_runs", [])
target_run_id = None
for run in workflow_runs:
run_id = run.get("id")
if not run_id:
continue
artifacts = request(f"/repos/{repository}/actions/runs/{run_id}/artifacts")
names = {artifact.get("name", "") for artifact in artifacts.get("artifacts", [])}
if "coordinator-report" in names:
target_run_id = str(run_id)
break
if not target_run_id:
print("No prior workflow run for this PR head SHA published a coordinator-report artifact.")
raise SystemExit(0)
Path(".pipeline_run_id").write_text(target_run_id, encoding="utf-8")
PY
if [[ -f .pipeline_run_id ]]; then
PIPELINE_RUN_ID="$(cat .pipeline_run_id)"
gh run download "$PIPELINE_RUN_ID" -R "$REPOSITORY" -n coordinator-report -D .
gh run download "$PIPELINE_RUN_ID" -R "$REPOSITORY" -n verify-feedback -D . || true
fi
- name: Stop early when no coordinator report is available
if: ${{ hashFiles('coordinator-report.md') == '' }}
run: |
echo "Skipping scorebook update: no real coordinator-report.md artifact was available for this merged PR."
echo "This is expected until a manual or automated review executor uploads pipeline artifacts for the PR head SHA."
- name: Record run in scorebook
if: ${{ hashFiles('coordinator-report.md') != '' }}
shell: bash
run: |
set -euo pipefail
args=(
--pr "${{ github.event.pull_request.number }}"
--coordinator-report coordinator-report.md
)
if [[ -f verify-feedback.json ]]; then
args+=(--verify-feedback verify-feedback.json)
fi
python scripts/record_run.py "${args[@]}"
- name: Commit updated scorebook
if: ${{ hashFiles('coordinator-report.md') != '' }}
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add data/pipeline-runs.jsonl
git diff --cached --quiet || git commit -m "chore: record pipeline scorebook entry"
git push