This is basically what CI/CD pipelines do.
Compile the code, run tests, run static analysis. If results pass, submit the code. If results fail, reject it with an explanation.
Idk the details of how you'd implement this for a class, without letting everyone see eachother's completed work, but I'm sure it could be done.