Template for grader image builders for c/c++ assignments
- To provide a template for creating a grader image for c/c++ assignments
- To automate the programming assignment grading process so that educators can focus more on teaching
- Fork this repository.
- Go to the
Settingstab of your repository and click onActionson the left sidebar.- Click on
Generaland go toWorkflow permissions. - Choose
Read and write permissionsand Save.
- Click on
- Edit
tests/test_build.pyif you need to customize build checks. - Customize
tests/test_dynamic.candtests/test_dynamic.pyto define the expected test cases. - Push to GitHub :
build-image.ymlbuilds your image and pushes to GHCR (GitHub Container Registry).
src_file_path,obj_file_path, andmy_src_folderfixtures will be available if your test script in thetests/folder importspytest(seeconftest.py).- Currently
requirements.txtis for documentation purpose. If you want to install additional Python packages, add them torequirements.txtand uncomment theCOPYandRUNlines in theDockerfile.
build-image.yml: Builds and pushes a multi-arch grader image to GHCR.- Uses GHCR for privacy and GitHub integration—swap to Docker Hub by updating
registryandtagsif preferred. - Requires
Dockerfilein repo root.
- Builds a lightweight grader image with
pytest. - Currently
requirements.txtis for documentation purpose only.- If you want to install additional python packages:
- add them to
requirements.txt, - and uncomment the
COPYandRUNlines in theDockerfile. - Please test whether
pythoncan import the packages you added.
- add them to
- If you want to install additional python packages:
- Customize
CMDto run your tests (e.g.,python3 -m pytest tests/).
This is the grader template — the instructor-facing half of a two-repo pattern:
- This repo (grader) — you customize the test files, push, and GitHub Actions builds a Docker image containing your tests. The image is published to GHCR.
- cpp-hw-template (student-facing) — contains
src/main.c,include/main.h, and aclassroom.ymlworkflow. When a student pushes,classroom.ymlpulls your grader image and runs the tests.
This repo uses secrets.GITHUB_TOKEN (automatically provided by GitHub Actions) to:
- Log in to GHCR and push the grader Docker image
- Pass as
GIT_AUTH_TOKENduring Docker build for cloning dependencies
No manual token setup is needed, but you must enable write access:
Settings > Actions > General > Workflow permissions > "Read and write permissions"
Without this, the Docker image push will fail with a 403 error.
| File | What to Change |
|---|---|
tests/test_build.py |
Usually no changes needed (checks if student code compiles) |
tests/test_style.py |
Usually no changes needed (checks clang-format style) |
tests/test_commit_msg.py |
Usually no changes needed (validates commit message quality) |
tests/test_dynamic.py |
Customize to define which C test functions to run |
tests/test_dynamic.c |
Write the actual C test cases for the assignment |
CMakeLists.txt |
Update if the assignment uses different source file names |
tests/conftest.py |
Usually no changes needed (provides path fixtures) |
After your grader image builds (check the Actions tab), note the image URL:
ghcr.io/{your-username}/{this-repo-name}:latest
In the student homework repository, set this as a repository variable:
Settings > Secrets and variables > Actions > Variables
Variable name: CPP_GRADER_??? (replace ??? with the assignment identifier, e.g., CPP_GRADER_201)
Value: ghcr.io/{your-username}/{this-repo-name}:latest
The following secrets are set on the homework template side (or as organization secrets):
A GitHub fine-grained Personal Access Token that allows the homework repo's workflow to pull the grader image from GHCR.
- Go to GitHub > Settings (user) > Developer settings > Personal access tokens > Fine-grained tokens.
- Click Generate new token.
- Set the following permission:
| Permission | Access | Purpose |
|---|---|---|
| Packages | Read | Pull grader Docker images from GHCR |
- Save as a secret named
CR_PATin the homework repo or organization.
GITHUB_TOKENcannot be used for this because it is scoped to the current repo and cannot read packages from a different repo.
These power the AI tutor feedback step in the homework repo. At least one must be set.
| Secret Name | Service | Where to Obtain |
|---|---|---|
CLAUDE_API_KEY |
Anthropic Claude | https://console.anthropic.com/ |
GOOGLE_API_KEY |
Google Gemini | https://aistudio.google.com/ |
XAI_API_KEY |
xAI Grok | https://console.x.ai/ |
NVIDIA_NIM_API_KEY |
NVIDIA NIM | https://build.nvidia.com/ |
PERPLEXITY_API_KEY |
Perplexity | https://perplexity.ai/settings/api |
Specifies the preferred LLM model. If unset, the AI tutor defaults to Gemini or uses whichever single key is available.
- Copyright © 2025 Kangwon Lee. Registered at the Korea Copyright Commission under #C-2025-027967 (as one of derivative works from original registration #C-2025-016393).
- Various LLMs and AI tools helped implementing the templates for this assignment.
- Google Gemini Flash / Pro 2.5
- xAI Grok3
- Perplexity Sonar
- Claude.ai 4.0 Sonnet