Skip to content

Commit 40d337d

Browse files
committed
feat: add runtime-aware builder config
Generated GitHub Actions workflows from `func config ci` previously used CLI flags for deploy configuration and had no builder selection logic. The deploy step now uses environment variables (FUNC_BUILDER, FUNC_REGISTRY, FUNC_REMOTE, FUNC_VERBOSE) and selects the builder based on the function runtime: host for Go/Python local builds, pack for Node/TypeScript/Rust/Quarkus/Springboot, and s2i for Python remote builds. CIConfig loads the function upfront, encapsulating runtime and root path, removing the need for callers to load separately. Platform validation now rejects empty values and error messages include supported platforms. Adds e2e tests using nektos/act to run generated workflows against a real cluster for each supported runtime, with a corresponding GitHub Actions job, Makefile target, and hack/test-full.sh entry. act is installed via hack/binaries.sh. Fixes TypeScript template imports (build → src) and the HTTP template body parameter type (string → optional IncomingBody). Fixes typos in CI workflow comments (Cluser → Cluster, runtim → runtime). Adds missing .PHONY declarations. Issue #3256 Signed-off-by: Stanislav Jakuschevskij <sjakusch@redhat.com>
1 parent 67c3fd2 commit 40d337d

11 files changed

Lines changed: 4962 additions & 4464 deletions

File tree

cmd/ci/common.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ package ci
22

33
import "fmt"
44

