-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_packaging_test.go
More file actions
109 lines (95 loc) · 2.75 KB
/
release_packaging_test.go
File metadata and controls
109 lines (95 loc) · 2.75 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
package githubplugin_test
import (
"os"
"strings"
"testing"
)
func TestReleaseArchiveIncludesGitHubRunnerProvider(t *testing.T) {
data, err := os.ReadFile(".goreleaser.yaml")
if err != nil {
t.Fatalf("read .goreleaser.yaml: %v", err)
}
text := string(data)
if !goreleaserBuildIncludes(text, "github-runner-provider", []string{
"main: ./cmd/github-runner-provider",
"binary: github-runner-provider",
}) {
t.Fatal("release config must build the versioned github-runner-provider binary")
}
if !goreleaserArchiveIncludesBuild(text, "workflow-plugin-github", "github-runner-provider") {
t.Fatal("release archive must include github-runner-provider so wfctl plugin install/fetch can provide it")
}
if _, err := os.Stat("cmd/github-runner-provider/main.go"); err != nil {
t.Fatalf("github-runner-provider command must exist: %v", err)
}
}
func TestReleaseArchiveCheckRejectsProviderBuildOutsideArchive(t *testing.T) {
config := `
builds:
- id: workflow-plugin-github
main: ./cmd/workflow-plugin-github
- id: github-runner-provider
main: ./cmd/github-runner-provider
binary: github-runner-provider
archives:
- id: workflow-plugin-github
ids:
- workflow-plugin-github
`
if goreleaserArchiveIncludesBuild(config, "workflow-plugin-github", "github-runner-provider") {
t.Fatal("archive check must reject configs that build github-runner-provider without packaging it")
}
}
func goreleaserBuildIncludes(config, id string, required []string) bool {
builds := topLevelSection(config, "builds:")
build := listItemWithID(builds, id)
if build == "" {
return false
}
for _, want := range required {
if !strings.Contains(build, want) {
return false
}
}
return true
}
func goreleaserArchiveIncludesBuild(config, archiveID, buildID string) bool {
archives := topLevelSection(config, "archives:")
archive := listItemWithID(archives, archiveID)
return strings.Contains(archive, "ids:") && strings.Contains(archive, "- "+buildID)
}
func topLevelSection(config, header string) string {
lines := strings.Split(config, "\n")
for i, line := range lines {
if line != header {
continue
}
var section []string
for _, next := range lines[i+1:] {
if next != "" && !strings.HasPrefix(next, " ") && !strings.HasPrefix(next, "\t") {
break
}
section = append(section, next)
}
return strings.Join(section, "\n")
}
return ""
}
func listItemWithID(section, id string) string {
lines := strings.Split(section, "\n")
marker := "- id: " + id
for i, line := range lines {
if strings.TrimSpace(line) != marker {
continue
}
item := []string{line}
for _, next := range lines[i+1:] {
if strings.HasPrefix(next, " - id: ") {
break
}
item = append(item, next)
}
return strings.Join(item, "\n")
}
return ""
}