forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 234
93 lines (84 loc) · 2.92 KB
/
Copy pathagent_governance.yml
File metadata and controls
93 lines (84 loc) · 2.92 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
name: Agent Governance
on:
pull_request:
types: [opened, synchronize, reopened, edited, ready_for_review]
permissions:
contents: read
pull-requests: read
issues: write
jobs:
governance:
name: Governance checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Run ABACUS governance checker
id: governance
run: |
set +e
base_sha="${{ github.event.pull_request.base.sha }}"
head_sha="${{ github.event.pull_request.head.sha }}"
merge_base="$(git merge-base "$base_sha" "$head_sha")"
merge_base_status=$?
if [ "$merge_base_status" -ne 0 ]; then
{
echo "## Agent Governance Check"
echo
echo "Failed to compute the pull request merge base."
} > agent_governance_summary.md
exit "$merge_base_status"
fi
python3 tools/03_code_analysis/agent_governance_check.py \
--base "$merge_base" \
--head "$head_sha" \
--event-path "$GITHUB_EVENT_PATH" \
--format markdown | tee agent_governance_summary.md
status=${PIPESTATUS[0]}
if [ ! -s agent_governance_summary.md ]; then
{
echo "## Agent Governance Check"
echo
echo "Checker failed before producing a summary."
} > agent_governance_summary.md
fi
exit "$status"
- name: Publish governance summary
if: always()
run: |
cat agent_governance_summary.md >> "$GITHUB_STEP_SUMMARY"
- name: Comment governance warnings
if: >-
always() &&
github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if ! grep -qi '^| warning |' agent_governance_summary.md; then
exit 0
fi
marker='<!-- agent-governance-warning -->'
body_file="$(mktemp)"
json_file="$(mktemp)"
{
echo "$marker"
echo
cat agent_governance_summary.md
} > "$body_file"
jq -Rs '{body: .}' < "$body_file" > "$json_file"
existing_comment_id="$(gh api --paginate \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
--jq ".[] | select(.body | contains(\"${marker}\")) | .id" \
| head -n 1)"
if [ -n "$existing_comment_id" ]; then
gh api --method PATCH \
"repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" \
--input "$json_file"
else
gh api --method POST \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
--input "$json_file"
fi