forked from jerray/publish-docker-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
54 lines (46 loc) · 1.48 KB
/
options.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
package main
import (
"fmt"
"github.com/caarlos0/env/v6"
)
type GitHub struct {
Workflow string `env:"GITHUB_WORKFLOW"`
Action string `env:"GITHUB_ACTION"`
Actor string `env:"GITHUB_ACTOR"`
Repository string `env:"GITHUB_REPOSITORY"`
Commit string `env:"GITHUB_SHA"`
EventName string `env:"GITHUB_EVENT_NAME"`
EventPath string `env:"GITHUB_EVENT_PATH"`
Ref string `env:"GITHUB_REF"`
}
type Inputs struct {
Username string `env:"INPUT_USERNAME"`
Password string `env:"INPUT_PASSWORD"`
Registry string `env:"INPUT_REGISTRY"`
Repository string `env:"INPUT_REPOSITORY"`
Cache string `env:"INPUT_CACHE"`
Dockerfile string `env:"INPUT_FILE" envDefault:"Dockerfile"`
Path string `env:"INPUT_PATH" envDefault:"."`
Tags []string `env:"INPUT_TAGS" envDefault:"latest" envSeparator:","`
BuildArgs []string `env:"INPUT_BUILD_ARGS" envSeparator:","`
AllowPullRequest bool `env:"INPUT_ALLOW_PULL_REQUEST"`
AutoTag bool `env:"INPUT_AUTO_TAG"`
}
type Options struct {
GitHub GitHub
Inputs Inputs
}
func LoadOptions() (*Options, error) {
github := GitHub{}
if err := env.Parse(&github); err != nil {
return nil, fmt.Errorf("failed to parse github envrionments: %s", err)
}
inputs := Inputs{}
if err := env.Parse(&inputs); err != nil {
return nil, fmt.Errorf("failed to parse inputs: %s", err)
}
return &Options{
GitHub: github,
Inputs: inputs,
}, nil
}