github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/packager/creator/utils.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package creator contains functions for creating Jackal packages. 5 package creator 6 7 import ( 8 "os" 9 "runtime" 10 "time" 11 12 "github.com/Racer159/jackal/src/config" 13 "github.com/Racer159/jackal/src/pkg/packager/deprecated" 14 "github.com/Racer159/jackal/src/types" 15 ) 16 17 // recordPackageMetadata records various package metadata during package create. 18 func recordPackageMetadata(pkg *types.JackalPackage, createOpts types.JackalCreateOptions) error { 19 now := time.Now() 20 // Just use $USER env variable to avoid CGO issue. 21 // https://groups.google.com/g/golang-dev/c/ZFDDX3ZiJ84. 22 // Record the name of the user creating the package. 23 if runtime.GOOS == "windows" { 24 pkg.Build.User = os.Getenv("USERNAME") 25 } else { 26 pkg.Build.User = os.Getenv("USER") 27 } 28 29 // Record the hostname of the package creation terminal. 30 // The error here is ignored because the hostname is not critical to the package creation. 31 hostname, _ := os.Hostname() 32 pkg.Build.Terminal = hostname 33 34 if pkg.IsInitConfig() { 35 pkg.Metadata.Version = config.CLIVersion 36 } 37 38 pkg.Build.Architecture = pkg.Metadata.Architecture 39 40 // Record the Jackal Version the CLI was built with. 41 pkg.Build.Version = config.CLIVersion 42 43 // Record the time of package creation. 44 pkg.Build.Timestamp = now.Format(time.RFC1123Z) 45 46 // Record the migrations that will be ran on the package. 47 pkg.Build.Migrations = []string{ 48 deprecated.ScriptsToActionsMigrated, 49 deprecated.PluralizeSetVariable, 50 } 51 52 // Record the flavor of Jackal used to build this package (if any). 53 pkg.Build.Flavor = createOpts.Flavor 54 55 pkg.Build.RegistryOverrides = createOpts.RegistryOverrides 56 57 // Record the latest version of Jackal without breaking changes to the package structure. 58 pkg.Build.LastNonBreakingVersion = deprecated.LastNonBreakingVersion 59 60 return nil 61 }