Skip to content

Commit

Permalink
Merge pull request #122 from sapcc/GoReleaser-update
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored Oct 11, 2023
2 parents 808b496 + b9427f9 commit 6402635
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
6 changes: 3 additions & 3 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Configuration struct {
Coverage CoverageConfiguration `yaml:"coverageTest"`
Golang GolangConfiguration `yaml:"golang"`
GolangciLint GolangciLintConfiguration `yaml:"golangciLint"`
Goreleaser GoreleaserConfiguration `yaml:"goreleaser"`
GoReleaser GoReleaserConfiguration `yaml:"goReleaser"`
SpellCheck SpellCheckConfiguration `yaml:"spellCheck"`
GitHubWorkflow *GithubWorkflowConfiguration `yaml:"githubWorkflow"`
Makefile MakefileConfig `yaml:"makefile"`
Expand Down Expand Up @@ -100,8 +100,8 @@ type GolangciLintConfiguration struct {
SkipDirs []string `yaml:"skipDirs"`
}

type GoreleaserConfiguration struct {
Enabled bool `yaml:"enabled"`
type GoReleaserConfiguration struct {
CreateConfig bool `yaml:"createConfig"`
}

// SpellCheckConfiguration appears in type Configuration.
Expand Down
7 changes: 5 additions & 2 deletions internal/ghworkflow/workflow_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func releaseWorkflow(cfg *core.GithubWorkflowConfiguration) {
return
}

w.Permissions.Contents = tokenScopeWrite
w.Permissions.Contents = tokenScopeRead
w.Permissions.Packages = tokenScopeWrite

w.On.Push.Branches = nil
Expand All @@ -37,7 +37,10 @@ func releaseWorkflow(cfg *core.GithubWorkflowConfiguration) {
}
j.addStep(jobStep{
Name: "Generate release info",
Run: "make build/release-info",
Run: makeMultilineYAMLString([]string{
"go install github.com/sapcc/go-bits/tools/release-info@latest",
"release-info CHANGELOG.md $(shell git describe --tags --abbrev=0) > build/release-info",
}),
})
j.addStep(jobStep{
Name: "Run GoReleaser",
Expand Down
38 changes: 5 additions & 33 deletions internal/goreleaser/goreleaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ package goreleaser

import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/sapcc/go-makefile-maker/internal/core"

Expand All @@ -34,11 +31,6 @@ import (
const goreleaserTemplate = `before:
hooks:
- go mod tidy
- rm -rf completions
- mkdir completions
- go run main.go completion bash >"completions/%[1]s.bash"
- go run main.go completion fish >"completions/%[1]s.fish"
- go run main.go completion zsh >"completions/%[1]s.zsh"
builds:
- env:
Expand All @@ -55,8 +47,7 @@ builds:
- -X github.com/sapcc/go-api-declarations/bininfo.binName=%[1]s
- -X github.com/sapcc/go-api-declarations/bininfo.version={{ .Version }}
- -X github.com/sapcc/go-api-declarations/bininfo.commit={{ .FullCommit }}
# Use CommitDate instead of Date for reproducibility.
- -X github.com/sapcc/go-api-declarations/bininfo.buildDate={{ .CommitDate }}
- -X github.com/sapcc/go-api-declarations/bininfo.buildDate={{ .CommitDate }} # use CommitDate instead of Date for reproducibility
# Set the modified timestamp on the output binary to ensure that builds are reproducible.
mod_timestamp: "{{ .CommitTimestamp }}"
Expand All @@ -75,24 +66,6 @@ archives:
- CHANGELOG.md
- LICENSE
- README.md
- completions/*
brews:
- repository:
owner: %[3]s
name: %[4]s
folder: HomebrewFormula
homepage: %[2]s
description: Command-line interface for Limes
license: Apache-2.0
install: |-
bin.install "%[1]s"
bash_completion.install "completions/%[1]s.bash" => "%[1]s"
fish_completion.install "completions/%[1]s.fish"
zsh_completion.install "completions/%[1]s.zsh" => "_%[1]s"
test: |
system "#{bin}/%[1]s --version"
commit_msg_template: "Homebrew: update formula to {{ .Tag }}"
`

func RenderConfig(cfg core.Configuration) {
Expand All @@ -103,10 +76,9 @@ func RenderConfig(cfg core.Configuration) {
logg.Fatal("Goreleasre requires metadata.url to be configured!")
}

metadataurl := must.Return(url.Parse(cfg.Metadata.URL))
githubOrg, githubRepo := filepath.Split(metadataurl.Path)

goreleaserFile := fmt.Sprintf(goreleaserTemplate, cfg.Binaries[0].Name, cfg.Metadata.URL, strings.ReplaceAll(githubOrg, "/", ""), githubRepo)
goreleaserFile := fmt.Sprintf(goreleaserTemplate, cfg.Binaries[0].Name)

must.Succeed(os.WriteFile(".goreleaser.yml", []byte(goreleaserFile), 0666))
// Remove renamed file
must.Succeed(os.RemoveAll(".goreleaser.yml"))
must.Succeed(os.WriteFile(".goreleaser.yaml", []byte(goreleaserFile), 0666))
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {
}

// Render Goreleaser config file
if cfg.Goreleaser.Enabled {
if cfg.GoReleaser.CreateConfig {
goreleaser.RenderConfig(cfg)
}

Expand Down

0 comments on commit 6402635

Please sign in to comment.