-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (72 loc) · 1.68 KB
/
main.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
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"errors"
"fmt"
"os"
"github.com/xmidt-org/release-builder-action/project"
)
var (
errBoolFormatError = errors.New("the string should be 'true' or 'false'")
)
func main() {
os.Exit(run())
}
func run() int {
p, err := parseAndValidateInput()
if err != nil {
Err("Error validating input: %s", err)
return 1
}
err = p.ExamineProject()
if err != nil {
Err("Error examining project: %s", err)
return 1
}
err = p.Release()
if err != nil {
Err("Error releasing: %s", err)
return 1
}
err = p.OutputData()
if err != nil {
Err("Error outputing: %s", err)
return 1
}
return 0
}
func parseAndValidateInput() (*project.Project, error) {
dryrun := false
switch os.Getenv("INPUTS_DRY_RUN") {
case "true":
dryrun = true
case "false":
default:
return nil, errBoolFormatError
}
opts := project.ProjectOpts{
Slug: os.Getenv("INPUTS_SLUG"),
BasePath: os.Getenv("INPUTS_WORKSPACE"),
Token: os.Getenv("INPUTS_TOKEN"),
TagPrefix: os.Getenv("INPUTS_TAG_PREFIX"),
ChangelogFile: os.Getenv("INPUTS_CHANGELOG"),
ArtifactDir: os.Getenv("INPUTS_ARTIFACT_DIR"),
SHASumFile: os.Getenv("INPUTS_SHASUM_FILE"),
Log: Info,
Meson: project.Meson{
Provides: os.Getenv("INPUTS_MESON_PROVIDES"),
},
}
p, err := project.NewProject(opts, dryrun)
if err != nil {
return nil, err
}
return p, nil
}
func Info(format string, v ...interface{}) {
fmt.Printf("\x1b[1;34m"+format+"\x1b[0m\n", v...)
}
func Err(format string, v ...interface{}) {
fmt.Printf("\x1b[1;31m"+format+"\x1b[0m\n", v...)
}