Skip to content

pull_request.yml: Check total reward weight change #23

pull_request.yml: Check total reward weight change

pull_request.yml: Check total reward weight change #23

Workflow file for this run

name: Pull Request
on:
pull_request:
branches:
- main
paths:
- '**.json'
- '**.yaml'
- '**.yml'
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
jobs:
validate:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Default is 1. We set it as 0 to get access to the target branch
- name: Validate JSON and YAML files
uses: GrantBirki/json-yaml-validate@d7814b94473939c1daaca2c96131b891d4703a3c # v2.7.1
with:
base_dir: configs
- name: Make sure total sum of reward weights doesn't change unless explicitly allowed
run: |
echo "${{ toJSON(github.event) }}"
mark='[allow-total-reward-weight-change]'
allow_total_reward_weight_change=$(echo "$COMMIT_MESSAGE" | grep -qF "$mark" && echo "true" || echo "false")
exit_code=0
for f in configs/*/approved-sv-id-values.yaml; do
content_orig=$(git show "$TARGET_BRANCH:$f")
content_new=$(cat "$f")
total_weight_orig=$(echo "$content_orig" | yq '.approvedSvIdentities[].rewardWeightBps as $n ireduce(0; . + $n)')
total_weight_new=$(echo "$content_new" | yq '.approvedSvIdentities[].rewardWeightBps as $n ireduce(0; . + $n)')
total_weight_diff=$((total_weight_new - total_weight_orig))
if [[ "$allow_total_reward_weight_change" == "true" ]]; then
echo "INFO: Total reward weight diff for $f is: $total_weight_diff. The change is allowed."
elif [[ "$total_weight_diff" == "0" ]]; then
echo "INFO: Total reward weight diff for $f is: $total_weight_diff."
else
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
exit_code=1
fi
done
exit "$exit_code"
env:
TARGET_BRANCH: "origin/${{ github.base_ref }}"
COMMIT_MESSAGE: ${{ github.event.pull_request.head_commit.message }}