feat(cmd/joj3): store output path to env var [force build]
This commit is contained in:
		
							parent
							
								
									0390e4c4b3
								
							
						
					
					
						commit
						4e84031e84
					
				
							
								
								
									
										3
									
								
								cmd/joj3/env/env.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								cmd/joj3/env/env.go
									
									
									
									
										vendored
									
									
								
							|  | @ -12,6 +12,7 @@ const ( | ||||||
| 	RunID              = "JOJ3_RUN_ID" | 	RunID              = "JOJ3_RUN_ID" | ||||||
| 	CommitMsg          = "JOJ3_COMMIT_MSG" | 	CommitMsg          = "JOJ3_COMMIT_MSG" | ||||||
| 	ForceQuitStageName = "JOJ3_FORCE_QUIT_STAGE_NAME" | 	ForceQuitStageName = "JOJ3_FORCE_QUIT_STAGE_NAME" | ||||||
|  | 	OutputPath         = "JOJ3_OUTPUT_PATH" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Attribute struct { | type Attribute struct { | ||||||
|  | @ -28,6 +29,7 @@ type Attribute struct { | ||||||
| 	ActorName          string | 	ActorName          string | ||||||
| 	ActorID            string | 	ActorID            string | ||||||
| 	ForceQuitStageName string | 	ForceQuitStageName string | ||||||
|  | 	OutputPath         string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var Attr Attribute | var Attr Attribute | ||||||
|  | @ -57,4 +59,5 @@ func Set() { | ||||||
| 	os.Setenv(RunID, Attr.RunID) | 	os.Setenv(RunID, Attr.RunID) | ||||||
| 	os.Setenv(CommitMsg, Attr.CommitMsg) | 	os.Setenv(CommitMsg, Attr.CommitMsg) | ||||||
| 	os.Setenv(ForceQuitStageName, Attr.ForceQuitStageName) | 	os.Setenv(ForceQuitStageName, Attr.ForceQuitStageName) | ||||||
|  | 	os.Setenv(OutputPath, Attr.OutputPath) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"github.com/joint-online-judge/JOJ3/cmd/joj3/env" | 	"github.com/joint-online-judge/JOJ3/cmd/joj3/env" | ||||||
| 	"github.com/joint-online-judge/JOJ3/cmd/joj3/stage" | 	"github.com/joint-online-judge/JOJ3/cmd/joj3/stage" | ||||||
| 	"github.com/joint-online-judge/JOJ3/internal/conf" | 	internalConf "github.com/joint-online-judge/JOJ3/internal/conf" | ||||||
| 	internalStage "github.com/joint-online-judge/JOJ3/internal/stage" | 	internalStage "github.com/joint-online-judge/JOJ3/internal/stage" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -18,7 +18,7 @@ var ( | ||||||
| 	confFileName         string | 	confFileName         string | ||||||
| 	fallbackConfFileName string | 	fallbackConfFileName string | ||||||
| 	tag                  string | 	tag                  string | ||||||
| 	showVersion          *bool | 	printVersion         *bool | ||||||
| 	Version              string = "debug" | 	Version              string = "debug" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -27,18 +27,18 @@ func init() { | ||||||
| 	flag.StringVar(&confFileName, "conf-name", "conf.json", "filename for config files") | 	flag.StringVar(&confFileName, "conf-name", "conf.json", "filename for config files") | ||||||
| 	flag.StringVar(&fallbackConfFileName, "fallback-conf-name", "", "filename for the fallback config file in conf-root, leave empty to use conf-name") | 	flag.StringVar(&fallbackConfFileName, "fallback-conf-name", "", "filename for the fallback config file in conf-root, leave empty to use conf-name") | ||||||
| 	flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, should equal to the scope in msg") | 	flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, should equal to the scope in msg") | ||||||
| 	showVersion = flag.Bool("version", false, "print current version") | 	printVersion = flag.Bool("version", false, "print current version") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func mainImpl() (err error) { | func mainImpl() (err error) { | ||||||
| 	confObj := new(conf.Conf) | 	conf := new(internalConf.Conf) | ||||||
| 
 | 
 | ||||||
| 	logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) | 	logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) | ||||||
| 	slog.SetDefault(logger) | 	slog.SetDefault(logger) | ||||||
| 
 | 
 | ||||||
| 	// parse flag & conf file
 | 	// parse flag & conf file
 | ||||||
| 	flag.Parse() | 	flag.Parse() | ||||||
| 	if *showVersion { | 	if *printVersion { | ||||||
| 		fmt.Println(Version) | 		fmt.Println(Version) | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  | @ -46,49 +46,50 @@ func mainImpl() (err error) { | ||||||
| 		fallbackConfFileName = confFileName | 		fallbackConfFileName = confFileName | ||||||
| 	} | 	} | ||||||
| 	slog.Info("start joj3", "version", Version) | 	slog.Info("start joj3", "version", Version) | ||||||
| 	commitMsg, err := conf.GetCommitMsg() | 	commitMsg, err := internalConf.GetCommitMsg() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("get commit msg", "error", err) | 		slog.Error("get commit msg", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	env.Attr.CommitMsg = commitMsg | 	env.Attr.CommitMsg = commitMsg | ||||||
| 	confPath, confStat, conventionalCommit, err := conf.GetConfPath( | 	confPath, confStat, conventionalCommit, err := internalConf.GetConfPath( | ||||||
| 		confFileRoot, confFileName, fallbackConfFileName, commitMsg, tag) | 		confFileRoot, confFileName, fallbackConfFileName, commitMsg, tag) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("get conf path", "error", err) | 		slog.Error("get conf path", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	slog.Info("try to load conf", "path", confPath) | 	slog.Info("try to load conf", "path", confPath) | ||||||
| 	confObj, err = conf.ParseConfFile(confPath) | 	conf, err = internalConf.ParseConfFile(confPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("parse conf", "error", err) | 		slog.Error("parse conf", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	env.Attr.ConfName = confObj.Name | 	env.Attr.ConfName = conf.Name | ||||||
| 	slog.Debug("conf loaded", "conf", confObj, "joj3 version", Version) | 	env.Attr.OutputPath = conf.Stage.OutputPath | ||||||
| 	if err := setupSlog(confObj); err != nil { | 	slog.Debug("conf loaded", "conf", conf, "joj3 version", Version) | ||||||
|  | 	if err := setupSlog(conf); err != nil { | ||||||
| 		slog.Error("setup slog", "error", err) | 		slog.Error("setup slog", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// log conf file info
 | 	// log conf file info
 | ||||||
| 	sha256, err := conf.GetSHA256(confPath) | 	confSHA256, err := internalConf.GetSHA256(confPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("get sha256", "error", err) | 		slog.Error("get sha256", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	slog.Info("conf info", "sha256", sha256, "modTime", confStat.ModTime(), | 	slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(), | ||||||
| 		"size", confStat.Size()) | 		"size", confStat.Size()) | ||||||
| 	if err := conf.CheckExpire(confObj); err != nil { | 	if err := internalConf.CheckExpire(conf); err != nil { | ||||||
| 		slog.Error("conf check expire", "error", err) | 		slog.Error("conf check expire", "error", err) | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// run stages
 | 	// run stages
 | ||||||
| 	groups := conf.MatchGroups(confObj, conventionalCommit) | 	groups := internalConf.MatchGroups(conf, conventionalCommit) | ||||||
| 	env.Attr.Groups = strings.Join(groups, ",") | 	env.Attr.Groups = strings.Join(groups, ",") | ||||||
| 	_, forceQuitStageName, err := stage.Run( | 	_, forceQuitStageName, err := stage.Run( | ||||||
| 		confObj, | 		conf, | ||||||
| 		groups, | 		groups, | ||||||
| 		func( | 		func( | ||||||
| 			stageResults []internalStage.StageResult, | 			stageResults []internalStage.StageResult, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user