Skip to content

Commit

Permalink
Merge pull request #40 from SpiffyEight77/chore/skip-github-env-write
Browse files Browse the repository at this point in the history
chore: skip writing to GITHUB_ENV when building formula
  • Loading branch information
schristoff committed May 24, 2024
2 parents f20a07c + f31d018 commit 9808687
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions releases/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type GitMetadata struct {

// IsTaggedRelease indicates if the build is for a versioned tag
IsTaggedRelease bool

// Repository is the owner+name of the current repository
Repository string
}

func (m GitMetadata) ShouldPublishPermalink() bool {
Expand All @@ -41,8 +44,9 @@ func (m GitMetadata) ShouldPublishPermalink() bool {
func LoadMetadata() GitMetadata {
loadMetadata.Do(func() {
gitMetadata = GitMetadata{
Version: getVersion(),
Commit: getCommit(),
Version: getVersion(),
Commit: getCommit(),
Repository: getRepository(),
}

gitMetadata.Permalink, gitMetadata.IsTaggedRelease = getPermalink()
Expand All @@ -51,12 +55,16 @@ func LoadMetadata() GitMetadata {
log.Println("Permalink:", gitMetadata.Permalink)
log.Println("Version:", gitMetadata.Version)
log.Println("Commit:", gitMetadata.Commit)
log.Println("Repository:", gitMetadata.Repository)
})

// Save the metadata as environment variables to use later in the CI pipeline
p, _ := ci.DetectBuildProvider()
mgx.Must(p.SetEnv("PERMALINK", gitMetadata.Permalink))
mgx.Must(p.SetEnv("VERSION", gitMetadata.Version))
// Workaround to avoid writing to GITHUB_ENV when building the Homebrew formula.
if gitMetadata.Repository != "Homebrew/homebrew-core" {
// Save the metadata as environment variables to use later in the CI pipeline
p, _ := ci.DetectBuildProvider()
mgx.Must(p.SetEnv("PERMALINK", gitMetadata.Permalink))
mgx.Must(p.SetEnv("VERSION", gitMetadata.Version))
}

return gitMetadata
}
Expand Down Expand Up @@ -162,3 +170,12 @@ func getPermalink() (string, bool) {
return fmt.Sprintf("%s-%s", permalinkPrefix, strings.TrimPrefix(branch, "release/")), taggedRelease
}
}

func getRepository() string {
repository, ok := os.LookupEnv("GITHUB_REPOSITORY")
if !ok {
repository = "getporter/porter"
}

return repository
}

0 comments on commit 9808687

Please sign in to comment.