generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
86 lines (68 loc) · 1.53 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
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"strings"
execute "github.com/alexellis/go-execute/v2"
)
func main() {
var (
yamlFile, jsonFile string
)
flag.StringVar(&yamlFile, "y", "", "File to write for actions inputs as YAML")
flag.StringVar(&jsonFile, "j", "", "File to write for actions inputs as JSON")
flag.Parse()
if len(yamlFile) == 0 && len(jsonFile) == 0 {
fmt.Println("You must supply a file to write to for -y and -j, see --help")
return
}
ctx := context.Background()
cmd := execute.ExecTask{
Command: "arkade",
Args: []string{"get", "-o", "list"},
StreamStdio: false,
}
res, err := cmd.Execute(ctx)
if err != nil {
panic(err)
}
if res.ExitCode != 0 {
panic("Non-zero exit code: " + res.Stderr)
}
yFile, err := os.Create(yamlFile)
if err != nil {
panic(err)
}
defer yFile.Close()
schema := []string{}
fmt.Fprintf(yFile, `inputs:
install-arkade:
description: 'Install the arkade binary'
default: true
required: false
print-summary:
description: 'Print a summary of tools installed by arkade'
default: true
required: false
`)
lines := strings.Split(strings.TrimSpace(res.Stdout), "\n")
for _, line := range lines {
cli := strings.TrimSpace(line)
schema = append(schema, cli)
fmt.Fprintf(yFile, ` %s:
description: 'Install %s'
required: false
`, cli, cli)
}
jFile, err := os.Create(jsonFile)
if err != nil {
panic(err)
}
en := json.NewEncoder(jFile)
if err := en.Encode(schema); err != nil {
panic(err)
}
}