5+
func determineBuilder(runtime string, remote bool) (string, error) {
6+
switch runtime {
7+
case "go":
8+
if remote {
9+
return "pack", nil
10+
}
11+
return "host", nil
12+
13+
case "node", "typescript", "rust", "quarkus", "springboot":
14+
return "pack", nil
15+
16+
case "python":
17+
if remote {
18+
return "s2i", nil
19+
}
20+
return "host", nil
21+
22+
default:
23+
return "", fmt.Errorf("no builder support for runtime: %s", runtime)
24+
}
25+
}
26+
527
func determineRunner(selfHosted bool) string {
628
if selfHosted {
729
return "self-hosted"

cmd/ci/printer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GitHub Workflow Configuration
1212
Workflow name: %s
1313
Branch: %s
1414
Builder: %s
15-
Remote build: %s
15+
Remote build %s
1616
Runner: %s
1717
Test step: %s
1818
Registry login: %s
@@ -50,11 +50,16 @@ Create the following Secret on github.com: %s
5050
)
5151

5252
func PrintConfiguration(w io.Writer, conf CIConfig) error {
53+
builder, err := determineBuilder(conf.FnRuntime(), conf.RemoteBuild())
54+
if err != nil {
55+
return err
56+
}
57+
5358
if _, err := fmt.Fprintf(w, MainLayoutPlainText,
5459
conf.OutputPath(),
5560
conf.WorkflowName(),
5661
conf.Branch(),
57-
conf.FnBuilder(),
62+
builder,
5863
enabledOrDisabled(conf.RemoteBuild()),
5964
determineRunner(conf.SelfHostedRunner()),
6065
enabledOrDisabled(conf.TestStep()),

cmd/ci/printer_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package ci
22

33
import (
4+
"bytes"
45
"errors"
6+
"fmt"
57
"testing"
68

79
"gotest.tools/v3/assert"
@@ -50,6 +52,15 @@ func TestPrintConfigurationFail(t *testing.T) {
5052

5153
assert.Error(t, err, errWrite.Error())
5254
})
55+
56+
t.Run("unsupported runtime fails", func(t *testing.T) {
57+
conf := CIConfig{fnRuntime: "ruby"}
58+
expectedErr := fmt.Errorf("no builder support for runtime: %s", conf.FnRuntime())
59+
60+
err := PrintConfiguration(&bytes.Buffer{}, conf)
61+
62+
assert.Error(t, err, expectedErr.Error())
63+
})
5364
}
5465

5566
func TestPrintPostExportMessageFail(t *testing.T) {

cmd/ci/workflow.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ type step struct {
4242
With map[string]string `yaml:"with,omitempty"`
4343
}
4444

45-
func NewGitHubWorkflow(conf CIConfig, messageWriter io.Writer) *githubWorkflow {
45+
func NewGitHubWorkflow(conf CIConfig, messageWriter io.Writer) (*githubWorkflow, error) {
4646
var steps []step
4747
steps = createCheckoutStep(steps)
4848
steps = createRuntimeTestStep(conf, messageWriter, steps)
4949
steps = createK8ContextStep(conf, steps)
5050
steps = createRegistryLoginStep(conf, steps)
5151
steps = createFuncCLIInstallStep(steps)
5252

53-
steps = createFuncDeployStep(conf, steps)
53+
steps, err := createFuncDeployStep(conf, steps)
54+
if err != nil {
55+
return nil, err
56+
}
5457

5558
return &githubWorkflow{
5659
Name: conf.WorkflowName(),
@@ -61,7 +64,7 @@ func NewGitHubWorkflow(conf CIConfig, messageWriter io.Writer) *githubWorkflow {
6164
Steps: steps,
6265
},
6366
},
64-
}
67+
}, nil
6568
}
6669

6770
func createCheckoutStep(steps []step) []step {
@@ -128,10 +131,15 @@ func createFuncCLIInstallStep(steps []step) []step {
128131
return append(steps, *installFuncCli)
129132
}
130133

131-
func createFuncDeployStep(conf CIConfig, steps []step) []step {
134+
func createFuncDeployStep(conf CIConfig, steps []step) ([]step, error) {
132135
deployFuncStep := newStep("Deploy function").
133-
withEnv("FUNC_VERBOSE", "true").
134-
withEnv("FUNC_BUILDER", conf.FnBuilder())
136+
withEnv("FUNC_VERBOSE", "true")
137+
138+
builder, err := determineBuilder(conf.FnRuntime(), conf.RemoteBuild())
139+
if err != nil {
140+
return nil, err
141+
}
142+
deployFuncStep.withEnv("FUNC_BUILDER", builder)
135143

136144
if conf.RemoteBuild() {
137145
deployFuncStep.withEnv("FUNC_REMOTE", "true")
@@ -144,7 +152,7 @@ func createFuncDeployStep(conf CIConfig, steps []step) []step {
144152
deployFuncStep.withEnv("FUNC_REGISTRY", registryUrl).
145153
withRun("func deploy")
146154

147-
return append(steps, *deployFuncStep)
155+
return append(steps, *deployFuncStep), nil
148156
}
149157

150158
func createPushTrigger(conf CIConfig) workflowTriggers {

cmd/ci/workflow_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func TestGitHubWorkflow_Export(t *testing.T) {
3131
)
3232
assert.NilError(t, configErr, "unexpected error when creating CIConfig")
3333

34-
gw := ci.NewGitHubWorkflow(cfg, &bytes.Buffer{})
34+
gw, workflowErr := ci.NewGitHubWorkflow(cfg, &bytes.Buffer{})
35+
assert.NilError(t, workflowErr, "unexpected error when creating GitHub Workflow")
36+
3537
exportErr := gw.Export(cfg.FnGitHubWorkflowFilepath(), bufferWriter, true, &bytes.Buffer{})
3638

3739
// THEN

cmd/config_ci.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ func runConfigCIGitHub(
158158
return err
159159
}
160160

161-
githubWorkflow := ci.NewGitHubWorkflow(cfg, messageWriter)
161+
githubWorkflow, err := ci.NewGitHubWorkflow(cfg, messageWriter)
162+
if err != nil {
163+
return err
164+
}
165+
162166
if err := githubWorkflow.Export(cfg.FnGitHubWorkflowFilepath(), writer, cfg.Force(), messageWriter); err != nil {
163167
return err
164168
}

0 commit comments

Comments
 (0)