Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change generated file headers to include GitHub link instead of version #894

Merged
merged 8 commits into from Apr 9, 2024
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -9,6 +9,7 @@ workflows:
- architect/go-build:
name: go-build-devctl
binary: devctl
pre_test_target: generate-go
# Needed to trigger job also on git tag.
filters:
tags:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,5 @@ TODO
.DS_Store
.idea/
.vscode/

*.template.sha
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- Header of generated files do not contain the devctl version any more
ubergesundheit marked this conversation as resolved.
Show resolved Hide resolved

### Changed

- Generated file headers now include a GitHub link

## [6.23.3] - 2024-03-26

### Changed
Expand Down
4 changes: 4 additions & 0 deletions Makefile.zzz.custom.mk
@@ -0,0 +1,4 @@
generate-go:
go generate ./...

$(SOURCES): generate-go
2 changes: 1 addition & 1 deletion pkg/gen/input/ami/internal/params/key_common.go
Expand Up @@ -5,7 +5,7 @@ import (
)

func Header(comment string) string {
return internal.Header(comment)
return internal.Header(comment, "")
}

func Package(p Params) string {
Expand Down
6 changes: 5 additions & 1 deletion pkg/gen/input/dependabot/internal/file/dependabot.go
Expand Up @@ -11,6 +11,10 @@ import (
//go:embed dependabot.yml.template
var createDependabotTemplate string

//go:generate go run ../../../update-template-sha.go dependabot.yml.template
//go:embed dependabot.yml.template.sha
var createDependabotTemplateSha string

func NewCreateDependabotInput(p params.Params) input.Input {
i := input.Input{
Path: filepath.Join(p.Dir, "dependabot.yml"),
Expand All @@ -19,7 +23,7 @@ func NewCreateDependabotInput(p params.Params) input.Input {
"EcosystemGithubActions": params.EcosystemGithubActions(p),
"EcosystemGomod": params.EcosystemGomod(p),
"Ecosystems": params.Ecosystems(p),
"Header": params.Header("#"),
"Header": params.Header("#", createDependabotTemplateSha),
"Interval": params.Interval(p),
"Reviewers": params.Reviewers(p),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/gen/input/dependabot/internal/params/key_common.go
Expand Up @@ -4,6 +4,6 @@ import (
"github.com/giantswarm/devctl/v6/pkg/gen/internal"
)

func Header(comment string) string {
return internal.Header(comment)
func Header(comment, githubUrl string) string {
return internal.Header(comment, githubUrl)
}
6 changes: 5 additions & 1 deletion pkg/gen/input/makefile/internal/file/makefile.go
Expand Up @@ -10,12 +10,16 @@ import (
//go:embed Makefile.template
var makefileTemplate string

//go:generate go run ../../../update-template-sha.go Makefile.template
//go:embed Makefile.template.sha
var makefileTemplateSha string

func NewMakefileInput(p params.Params) input.Input {
i := input.Input{
Path: "Makefile",
TemplateBody: makefileTemplate,
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", makefileTemplateSha),
},
}

Expand Down
Expand Up @@ -10,12 +10,16 @@ import (
//go:embed Makefile.gen.app.mk.template
var makefileGenAppMkTemplate string

//go:generate go run ../../../update-template-sha.go Makefile.gen.app.mk.template
//go:embed Makefile.gen.app.mk.template.sha
var makefileGenAppMkTemplateSha string

func NewMakefileGenAppMkInput(p params.Params) input.Input {
i := input.Input{
Path: "Makefile.gen.app.mk",
TemplateBody: makefileGenAppMkTemplate,
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", makefileGenAppMkTemplateSha),
},
}

Expand Down
Expand Up @@ -10,12 +10,16 @@ import (
//go:embed Makefile.gen.cluster_app.mk.template
var makefileGenClusterAppMkTemplate string

//go:generate go run ../../../update-template-sha.go Makefile.gen.cluster_app.mk.template
//go:embed Makefile.gen.cluster_app.mk.template.sha
var makefileGenClusterAppMkTemplateSha string

func NewMakefileGenClusterAppMkInput(p params.Params) input.Input {
i := input.Input{
Path: "Makefile.gen.cluster_app.mk",
TemplateBody: makefileGenClusterAppMkTemplate,
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", makefileGenClusterAppMkTemplateSha),
},
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/gen/input/makefile/internal/file/makefile_gen_go_mk.go
Expand Up @@ -10,17 +10,25 @@ import (
//go:embed Makefile.gen.go.mk.template
var makefileGenGoMkTemplate string

//go:generate go run ../../../update-template-sha.go Makefile.gen.go.mk.template
//go:embed Makefile.gen.go.mk.template.sha
var makefileGenGoMkTemplateSha string

//go:embed windows-code-signing.sh.template
var windowsCodeSigningShellScriptTemplate string

//go:generate go run ../../../update-template-sha.go windows-code-signing.sh.template
//go:embed windows-code-signing.sh.template.sha
var windowsCodeSigningShellScriptTemplateSha string

func NewMakefileGenGoMkInput(p params.Params) []input.Input {
inputs := []input.Input{
{
Path: "Makefile.gen.go.mk",
TemplateBody: makefileGenGoMkTemplate,
TemplateData: map[string]interface{}{
"IsFlavourCLI": params.IsFlavourCLI(p),
"Header": params.Header("#"),
"Header": params.Header("#", makefileGenGoMkTemplateSha),
},
},
}
Expand All @@ -31,7 +39,7 @@ func NewMakefileGenGoMkInput(p params.Params) []input.Input {
Permissions: 0755,
TemplateBody: windowsCodeSigningShellScriptTemplate,
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", windowsCodeSigningShellScriptTemplateSha),
},
})
}
Expand Down
Expand Up @@ -10,12 +10,16 @@ import (
//go:embed Makefile.gen.k8sapi.mk.template
var makefileGenKubernetesAPITemplate string

//go:generate go run ../../../update-template-sha.go Makefile.gen.k8sapi.mk.template
//go:embed Makefile.gen.k8sapi.mk.template.sha
var makefileGenKubernetesAPITemplateSha string

func NewMakefileGenKubernetesAPIMkInput(p params.Params) input.Input {
i := input.Input{
Path: "Makefile.gen.k8sapi.mk",
TemplateBody: makefileGenKubernetesAPITemplate,
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", makefileGenKubernetesAPITemplateSha),
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gen/input/makefile/internal/params/key_common.go
Expand Up @@ -9,8 +9,8 @@ func IsFlavourCLI(p Params) bool {
return p.Flavours.Contains(gen.FlavourCLI)
}

func Header(comment string) string {
return internal.Header(comment)
func Header(comment, githubUrl string) string {
return internal.Header(comment, githubUrl)
}

func FileName(p Params, suffix string) string {
Expand Down
38 changes: 38 additions & 0 deletions pkg/gen/input/update-template-sha.go
@@ -0,0 +1,38 @@
//go:build ignore

package main

import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)

func main() {
filename := os.Args[1]

currentWorkingDirectory, err := os.Getwd()
if err != nil {
log.Fatal(err)
}

rootCmd := exec.Command("git", "rev-parse", "--show-toplevel")
gitRoot, err := rootCmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}

shaCmd := exec.Command("git", "rev-list", "--all", "-1", "--", fmt.Sprintf("%s/%s", currentWorkingDirectory, filename))
sha, err := shaCmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}

strippedPath := strings.TrimPrefix(currentWorkingDirectory, strings.TrimSpace(string(gitRoot)))

if err := os.WriteFile(filename+".sha", []byte(fmt.Sprintf("https://github.com/giantswarm/devctl/blob/%s%s/%s", strings.TrimSpace(string(sha)), strippedPath, filename)), 0666); err != nil {
log.Fatal(err)
}
}
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed add_customer_board_automation.yaml.template
var customerBoardAutomationTemplate string

//go:generate go run ../../../update-template-sha.go add_customer_board_automation.yaml.template
//go:embed add_customer_board_automation.yaml.template.sha
var customerBoardAutomationTemplateSha string

func NewCustomerBoardAutomationInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "add_customer_board_automation.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewCustomerBoardAutomationInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", customerBoardAutomationTemplateSha),
},
}

Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed check_values_schema.yaml.template
var checkValuesSchemaTemplate string

//go:generate go run ../../../update-template-sha.go check_values_schema.yaml.template
//go:embed check_values_schema.yaml.template.sha
var checkValuesSchemaTemplateSha string

func NewCheckValuesSchemaInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "check_values_schema.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewCheckValuesSchemaInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", checkValuesSchemaTemplateSha),
"SchemaDocsURL": "https://intranet.giantswarm.io/docs/organizational-structure/teams/cabbage/app-updates/helm-values-schema/",
},
}
Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed cluster_app_documentation_validation.yaml.template
var clusterAppDocumentationValidationTemplate string

//go:generate go run ../../../update-template-sha.go cluster_app_documentation_validation.yaml.template
//go:embed cluster_app_documentation_validation.yaml.template.sha
var clusterAppDocumentationValidationTemplateSha string

func NewClusterAppDocumentationValidation(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "documentation_validation.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewClusterAppDocumentationValidation(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", clusterAppDocumentationValidationTemplateSha),
},
}

Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed cluster_app_schema_validation.yaml.template
var clusterAppSchemaValidationTemplate string

//go:generate go run ../../../update-template-sha.go cluster_app_schema_validation.yaml.template
//go:embed cluster_app_schema_validation.yaml.template.sha
var clusterAppSchemaValidationTemplateSha string

func NewClusterAppSchemaValidation(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "json_schema_validation.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewClusterAppSchemaValidation(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", clusterAppSchemaValidationTemplateSha),
},
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/gen/input/workflows/internal/file/create_release.go
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed create_release.yaml.template
var createReleaseTemplate string

//go:generate go run ../../../update-template-sha.go create_release.yaml.template
//go:embed create_release.yaml.template.sha
var createReleaseTemplateSha string

func NewCreateReleaseInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "create_release.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewCreateReleaseInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", createReleaseTemplateSha),
"EnableFloatingMajorVersionTags": params.EnableFloatingMajorVersionTags(p),
"IsFlavourCLI": params.IsFlavourCLI(p),
"StepSetUpGitIdentity": params.StepSetUpGitIdentity(),
Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed create_release_pr.yaml.template
var createReleasePRTemplate string

//go:generate go run ../../../update-template-sha.go create_release_pr.yaml.template
//go:embed create_release_pr.yaml.template.sha
var createReleasePRTemplateSha string

func NewCreateReleasePRInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "create_release_pr.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewCreateReleasePRInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", createReleasePRTemplateSha),
"StepSetUpGitIdentity": params.StepSetUpGitIdentity(),
},
}
Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed ensure_major_version_tags.yaml.template
var ensureMajorVersionTagsTemplate string

