Skip to content
Snippets Groups Projects
Commit 4ff1ea71 authored by Ivan Buntic's avatar Ivan Buntic Committed by Hamza Oukili
Browse files

Add solution checker, checks if the solution is updated with the exercise

parent 8850e387
No related branches found
No related tags found
1 merge request!221solution checker
Showing
with 7347 additions and 0 deletions
#!/bin/bash
#This is to be executed at the root folder of dumux-course, no input arguments required. The script creates patches for all exercises stored in the exercise/ folder and with a name starting with exercise-*
exerciseFolder=exercises/
# Iterate over all subdirectories
for exercise in $(find $exerciseFolder -maxdepth 1 -type d -name "exercise-*")
do
#crop path to get exercise name
exerciseName=${exercise%/} # this removes the trailing slash of the path - % removes smallest suffix matching the given pattern
exerciseName=${exercise#exercises/} # this remove the leading exercises/ of the path - # removes the smallest prefix matching the given pattern
#check if the exercise-folder exists. Should always exist, as we iterate over them
if [ ! -d exercises/$exerciseName ]
then
echo
echo "exercises/$exerciseName does NOT exist. Terminating."
exit 1
fi
echo "Generating diff for $exerciseName. Storing the patch file into patches/$exerciseName/$exerciseName.patch"
diff -ruN $exercise exercises/solution/$exerciseName > .patches/$exerciseName/$exerciseName.patch
done
#!/bin/bash
#This is to be executed at the root folder of dumux-course. Via the necessary option -x you name the exercise folder you would like to create a patch on. E.g.:
#./.create_single_patch.sh -x exercise-basic
#read in the parameter -x from the terminal
while getopts "x:" opt
do
case $opt in
x)
exerciseName=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
#if -x option is empty, throw an error
if [ -z "$exerciseName" ]
then
echo "ERROR: -x option must be set"
exit 1
fi
#flag for remembering if a patch should be created using git
shouldRunDiff=true
#check if the exercise-folder exists. Should always exist, as we iterate over them
if [ ! -d exercises/$exerciseName ]
then
echo "exercises/$exerciseName does NOT exist. Terminating."
exit 1
fi
#check if the respective solution to the exercise exists. If not, check if it is required. In any case where the answer is no, set the flag to false to only generate an empty patch
if [ ! -d exercises/solution/$exerciseName ]
then
echo "ERROR: exercises/$exerciseName exists but exercises/solution/$exerciseName does NOT exist."
shouldRunDiff=false
# Prompt the user for input - is this solution required?
while true; do
read -p "Does $exerciseName require a solution (y/n)?" yn
case $yn in
[Yy]* ) echo "Please create a solution to the exercise first."; exit;;
[Nn]* ) echo "Continuing..."; break;;
* ) echo "Please answer y or n.";;
esac
done
fi
#depending on the state of shouldRunDiff - create a patch using git diff or an empty patch
if [ $shouldRunDiff = true ]
then
echo "Generating diff for $exerciseName. Storing the patch file into .patches/$exerciseName/$exerciseName.patch"
diff -ruN exercises/$exerciseName exercises/solution/$exerciseName > .patches/$exerciseName/$exerciseName.patch
else
echo "Skipping diff generation for $exerciseName due to previous conflicts. Creating an empty patch..."
touch .patches/$exerciseName/$exerciseName.patch
fi
# Notes for developers
This README provides instructions on how to handle changing exercises and their respective solutions.
## Instructions
The Gitlab CI now also includes a check to ensure that the stored patches, located in .patches/, match the current exercises and their respective solutions. Each exercise has one associated patch that maps it to its respective solution. If you change an exercise without updating the patch, the CI will complain that the exercise and solution are out of sync. Keep in mind, that this is only a reminder to update the respective solution once you changed an exercise. Of course, you do not have to adapt the solution if it is not necessary. But in any case, whether changing the exercise, the solution or both, you always need to update the respective patch before pushing the remote repository.
To this end, there are two possible ways of generating the patch:
1. In the root folder of dumux-course, there is the hidden script `.create_all_patches.sh` (can show it in terminal via `ls -a`). You can simply run `./.create_all_patches.sh` which will create patches for all exercises. However, this might be prone to errors, if you changed other exercises too by accident.
2. In the root folder of dumux-course, there is another hidden script `.create_single_patch.sh` (can show it in terminal via `ls -a`). For this script, you need to provide a specific exercise name for which you want to generate the patch. As an example, for generating the patch for the exercise exercise-basic, you would need to run: `./.create_single_patch.sh -x exercise-basic` in the root folder of dumux-course.
TLDR: Before pushing to the remote repository, always generate a new patch, when changing an exercise and/or a solution by using one of the scripts.
stages:
- trigger pipelines
- deploy
- solution checker
variables:
IMAGE_REGISTRY_URL: $CI_REGISTRY/dumux-repositories/dumux-docker-ci
......@@ -60,3 +61,9 @@ pages:
- public
only:
- master
apply_patches:
stage: solution checker
image: $IMAGE_REGISTRY_URL/full:dune-$DUMUX_CI_DUNE_LATEST_RELEASE-gcc-ubuntu-20.04
script:
- sh .patches/apply_patches.sh
#!/bin/bash
exerciseFolder=exercises/
# Iterate over all subdirectories
for exercise in $(find $exerciseFolder -maxdepth 1 -type d -name "exercise-*")
do
#crop path to get exercise name
exerciseName=${exercise%/} # this removes the trailing slash of the path - % removes smallest suffix matching the given pattern
exerciseName=${exercise#exercises/} # this remove the leading exercises/ of the path - # removes the smallest prefix matching the given pattern
#for all exercises, apply the respective patches within the respective exercise folder
patch -s -p2 -d $exercise < .patches/$exerciseName/$exerciseName.patch
#for all exercises, apply the compare the created solution via patching and the already existing solution in the solution folder
diff -ruN $exercise exercises/solution/$exerciseName > $exercise/$exerciseName.patch
#if the patch file is empty, everything went ok and the stored patch matches the existing exercise and solution. If it was forgotten to update the patch, the created patch file for comparing the solutions will not be empty.
if [ ! -s $exercise/$exerciseName.patch ]
then
echo "The solution for $exerciseName seems to be up to date."
else
echo "You forgot to update the exercise or the solution for $exerciseName!"
exit
fi
done
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
diff -ruN exercises/exercise-dunemodule/README.md exercises/solution/exercise-dunemodule/README.md
--- exercises/exercise-dunemodule/README.md 2023-06-01 14:31:33.149062999 +0200
+++ exercises/solution/exercise-dunemodule/README.md 1970-01-01 01:00:00.000000000 +0100
@@ -1,108 +0,0 @@
-# Exercise New Dune Module (DuMuX course)
-
-This exercise describes how to create a new DuMuX module
-and how to create a corresponding GitLab project.
-
-This is the suggested
-workflow to develop code on top of DuMuX.
-
-### Task 1: Create new dune module
-<hr>
-
-* Execute the following command (bash environment) in the top-folder, i.e. above the dumux folder
-
-```bash
-./dune-common/bin/duneproject
-```
-
-* Follow the introductions and specify
- * as name of the new module: `dumux-example`
- * as module dependencies: `dumux`
- * a version at your choice (the version of your project, not of dumux.)
- * your email address
-
-<br><br><br>
-### Task 2: Rerun dunecontrol to configure your new project
-<hr>
-
-The following command will configure your new module
-
-```bash
-./dune-common/bin/dunecontrol --opts=<opts file> --only=dumux-example all
-```
-
-You need to run this command in the folder with content dumux, dumux-course, dune-common, dune-geometry, dune-grid, dune-istl, etc. `<opts file>` needs to be replaced (please replace the angle brackets also) by an options file, e.g., by `./dumux/cmake.opts`. Have a look at the comments in this file to see how you can adapt it to your needs.
-
-<br><br><br>
-### Task 3: Create a new test case within your new DuMuX module
-<hr>
-
-* Create a new folder (in your module folder), e.g., `appl`
-
-```bash
-mkdir appl
-```
-
-* Copy some test case from the dumux module, e.g., test_1p from test/porousmediumflow/1p/compressible/stationary in your new folder (e.g., `appl`)
-* Copy the problem file, spatialparams file, properties file, cc source file and input file
-
-* Adjust the CMakeLists.txt file within the dumux-example (or your module name)-folder to include your new subdirectory
-
-* Add a new CMakeLists.txt in the folder `appl` with the content
-
-```cmake
-# add a new finite volume 1p test
-dumux_add_test(NAME test_1p_compressible_stationary_tpfa
- SOURCES main.cc
- COMPILE_DEFINITIONS TYPETAG=OnePCompressibleTpfa
- CMD_ARGS params.input)
-
-# add a symlink for the input file
-dune_symlink_to_source_files(FILES "params.input")
-
-```
-
-* Reconfigure your module by running in the topmost directory of your new module
-
-```bash
-cmake build-cmake
-```
-
-* Build and execute the test problem
-
-```bash
-cd build-cmake
-make build_tests
-cd appl
-./test_1p_compressible_stationary_tpfa params.input
-```
-
-<br><br><br>
-### Task 4: Create a new GitLab project
-<hr>
-
-* Login with your username and password at https://git.iws.uni-stuttgart.de/
-
-Note: If you don't have an account create one. We allow anyone to host repositories
-on our GitLab instance as long as it is DuMuX related. If you created a GitLab account recently or just now, one of
-the administrators first has to increase the number of permitted personal projects for your account before you can create
-your own project.
-
-* Click the **New project** button.
-
-* Then choose to **Create blank project**.
-
-* Specify your project name, untick the box *Initialize repository with a README* and click the **Create project** button.
-
-* Follow the given instructions for an *existing folder*.
-
-Hint: if you have not done so already, be sure to inform your computer of your git account with the following commands:
-```bash
-git config --global user.name "FIRST_NAME LAST_NAME"
-git config --global user.email "YOUR_EMAIL_ADDRESS"
-```
-
-**Important**: Before executing the `git add .` command, you should add your cmake build folder to `.gitignore`.
-The easiest way to do so is to copy the `.gitignore` file from the dumux module into your module path. If everything
-worked, executing `git status` should not show `build-cmake` anymore. Never put your executables or other build files
-under version control. Only source files (`*.hh`, `*.cc`, `*.input`, `CMakeLists.txt`) should be under version control.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment