Skip to content

Commit dccfcf5

Browse files
author
Christian Weichel
committed
Initial commit
0 parents  commit dccfcf5

File tree

12 files changed

+2049
-0
lines changed

12 files changed

+2049
-0
lines changed

.github/workflows/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
push:
3+
tags:
4+
- 'v*'
5+
name: GoReleaser
6+
jobs:
7+
release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
#needs: [ test ]
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@master
14+
- name: goreleaser
15+
uses: docker://goreleaser/goreleaser
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
DOCKER_USERNAME: ${{ secrets.GITHUB_DOCKER_USERNAME }}
19+
DOCKER_PASSWORD: ${{ secrets.GITHUB_DOCKER_TOKEN }}
20+
DOCKER_REGISTRY: docker.io
21+
with:
22+
args: release
23+
if: success()

.goreleaser.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is an example goreleaser.yaml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
before:
4+
hooks:
5+
# you may remove this if you don't use vgo
6+
- go mod tidy
7+
# you may remove this if you don't need go generate
8+
- go generate ./...
9+
builds:
10+
- env:
11+
- CGO_ENABLED=0
12+
archives:
13+
- replacements:
14+
darwin: Darwin
15+
linux: Linux
16+
386: i386
17+
amd64: x86_64
18+
checksum:
19+
name_template: 'checksums.txt'
20+
snapshot:
21+
name_template: "{{ .Tag }}-next"
22+
changelog:
23+
sort: asc
24+
filters:
25+
exclude:
26+
- '^docs:'
27+
- '^test:'

cmd/build.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cmd
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/typefox/gitpod/leeway/pkg/leeway"
8+
)
9+
10+
// buildCmd represents the build command
11+
var buildCmd = &cobra.Command{
12+
Use: "build [targetPackage]",
13+
Short: "Builds a package",
14+
Args: cobra.MaximumNArgs(1),
15+
Run: func(cmd *cobra.Command, args []string) {
16+
workspace, err := getWorkspace()
17+
if err != nil {
18+
log.Fatal(err)
19+
}
20+
21+
var target string
22+
if len(args) == 0 {
23+
target = workspace.DefaultTarget
24+
} else {
25+
target = args[0]
26+
}
27+
if target == "" {
28+
log.Fatal("no target")
29+
}
30+
31+
pkg, exists := workspace.Packages[target]
32+
if !exists {
33+
log.Fatalf("package \"%s\" not found", target)
34+
return
35+
}
36+
37+
cacheMode, _ := cmd.Flags().GetString("cache")
38+
cache := getRemoteCache()
39+
if cacheMode != "remote" {
40+
cache = leeway.NoRemoteCache{}
41+
}
42+
useLocalCache := cacheMode != "none"
43+
44+
err = leeway.Build(pkg, useLocalCache, cache)
45+
if err != nil {
46+
log.Fatal(err)
47+
}
48+
},
49+
}
50+
51+
func init() {
52+
rootCmd.AddCommand(buildCmd)
53+
buildCmd.Flags().StringP("cache", "c", "remote", "Configures the caching behaviour: none=no caching, local=local caching only, remote=use all configured caches")
54+
}

cmd/collect.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"sort"
7+
"text/tabwriter"
8+
9+
log "github.com/sirupsen/logrus"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// collectCmd represents the collect command
14+
var collectCmd = &cobra.Command{
15+
Use: "collect",
16+
Short: "Collects all packages in a workspace",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
workspace, err := getWorkspace()
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
var pkgs []string
24+
for _, comp := range workspace.Components {
25+
for _, pkg := range comp.Packages {
26+
version, err := pkg.Version()
27+
if err != nil {
28+
version = "ERROR: " + err.Error()
29+
}
30+
31+
pkgs = append(pkgs, fmt.Sprintf("%s\t%s\n", pkg.FullName(), version))
32+
}
33+
}
34+
35+
sort.Slice(pkgs, func(i, j int) bool { return pkgs[i] < pkgs[j] })
36+
37+
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 2, ' ', 0)
38+
for _, pkg := range pkgs {
39+
fmt.Fprint(tw, pkg)
40+
}
41+
tw.Flush()
42+
},
43+
}
44+
45+
func init() {
46+
rootCmd.AddCommand(collectCmd)
47+
// collectCmd.Flags().Bool("dot", false, "print dependency graph as Graphviz dot")
48+
}