//go:generate go run ../../../update-template-sha.go ensure_major_version_tags.yaml.template
//go:embed ensure_major_version_tags.yaml.template.sha
var ensureMajorVersionTagsTemplateSha string

func NewEnsureMajorVersionTagsInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "ensure_major_version_tags.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewEnsureMajorVersionTagsInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", ensureMajorVersionTagsTemplateSha),
},
}

Expand Down
Expand Up @@ -10,6 +10,10 @@ import (
//go:embed fix_vulnerabilities.yaml.template
var fixVulnerabilitiesTemplate string

//go:generate go run ../../../update-template-sha.go fix_vulnerabilities.yaml.template
//go:embed fix_vulnerabilities.yaml.template.sha
var fixVulnerabilitiesTemplateSha string

func NewFixVulnerabilitiesInput(p params.Params) input.Input {
i := input.Input{
Path: params.RegenerableFileName(p, "fix_vulnerabilities.yaml"),
Expand All @@ -19,7 +23,7 @@ func NewFixVulnerabilitiesInput(p params.Params) input.Input {
Right: "}}}}",
},
TemplateData: map[string]interface{}{
"Header": params.Header("#"),
"Header": params.Header("#", fixVulnerabilitiesTemplateSha),
"StepSetUpGitIdentity": params.StepSetUpGitIdentity(),
},
}
Expand Down