-
Notifications
You must be signed in to change notification settings - Fork 17
/
plugin.go
67 lines (58 loc) · 1.5 KB
/
plugin.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
package main
import (
"log"
"os/exec"
"path/filepath"
"github.com/pkg/errors"
)
// Plugin defines the PyPi plugin parameters
type Plugin struct {
Repository string
Username string
Password string
SetupFile string
Distributions []string
SkipBuild bool
DistDir string
}
func (p Plugin) buildCommand() *exec.Cmd {
// Set the default of distributions in here
// as CLI package still has issues with string slice defaults
distributions := []string{"sdist"}
if len(p.Distributions) > 0 {
distributions = p.Distributions
}
args := []string{p.SetupFile}
for i := range distributions {
args = append(args, distributions[i])
}
return exec.Command("python3", args...)
}
func (p Plugin) uploadCommand() *exec.Cmd {
args := []string{}
args = append(args, "upload")
args = append(args, "--repository-url")
args = append(args, p.Repository)
args = append(args, "--username")
args = append(args, p.Username)
args = append(args, "--password")
args = append(args, p.Password)
args = append(args, filepath.Join(p.DistDir, "/*"))
return exec.Command("twine", args...)
}
// Exec runs the plugin - doing the necessary setup.py modifications
func (p Plugin) Exec() error {
if !p.SkipBuild {
out, err := p.buildCommand().CombinedOutput()
if err != nil {
return errors.Wrap(err, string(out))
}
log.Printf("Output: %s", out)
}
out, err := p.uploadCommand().CombinedOutput()
if err != nil {
return errors.Wrap(err, string(out))
}
log.Printf("Output: %s", out)
return nil
}