Skip to content

chore: add unique IDs to new code cells in the training notebook #3

chore: add unique IDs to new code cells in the training notebook

chore: add unique IDs to new code cells in the training notebook #3

name: Protect Main-Only Files
on:
push:
pull_request:
jobs:
guard:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Block protected files outside main
env:
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
BEFORE_SHA: ${{ github.event.before }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -eu
protected_files='^(main\.py|main\.ipynb)$'
branch_name="$REF_NAME"
if [ "$EVENT_NAME" = "pull_request" ]; then
branch_name="$HEAD_REF"
fi
if [ "$branch_name" = "main" ]; then
echo "Protected files can be changed on main."
exit 0
fi
if [ "$EVENT_NAME" = "pull_request" ]; then
diff_base="$BASE_SHA"
diff_head="$PR_HEAD_SHA"
elif [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
diff_base="$(git rev-list --max-parents=0 HEAD)"
diff_head="HEAD"
else
diff_base="$BEFORE_SHA"
diff_head="HEAD"
fi
changed_files="$(git diff --name-only "$diff_base" "$diff_head")"
echo "Branch: $branch_name"
echo "Changed files:"
printf '%s\n' "$changed_files"
blocked_files="$(printf '%s\n' "$changed_files" | grep -E "$protected_files" || true)"
if [ -n "$blocked_files" ]; then
echo "::error::These files may only be changed on main:"
printf '%s\n' "$blocked_files"
exit 1
fi