Skip to content

Swapping to manhattan heuristic by default A1 #121

Swapping to manhattan heuristic by default A1

Swapping to manhattan heuristic by default A1 #121

name: Generate Assignment Branches
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: write # 👈 allows commits and pushes using GITHUB_TOKEN
jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # So we can push branches
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Set up Git user
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Generate branches for each assignment
run: |
# Helper: Remove answer regions above a certain assignment number
remove_answers() {
local max=$1
echo "Removing regions with A > $max"
for f in $(find . -type f -name "*.py"); do
echo "Processing $f..."
awk -v max="$max" '
BEGIN { skip=0; indent="" }
# Match start of ANSWER region (allow leading spaces)
/^ *# *region +ANSWER +A[0-9]+:/ {
match($0, /^( *)/, m)
indent = m[1] # capture indentation
match($0, /A([0-9]+)/, m)
if (m[1] > max) {
skip = 1
print indent "pass" # insert placeholder
next # skip printing region line
}
}
# Match end of region
/^ *# *endregion/ {
if (skip) { skip = 0; next } # skip the end line entirely
}
# Print everything else if not skipping
skip == 0 { print }
' "$f" > "$f.tmp"
if [ -s "$f.tmp" ]; then
mv "$f.tmp" "$f"
else
echo "⚠️ Skipping $f (produced empty output)"
rm "$f.tmp"
fi
done
}
# Generate branches a1-a4 containing only the python/ and example_problems/ folders
for i in 0 1 2 3 4; do
j=$((i + 1))
branch="a${j}"
echo "=== Generating branch $branch ==="
# Reset to main
git checkout main -f
# Clean working directory except for python/ and example_problems/
echo "Keeping only python/ and example_problems/ directories..."
find . -mindepth 1 -maxdepth 1 \
! -name 'python' \
! -name 'example_problems' \
! -name '.git' \
-exec rm -rf {} +
# Process only files in the kept folders
for dir in python example_problems; do
if [ -d "$dir" ]; then
remove_answers "$i"
fi
done
# Create/update branch
git checkout -B "$branch"
git add -A
git commit -m "Generated $branch with only python/ and example_problems/ (answers up to A${j})" || echo "No changes to commit"
git push origin "$branch" --force
done