Yeet those builds out!
at main 91 lines 2.0 kB view raw
1package internal 2 3import ( 4 "context" 5 "flag" 6 "log/slog" 7 "os" 8 "os/exec" 9 "path/filepath" 10 "strconv" 11 "strings" 12 "time" 13 14 "github.com/Songmu/gitconfig" 15 "github.com/TecharoHQ/yeet/internal/yeet" 16) 17 18var ( 19 GPGKeyFile = flag.String("gpg-key-file", gpgKeyFileLocation(), "GPG key file to sign the package") 20 GPGKeyID = flag.String("gpg-key-id", "", "GPG key ID to sign the package") 21 GPGKeyPassword = flag.String("gpg-key-password", "", "GPG key password to sign the package") 22 UserName = flag.String("git-user-name", GitUserName(), "user name in Git") 23 UserEmail = flag.String("git-user-email", GitUserEmail(), "user email in Git") 24 SourceDateEpoch = flag.Int64("source-date-epoch", GetSourceDateEpoch(), "Timestamp to use for all files in packages") 25) 26 27const ( 28 fallbackName = "Mimi Yasomi" 29 fallbackEmail = "mimi@xeserv.us" 30) 31 32func gpgKeyFileLocation() string { 33 folder, err := os.UserConfigDir() 34 if err != nil { 35 return "" 36 } 37 38 return filepath.Join(folder, "techaro.lol", "yeet", "key.asc") 39} 40 41func GitUserName() string { 42 name, err := gitconfig.User() 43 if err != nil { 44 return fallbackName 45 } 46 47 return name 48} 49 50func GitUserEmail() string { 51 email, err := gitconfig.Email() 52 if err != nil { 53 return fallbackEmail 54 } 55 56 return email 57} 58 59func GitVersion() string { 60 vers, err := yeet.GitTag(context.Background()) 61 if err != nil { 62 panic(err) 63 } 64 65 return vers 66} 67 68func GetSourceDateEpoch() int64 { 69 // fallback needs to be 1 because some software thinks unix time 0 means "no time" 70 const fallback = 1 71 72 gitPath, err := exec.LookPath("git") 73 if err != nil { 74 slog.Warn("git not found in $PATH", "err", err) 75 return fallback 76 } 77 78 epochFromGitStr, err := yeet.Output(context.Background(), gitPath, "log", "-1", "--format=%ct") 79 if err == nil { 80 num, _ := strconv.ParseInt(strings.TrimSpace(epochFromGitStr), 10, 64) 81 if num != 0 { 82 return num 83 } 84 } 85 86 return fallback 87} 88 89func SourceEpoch() time.Time { 90 return time.Unix(*SourceDateEpoch, 0) 91}