diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 6eac295..18686fa 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -38,6 +38,8 @@ jobs: run: make lint - name: Build run: make build + - name: Version + run: ./build/joj3 -v - name: Test run: | make prepare-test diff --git a/cmd/healthcheck/main.go b/cmd/healthcheck/main.go index 5951848..272b634 100644 --- a/cmd/healthcheck/main.go +++ b/cmd/healthcheck/main.go @@ -35,9 +35,12 @@ func setupSlog() { slog.SetDefault(logger) } +var Version string + // Generally, err is used for runtime errors, and checkRes is used for the result of the checks. func main() { var gitWhitelist, metaFile, releaseTags []string + showVersion := flag.Bool("v", false, "print current version") rootDir := flag.String("root", "", "") repo := flag.String("repo", "", "") localList := flag.String("localList", "", "") @@ -50,6 +53,10 @@ func main() { parseMultiValueFlag(&metaFile, "meta", "") parseMultiValueFlag(&releaseTags, "releaseTags", "") flag.Parse() + if *showVersion { + fmt.Println(Version) + return + } setupSlog() var err error err = healthcheck.RepoSize() diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index a83f1b7..24f65ff 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "flag" + "fmt" "log/slog" "os" @@ -92,16 +93,23 @@ func outputResult(outputPath string, results []stage.StageResult) error { var ( metaConfPath string msg string + showVersion *bool + Version string ) func init() { flag.StringVar(&metaConfPath, "meta-conf", "meta-conf.toml", "meta config file path") flag.StringVar(&msg, "msg", "", "message to trigger the running, leave empty to use git commit message on HEAD") + showVersion = flag.Bool("v", false, "print current version") } func mainImpl() error { setupSlog(int(slog.LevelInfo)) // before conf is loaded flag.Parse() + if *showVersion { + fmt.Println(Version) + return nil + } if msg == "" { var err error msg, err = getCommitMsg() diff --git a/cmd/sample/main.go b/cmd/sample/main.go index 16d1202..8e0713f 100644 --- a/cmd/sample/main.go +++ b/cmd/sample/main.go @@ -9,9 +9,16 @@ import ( "github.com/joint-online-judge/JOJ3/pkg/sample" ) +var Version string + func main() { + showVersion := flag.Bool("v", false, "print current version") score := flag.Int("score", 0, "score") flag.Parse() + if *showVersion { + fmt.Println(Version) + return + } res, err := sample.Run(sample.Conf{Score: *score}) if err != nil { fmt.Fprint(os.Stderr, err)