cmd/describe.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"sort"
7+
"strings"
8+
"text/tabwriter"
9+
10+
"github.com/disiqueira/gotree"
11+
log "github.com/sirupsen/logrus"
12+
"github.com/spf13/cobra"
13+
"github.com/typefox/gitpod/leeway/pkg/leeway"
14+
"gopkg.in/yaml.v2"
15+
)
16+
17+
var printDepTree bool
18+
19+
// describeCmd represents the describe command
20+
var describeCmd = &cobra.Command{
21+
Use: "describe <component|package>",
22+
Short: "Describes a single component or package",
23+
Args: cobra.MaximumNArgs(1),
24+
Run: func(cmd *cobra.Command, args []string) {
25+
workspace, err := getWorkspace()
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
30+
var target string
31+
if len(args) == 0 {
32+
target = workspace.DefaultTarget
33+
} else {
34+
target = args[0]
35+
}
36+
if target == "" {
37+
log.Fatal("no target")
38+
}
39+
40+
if isPkg := strings.Contains(target, ":"); isPkg {
41+
pkg, exists := workspace.Packages[target]
42+
if !exists {
43+
log.Fatalf("package \"%s\" does not exist", target)
44+
return
45+
}
46+
47+
if printDepTree {
48+
err = printDependencyTree(pkg)
49+
if err != nil {
50+
log.Fatal(err)
51+
}
52+
return
53+
}
54+
describePackage(pkg)
55+
} else {
56+
comp, exists := workspace.Components[target]
57+
if !exists {
58+
log.Fatalf("component \"%s\" does not exist", target)
59+
return
60+
}
61+
62+
if printDepTree {
63+
log.Fatal("--tree only makes sense for packages")
64+
}
65+
describeComponent(comp)
66+
}
67+
},
68+
}
69+
70+
func printDependencyTree(pkg *leeway.Package) error {
71+
var print func(parent gotree.Tree, pkg *leeway.Package)
72+
print = func(parent gotree.Tree, pkg *leeway.Package) {
73+
n := parent.Add(pkg.FullName())
74+
for _, dep := range pkg.GetDependencies() {
75+
print(n, dep)
76+
}
77+
}
78+
79+
tree := gotree.New("WORKSPACE")
80+
print(tree, pkg)
81+
_, err := fmt.Println(tree.Print())
82+
return err
83+
}
84+
85+
func describePackage(pkg *leeway.Package) {
86+
manifest, err := pkg.ContentManifest()
87+
if err != nil {
88+
log.Fatal(err)
89+
}
90+
version, err := pkg.Version()
91+
if err != nil {
92+
log.Fatal(err)
93+
}
94+
95+
deps := make([]string, len(pkg.GetDependencies()))
96+
for i, dep := range pkg.GetDependencies() {
97+
version, _ := dep.Version()
98+
deps[i] = fmt.Sprintf("\t%s\t%s\n", dep.FullName(), version)
99+
}
100+
sort.Slice(deps, func(i, j int) bool { return deps[i] < deps[j] })
101+
102+
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
103+
defer w.Flush()
104+
105+
fmt.Fprintf(w, "Name:\t%s\n", pkg.FullName())
106+
fmt.Fprintf(w, "Version:\t%s\t\n", version)
107+
fmt.Fprintf(w, "Configuration:\n%s", describeConfig(pkg.Config))
108+
if len(pkg.ArgumentDependencies) > 0 {
109+
fmt.Fprintf(w, "Version Relevant Arguments:\n")
110+
for _, argdep := range pkg.ArgumentDependencies {
111+
fmt.Fprintf(w, "\t%s\n", argdep)
112+
}
113+
}
114+
fmt.Fprintf(w, "Dependencies:\n")
115+
for _, dep := range deps {
116+
fmt.Fprint(w, dep)
117+
}
118+
fmt.Fprintf(w, "Sources:\n")
119+
for _, src := range manifest {
120+
segs := strings.Split(src, ":")
121+
name := strings.TrimPrefix(segs[0], pkg.C.Origin+"/")
122+
version := segs[1]
123+
fmt.Fprintf(w, "\t%s\t%s\n", name, version)
124+
}
125+
}
126+
127+
func describeComponent(comp leeway.Component) {
128+
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
129+
defer w.Flush()
130+
131+
fmt.Fprintf(w, "Name:\t%s\n", comp.Name)
132+
fmt.Fprintf(w, "Origin:\t%s\n", comp.Origin)
133+
fmt.Fprintf(w, "Packages:\t\n")
134+
for _, pkg := range comp.Packages {
135+
fmt.Fprintf(w, "\t%s\n", pkg.Name)
136+
}
137+
}
138+
139+
func describeConfig(cfg leeway.PackageConfig) string {
140+
fc, err := yaml.Marshal(cfg)
141+
if err != nil {
142+
return fmt.Sprintf("\t!! cannot present: %v !!", err)
143+
}
144+
145+
cfgmap := make(map[string]interface{})
146+
err = yaml.Unmarshal(fc, &cfgmap)
147+
if err != nil {
148+
return fmt.Sprintf("\t!! cannot present: %v !!", err)
149+
}
150+
151+
var res string
152+
for k, v := range cfgmap {
153+
res += fmt.Sprintf("\t%s:\t%v\n", k, v)
154+
}
155+
return res
156+
}
157+
158+
func init() {
159+
rootCmd.AddCommand(describeCmd)
160+
describeCmd.Flags().BoolVar(&printDepTree, "tree", false, "print the dependency tree of a package")
161+
}

0 commit comments

Comments
 (0)