Skip to content

Commit 6031e03

Browse files
committed
fix(github-action): Set and save config early
This allows the scripts set in `before`, `run` and `after` to be able to use these modifications via `kraft`. Signed-off-by: Alexander Jung <alex@unikraft.io>
1 parent bd23d6a commit 6031e03

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

tools/github-action/main.go

+33-27
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,39 @@ func (opts *GithubAction) execScript(ctx context.Context, path string) error {
8585
}
8686

8787
func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) {
88+
if opts.RuntimeDir != "" {
89+
config.G[config.KraftKit](ctx).RuntimeDir = opts.RuntimeDir
90+
}
91+
92+
if opts.Auths != "" {
93+
var auths map[string]config.AuthConfig
94+
if err := yaml.Unmarshal([]byte(opts.Auths), &auths); err != nil {
95+
return fmt.Errorf("could not parse auths: %w", err)
96+
}
97+
98+
if config.G[config.KraftKit](ctx).Auth == nil {
99+
config.G[config.KraftKit](ctx).Auth = make(map[string]config.AuthConfig)
100+
}
101+
102+
for domain, auth := range auths {
103+
config.G[config.KraftKit](ctx).Auth[domain] = auth
104+
}
105+
}
106+
107+
if opts.Manifests != "" {
108+
var manifests []string
109+
if err := yaml.Unmarshal([]byte(opts.Manifests), &manifests); err != nil {
110+
return fmt.Errorf("could not parse manifests: %w", err)
111+
}
112+
config.G[config.KraftKit](ctx).Unikraft.Manifests = manifests
113+
}
114+
115+
// Save configuration to disk such that uses of `before`, `run` and `after`
116+
// scripts can access the configuration via `kraft`.
117+
if err := config.M[config.KraftKit](ctx).Write(true); err != nil {
118+
return fmt.Errorf("could not write configuration: %w", err)
119+
}
120+
88121
if (len(opts.Arch) > 0 || len(opts.Plat) > 0) && len(opts.Target) > 0 {
89122
return fmt.Errorf("target and platform/architecture are mutually exclusive")
90123
}
@@ -113,33 +146,6 @@ func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) {
113146
log.G(ctx).SetLevel(logrus.TraceLevel)
114147
}
115148

116-
if opts.RuntimeDir != "" {
117-
config.G[config.KraftKit](ctx).RuntimeDir = opts.RuntimeDir
118-
}
119-
120-
if opts.Auths != "" {
121-
var auths map[string]config.AuthConfig
122-
if err := yaml.Unmarshal([]byte(opts.Auths), &auths); err != nil {
123-
return fmt.Errorf("could not parse auths: %w", err)
124-
}
125-
126-
if config.G[config.KraftKit](ctx).Auth == nil {
127-
config.G[config.KraftKit](ctx).Auth = make(map[string]config.AuthConfig)
128-
}
129-
130-
for domain, auth := range auths {
131-
config.G[config.KraftKit](ctx).Auth[domain] = auth
132-
}
133-
}
134-
135-
if opts.Manifests != "" {
136-
var manifests []string
137-
if err := yaml.Unmarshal([]byte(opts.Manifests), &manifests); err != nil {
138-
return fmt.Errorf("could not parse manifests: %w", err)
139-
}
140-
config.G[config.KraftKit](ctx).Unikraft.Manifests = manifests
141-
}
142-
143149
if len(opts.Workdir) == 0 {
144150
opts.Workdir, err = os.Getwd()
145151
if err != nil {

0 commit comments

Comments
 (0)