Skip to content

Commit 39b1f34

Browse files
committed
pull_request.yml: Check total reward weight change
Make sure total reward weight doesn't change unless explicitly allowed by adding [allow-total-reward-weight-change] to a commit message Example outputs: # Change disallowed ERROR: Total reward weight diff for configs/DevNet/approved-sv-id-values.yaml is: 2. The change is not allowed. Add [allow-total-reward-weight-change] to the commit message to override. INFO: Total reward weight diff for configs/MainNet/approved-sv-id-values.yaml is: 0. INFO: Total reward weight diff for configs/TestNet/approved-sv-id-values.yaml is: 0. # Change allowed INFO: Total reward weight diff for configs/DevNet/approved-sv-id-values.yaml is: 2. The change is allowed. INFO: Total reward weight diff for configs/MainNet/approved-sv-id-values.yaml is: 0. INFO: Total reward weight diff for configs/TestNet/approved-sv-id-values.yaml is: 0.
1 parent 1ade2bb commit 39b1f34

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,40 @@ jobs:
2828
steps:
2929
- name: Checkout code
3030
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0 # Default is 1. We set it as 0 to get access to the target branch
3133

3234
- name: Validate JSON and YAML files
3335
uses: GrantBirki/json-yaml-validate@d7814b94473939c1daaca2c96131b891d4703a3c # v2.7.1
3436
with:
3537
base_dir: configs
38+
39+
- name: Make sure total sum of reward weights doesn't change unless explicitly allowed
40+
run: |
41+
mark='[allow-total-reward-weight-change]'
42+
allow_total_reward_weight_change=$(echo "$COMMIT_MESSAGE" | grep -qF "$mark" && echo "true" || echo "false")
43+
exit_code=0
44+
45+
for f in configs/*/approved-sv-id-values.yaml; do
46+
content_orig=$(git show "$TARGET_BRANCH:$f")
47+
content_new=$(cat "$f")
48+
49+
total_weight_orig=$(echo "$content_orig" | yq '.approvedSvIdentities[].rewardWeightBps as $n ireduce(0; . + $n)')
50+
total_weight_new=$(echo "$content_new" | yq '.approvedSvIdentities[].rewardWeightBps as $n ireduce(0; . + $n)')
51+
52+
total_weight_diff=$((total_weight_new - total_weight_orig))
53+
54+
if [[ "$allow_total_reward_weight_change" == "true" ]]; then
55+
echo "INFO: Total reward weight diff for $f is: $total_weight_diff. The change is allowed."
56+
elif [[ "$total_weight_diff" == "0" ]]; then
57+
echo "INFO: Total reward weight diff for $f is: $total_weight_diff."
58+
else
59+
echo "ERROR: Total reward weight diff for $f is: $total_weight_diff. The change is not allowed. Add $mark to the commit message to override." >&2
60+
exit_code=1
61+
fi
62+
done
63+
64+
exit "$exit_code"
65+
env:
66+
TARGET_BRANCH: "origin/${{ github.base_ref }}"
67+
COMMIT_MESSAGE: ${{ github.event.pull_request.head_commit.message }}

0 commit comments

Comments
 (0)