Skip to content

Commit

Permalink
Add support for unziped version of autograder
Browse files Browse the repository at this point in the history
* autograder folder has priority over ziped version
  • Loading branch information
ksimuk committed Oct 19, 2023
1 parent ca37951 commit 5d16184
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func main() {
args := os.Args[1:]
runSetup := slices.Contains(args, "run-setup")
extendedLogs := slices.Contains(args, "logs")
debugFlag := slices.Contains(args, "debug")

if checkRoot() {
url := os.Getenv("CODIO_AUTOGRADE_V2_URL")
Expand All @@ -45,7 +46,7 @@ func main() {
executeSetupScript()
}
prepareSubmission()
execute()
execute(debugFlag)
submitResults(url, extendedLogs)
cleanup()
} else {
Expand Down Expand Up @@ -206,7 +207,7 @@ func prepareSubmission() {
_ = os.WriteFile("/autograder/submission_metadata.json", file, 0644)
}

func execute() {
func execute(debugFlag bool) {
log.Println("Copy run_autograde")
_, err := copy("/autograder/source/run_autograder", "/autograder/run_autograder")
if (err != nil) && !errors.Is(err, os.ErrNotExist) {
Expand All @@ -229,9 +230,11 @@ func execute() {
autograde.Start()
autograde.Wait()
log.Printf("Exite Code: %d\n", autograde.ProcessState.ExitCode())
// uncomment to debug output
// stdpoutFile, _ := os.ReadFile("/autograder/results/stdout")
// fmt.Printf("OUTPUT:\n%s\n", stdpoutFile)
if debugFlag {
stdpoutFile, _ := os.ReadFile("/autograder/results/stdout")
fmt.Printf("OUTPUT:\n%s\n", stdpoutFile)
}

if autograde.ProcessState.ExitCode() != 0 {
panic(fmt.Sprintf("run_autograde failed with %d", autograde.ProcessState.ExitCode()))
}
Expand Down Expand Up @@ -293,19 +296,57 @@ func checkFileExists(name string) (bool, error) {
return false, err
}

func findAutograder() (string, error) {
exist, err := checkFileExists("/home/codio/workspace/.guides/secure/autograder")
if err != nil {
return "", err
}
if exist {
return "/home/codio/workspace/.guides/secure/autograder", nil
}

exist, err = checkFileExists("/home/codio/workspace/.guides/autograder")
if err != nil {
return "", err
}
if exist {
return "/home/codio/workspace/.guides/autograder", nil
}

exist, err = checkFileExists("/home/codio/workspace/.guides/secure/autograder.zip")
if err != nil {
return "", err
}
if exist {
return "/home/codio/workspace/.guides/secure/autograder.zip", nil
}

exist, err = checkFileExists("/home/codio/workspace/.guides/autograder.zip")
if err != nil {
return "", err
}
if exist {
return "/home/codio/workspace/.guides/autograder.zip", nil
}
return "", errors.New("autograder not found")
}

func unzip(destination string) error {
autograderFile := "/home/codio/workspace/.guides/autograder.zip"
exist, err := checkFileExists(autograderFile)
// check unzip folder exists
autograder, err := findAutograder()
check(err)
if !exist {
autograderFile = "/home/codio/workspace/.guides/secure/autograder.zip"
exist, err = checkFileExists(autograderFile)
log.Printf("Using %s autograder", autograder)

if !strings.HasSuffix(autograder, ".zip") {
// copy autograder files
_, err := exec.Command("rsync", "-av", "--exclude", "autograder.zip", "--exclude", "gradescope_wrapper",
"--exclude", ".guides", "--exclude", ".codio", "--exclude", ".settings",
fmt.Sprintf("%s/", autograder), destination).Output()
check(err)
if !exist {
panic("autograder.zip not found in .guides/ or .guides/secure")
}
return nil
}

autograderFile := autograder
archive, err := zip.OpenReader(autograderFile)
if err != nil {
panic(err)
Expand Down

0 comments on commit 5d16184

Please sign in to comment.