-
Notifications
You must be signed in to change notification settings - Fork 18
/
magefile.publish.go
144 lines (113 loc) · 3.5 KB
/
magefile.publish.go
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
// +build mage
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
const distPath = "dist"
const packageName = "cartridge-cli"
type Distro struct {
OS string
Dist string
}
var targetDistros = []Distro{
{OS: "el", Dist: "7"},
{OS: "el", Dist: "8"},
{OS: "fedora", Dist: "30"},
{OS: "fedora", Dist: "31"},
{OS: "fedora", Dist: "32"},
{OS: "fedora", Dist: "33"},
{OS: "fedora", Dist: "34"},
{OS: "fedora", Dist: "35"},
{OS: "fedora", Dist: "36"},
{OS: "ubuntu", Dist: "xenial"},
{OS: "ubuntu", Dist: "bionic"},
{OS: "ubuntu", Dist: "eoan"},
{OS: "ubuntu", Dist: "focal"},
{OS: "ubuntu", Dist: "hirsute"},
{OS: "ubuntu", Dist: "impish"},
{OS: "ubuntu", Dist: "jammy"},
{OS: "debian", Dist: "stretch"},
{OS: "debian", Dist: "buster"},
{OS: "debian", Dist: "bullseye"},
}
// walkMatch walks through directory and collects file paths satisfying patterns.
func walkMatch(root string, patterns []string) ([]string, error) {
var matches []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
for _, pattern := range patterns {
if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil {
return err
} else if matched {
matches = append(matches, path)
return nil
}
}
return nil
})
if err != nil {
return nil, err
}
return matches, nil
}
// getPatterns returns patterns to select goreleaser build artifacts.
// Based on update_repo.sh with some modifications.
// See https://github.com/tarantool/tarantool/blob/c9e3926e5ae82785c5eb494521c44ba522109e95/tools/update_repo.sh#L517
// and https://github.com/tarantool/tarantool/blob/c9e3926e5ae82785c5eb494521c44ba522109e95/tools/update_repo.sh#L986
func getPatterns(distro Distro) ([]string, error) {
if distro.OS == "el" || distro.OS == "fedora" {
return []string{"*.x86_64.rpm", "*.noarch.rpm"}, nil
}
if distro.OS == "ubuntu" || distro.OS == "debian" {
return []string{"*.deb", "*.dsc"}, nil
}
return nil, fmt.Errorf("Unknown OS: %s", distro.OS)
}
func PublishRWS() error {
fmt.Printf("Publish packages to RWS...\n")
for _, targetDistro := range targetDistros {
fmt.Printf("Publish package for %s/%s...\n", targetDistro.OS, targetDistro.Dist)
patterns, perr := getPatterns(targetDistro)
if perr != nil {
return fmt.Errorf("Failed to publish package for %s/%s: %s", targetDistro.OS, targetDistro.Dist, perr)
}
files, ferr := walkMatch(distPath, patterns)
if ferr != nil {
return fmt.Errorf("Failed to publish package for %s/%s: %s", targetDistro.OS, targetDistro.Dist, ferr)
}
rwsUrlPart := os.Getenv("RWS_URL_PART")
if rwsUrlPart == "" {
return fmt.Errorf("Failed to publish package: RWS_URL_PART is not set")
}
flags := []string{
"-v",
"-LfsS",
"-X", "PUT", fmt.Sprintf("%s/%s/%s", rwsUrlPart, targetDistro.OS, targetDistro.Dist),
"-F", fmt.Sprintf("product=%s", packageName),
}
for _, file := range files {
flags = append(flags, "-F", fmt.Sprintf("%s=@./%s", filepath.Base(file), file))
}
fmt.Printf("curl flags (excluding secrets): %s\n", flags)
rwsAuth := os.Getenv("RWS_AUTH")
if rwsAuth == "" {
return fmt.Errorf("Failed to publish package: RWS_AUTH is not set")
}
flags = append(flags, "-u", rwsAuth)
cmd := exec.Command("curl", flags...)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Failed to publish package for %s/%s: %s, %s",
targetDistro.OS, targetDistro.Dist, err, output)
}
}
return nil
}