JOJ3/cmd/joj3/env/env.go
张泊明518370910136 e8c6e87b94
All checks were successful
submodules sync / sync (push) Successful in 33s
build / build (push) Successful in 1m5s
build / trigger-build-image (push) Successful in 7s
feat(cmd): load groups from env
2025-01-31 21:06:38 -05:00

55 lines
1.1 KiB
Go

package env
import (
"fmt"
"os"
"time"
)
const (
ConfName = "JOJ3_CONF_NAME"
Groups = "JOJ3_GROUPS"
RunID = "JOJ3_RUN_ID"
)
type Attribute struct {
ConfName string
Groups string
RunID string
Actor string
Repository string
Sha string
Ref string
Workflow string
RunNumber string
ActorName string
ActorID string
}
var Attr Attribute
func init() {
timestamp := time.Now().UnixNano()
pid := os.Getpid()
high := timestamp >> 32
low := timestamp & 0xFFFFFFFF
combined := high ^ low
combined ^= int64(pid)
combined ^= int64(timestamp >> 16)
combined ^= (combined >> 8)
combined ^= (combined << 16)
Attr.RunID = fmt.Sprintf("%08X", combined&0xFFFFFFFF)
Attr.Actor = os.Getenv("GITHUB_ACTOR")
Attr.Repository = os.Getenv("GITHUB_REPOSITORY")
Attr.Sha = os.Getenv("GITHUB_SHA")
Attr.Ref = os.Getenv("GITHUB_REF")
Attr.Workflow = os.Getenv("GITHUB_WORKFLOW")
Attr.RunNumber = os.Getenv("GITHUB_RUN_NUMBER")
}
func Set() {
os.Setenv(ConfName, Attr.ConfName)
os.Setenv(Groups, Attr.Groups)
os.Setenv(RunID, Attr.RunID)
}