feat: show version
All checks were successful
build / build (push) Successful in 1m17s
build / trigger-build-image (push) Successful in 5s

This commit is contained in:
张泊明518370910136 2024-10-01 00:52:19 -04:00
parent 43a799e958
commit 198d329c8e
GPG Key ID: D47306D7062CDA9D
4 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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)