-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_metadata_test.go
More file actions
167 lines (153 loc) · 5.07 KB
/
release_metadata_test.go
File metadata and controls
167 lines (153 loc) · 5.07 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package cms_test
import (
"encoding/json"
"os"
"sort"
"strings"
"testing"
)
type releaseManifest struct {
Name string `json:"name"`
Version string `json:"version"`
MinEngineVersion string `json:"minEngineVersion"`
Capabilities releaseCapabilities `json:"capabilities"`
Downloads []releaseDownload `json:"downloads"`
}
type releaseCapabilities struct {
ModuleTypes []string `json:"moduleTypes"`
StepTypes []string `json:"stepTypes"`
}
type releaseDownload struct {
OS string `json:"os"`
Arch string `json:"arch"`
URL string `json:"url"`
}
type releaseContractsFile struct {
Contracts []releaseContract `json:"contracts"`
}
type releaseContract struct {
Kind string `json:"kind"`
Type string `json:"type"`
Mode string `json:"mode"`
Config string `json:"config,omitempty"`
Input string `json:"input,omitempty"`
Output string `json:"output,omitempty"`
}
func TestReleaseMetadataIsPublishable(t *testing.T) {
manifestData, err := os.ReadFile("plugin.json")
if err != nil {
t.Fatal(err)
}
var manifest releaseManifest
if err := json.Unmarshal(manifestData, &manifest); err != nil {
t.Fatal(err)
}
if manifest.MinEngineVersion != "0.64.4" {
t.Fatalf("minEngineVersion = %q, want 0.64.4", manifest.MinEngineVersion)
}
wantDownloads := []string{
"darwin/amd64",
"darwin/arm64",
"linux/amd64",
"linux/arm64",
}
gotDownloads := make([]string, 0, len(manifest.Downloads))
for _, dl := range manifest.Downloads {
gotDownloads = append(gotDownloads, dl.OS+"/"+dl.Arch)
if !strings.Contains(dl.URL, "github.com/GoCodeAlone/workflow-plugin-cms/releases/download/v0.0.0/") {
t.Fatalf("download URL %q must use the releaser placeholder tag", dl.URL)
}
if !strings.HasSuffix(dl.URL, "workflow-plugin-cms-"+dl.OS+"-"+dl.Arch+".tar.gz") {
t.Fatalf("download URL %q does not match GoReleaser archive naming", dl.URL)
}
}
sort.Strings(gotDownloads)
if strings.Join(gotDownloads, ",") != strings.Join(wantDownloads, ",") {
t.Fatalf("downloads = %v, want %v", gotDownloads, wantDownloads)
}
contractsData, err := os.ReadFile("plugin.contracts.json")
if err != nil {
t.Fatal(err)
}
var contracts releaseContractsFile
if err := json.Unmarshal(contractsData, &contracts); err != nil {
t.Fatal(err)
}
byKindType := map[string]releaseContract{}
for _, contract := range contracts.Contracts {
byKindType[contract.Kind+"\x00"+contract.Type] = contract
}
for _, typ := range manifest.Capabilities.ModuleTypes {
contract := byKindType["module\x00"+typ]
if contract.Mode != "strict" || contract.Config == "" {
t.Fatalf("module %q contract = %+v, want strict config descriptor", typ, contract)
}
}
for _, typ := range manifest.Capabilities.StepTypes {
contract := byKindType["step\x00"+typ]
if contract.Mode != "strict" || contract.Input == "" || contract.Output == "" {
t.Fatalf("step %q contract = %+v, want strict input/output descriptors", typ, contract)
}
}
}
func TestGoReleaserStagesReleaseManifestWithoutMutatingRoot(t *testing.T) {
data, err := os.ReadFile(".goreleaser.yaml")
if err != nil {
t.Fatal(err)
}
src := string(data)
for _, want := range []string{
"cp plugin.json cmd/workflow-plugin-cms/plugin.json",
".release/plugin.json",
"sed -i.bak 's|/releases/download/v[^/]*/|/releases/download/{{ .Tag }}/|g' .release/plugin.json",
"plugin validate --file .release/plugin.json --strict-contracts",
"dst: plugin.json",
"draft: true",
} {
if !strings.Contains(src, want) {
t.Fatalf(".goreleaser.yaml missing %q", want)
}
}
if strings.Contains(src, "sed -i.bak 's/\\\"version\\\": \\\".*\\\"/\\\"version\\\": \\\"{{ .Version }}\\\"/' plugin.json") {
t.Fatal(".goreleaser.yaml must not mutate root plugin.json during release")
}
}
func TestReleaseWorkflowFollowsCurrentPluginPattern(t *testing.T) {
data, err := os.ReadFile(".github/workflows/release.yml")
if err != nil {
t.Fatal(err)
}
src := string(data)
for _, want := range []string{
"GoCodeAlone/setup-wfctl@v1",
"version: v0.64.4",
"wfctl plugin validate-contract --for-publish --tag",
"wfctl plugin verify-capabilities --binary",
"Verify shipped plugin.json carries tag",
"peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697",
} {
if !strings.Contains(src, want) {
t.Fatalf("release workflow missing %q", want)
}
}
for _, stale := range []string{"wfctl v0.63.2", "workflow/releases/download/v0.63.2", "${{ runner.temp }}/wfctl-bin/wfctl", "repository-dispatch@v3"} {
if strings.Contains(src, stale) {
t.Fatalf("release workflow contains stale pattern %q", stale)
}
}
}
func TestCommandEmbedsCanonicalPluginManifest(t *testing.T) {
if _, err := os.Stat("cmd/workflow-plugin-cms/plugin.json"); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile("cmd/workflow-plugin-cms/main.go")
if err != nil {
t.Fatal(err)
}
src := string(data)
for _, want := range []string{"//go:embed plugin.json", "sdk.MustEmbedManifest(pluginJSON)", "sdk.WithManifestProvider(manifest)"} {
if !strings.Contains(src, want) {
t.Fatalf("main.go missing %q", want)
}
}
}