generated from fresh-hduhelper/GoPracticeGin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
102 lines (80 loc) · 1.62 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"log"
"os"
"os/exec"
)
var workflow = `name: GitHub Classroom Workflow
on: [push]
permissions:
checks: write
actions: read
contents: read
jobs:
build:
name: Autograding
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3.2.1
with:
go-version: 1.19
- name: Collect Dependencies
run: pip3 install requests
- name: Build
run: |
- name: Run after build
run:
- uses: education/autograding@v1
`
func main() {
//TODO:
// 1. hash 所有文件夹及其内容,有修改的话,在启动本地检查的时候再检查
// 2. go run build.go 时能够覆写 workflow
//
}
var checkScriptContent = `//go:build check
// +build check
package main
func main() {
}
`
func genCheckScript() {
checkScript, err := os.Create("check.go")
if err != nil {
log.Fatal(err)
}
_, err = checkScript.Write([]byte(checkScriptContent))
if err != nil {
log.Fatal(err)
}
}
type CommandBatch []*exec.Cmd
func (cb *CommandBatch) lazyInit() {
if cb == nil {
*cb = make([]*exec.Cmd, 16)
}
}
func (cb *CommandBatch) AddBatch(cmdBatch ...*exec.Cmd) {
cb.lazyInit()
*cb = append(*cb, cmdBatch...)
}
func (cb *CommandBatch) ExecAll() {
if cb == nil || len(*cb) <= 0 {
return
}
for _, cmd := range *cb {
cmd.Start()
}
}
func updateWorkflowOverwrite() {
}
func updateWorkflowPush() {
var cmds CommandBatch
cmds.AddBatch(
exec.Command("git", "add", ".github/workflows/classroom.yml"),
exec.Command("git", "commit", "-m", "Update autograding"),
exec.Command("git", "push"),
)
cmds.ExecAll()
}