forked from siderolabs/kres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.go
More file actions
119 lines (99 loc) · 3.31 KB
/
Copy pathgen.go
File metadata and controls
119 lines (99 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/siderolabs/kres/internal/config"
"github.com/siderolabs/kres/internal/output"
"github.com/siderolabs/kres/internal/output/codecov"
"github.com/siderolabs/kres/internal/output/conform"
"github.com/siderolabs/kres/internal/output/dockerfile"
"github.com/siderolabs/kres/internal/output/dockerignore"
"github.com/siderolabs/kres/internal/output/ghworkflow"
"github.com/siderolabs/kres/internal/output/github"
"github.com/siderolabs/kres/internal/output/gitignore"
"github.com/siderolabs/kres/internal/output/golangci"
"github.com/siderolabs/kres/internal/output/lefthook"
"github.com/siderolabs/kres/internal/output/license"
"github.com/siderolabs/kres/internal/output/makefile"
"github.com/siderolabs/kres/internal/output/markdownlint"
"github.com/siderolabs/kres/internal/output/release"
"github.com/siderolabs/kres/internal/output/renovate"
"github.com/siderolabs/kres/internal/output/sops"
"github.com/siderolabs/kres/internal/output/template"
"github.com/siderolabs/kres/internal/project/auto"
"github.com/siderolabs/kres/internal/project/meta"
)
var genCmd = &cobra.Command{
Use: "gen",
Short: "Generate build instructions for the project.",
Long: `Usage: kres gen
Generate build instructions for the project. Kres analyzes the project structure
starting from the current directory, detects project type and components, and emits
build instructions in the following formats:
* Makefile
* Dockerfile`,
Args: cobra.NoArgs,
RunE: func(*cobra.Command, []string) error {
return runGen()
},
}
func runGen() error {
fmt.Println("gen started")
var err error
options := meta.Options{
GoContainerVersion: config.GolangContainerImageVersion,
ContainerImageFrontend: config.ContainerImageFrontendDockerfile,
}
options.Config, err = config.NewProvider(".kres.yaml")
if err != nil {
return err
}
proj, err := auto.Build(&options)
if err != nil {
return err
}
if err := proj.LoadConfig(options.Config); err != nil {
return err
}
outputs := []output.Writer{
output.Wrap(github.NewOutput()),
output.Wrap(sops.NewOutput()),
output.Wrap(renovate.NewOutput()),
output.Wrap(conform.NewOutput()),
}
if !options.CompileGithubWorkflowsOnly {
outputs = append(
outputs,
output.Wrap(dockerfile.NewOutput()),
output.Wrap(dockerignore.NewOutput()),
output.Wrap(makefile.NewOutput()),
output.Wrap(golangci.NewOutput()),
output.Wrap(license.NewOutput()),
output.Wrap(gitignore.NewOutput()),
output.Wrap(codecov.NewOutput()),
output.Wrap(release.NewOutput()),
output.Wrap(markdownlint.NewOutput()),
output.Wrap(template.NewOutput()),
output.Wrap(lefthook.NewOutput()),
)
}
outputs = append(outputs, output.Wrap(ghworkflow.NewOutput(
options.MainBranch,
!options.CompileGithubWorkflowsOnly,
!options.SkipStaleWorkflow,
options.CIFailureSlackNotifyChannel,
)))
if err := proj.Compile(outputs); err != nil {
return err
}
for _, out := range outputs {
if err := out.Generate(); err != nil {
return fmt.Errorf("failed on step '%T', error: %w", out, err)
}
}
fmt.Println("success")
return nil
}