GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [release-1.23] fix: source func CLI version from build ldflags (#4030) · knative/func@aff9ef3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • config_ci.go
    • config_ci_int_test.go
  • pkg/ci/github
    • generator_test.go
    • workflow.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/config_ci.go‎

Copy file name to clipboardExpand all lines: cmd/config_ci.go
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"io"
6+
"regexp"
67
"strings"
78

89
"github.com/ory/viper"
@@ -11,8 +12,13 @@ import (
1112
"knative.dev/func/cmd/common"
1213
"knative.dev/func/pkg/ci/github"
1314
fn "knative.dev/func/pkg/functions"
15+
"knative.dev/func/pkg/version"
1416
)
1517

18+
// gitDescribeSuffix matches the "-N-gHASH" suffix produced by git describe
19+
// on commits that are not exactly on a release tag.
20+
var gitDescribeSuffix = regexp.MustCompile(`-\d+-g[0-9a-f]+$`)
21+
1622
// ciGeneratorFactory creates a CIGenerator from resolved CLI flag values.
1723
// Using a factory allows tests to capture the resolved config and inject
1824
// a mock generator without running the real implementation.
@@ -250,6 +256,7 @@ func newConfigAndLoadedFunc(
250256
RegistryUserVar: viper.GetString(registryUserVariableNameFlag),
251257
RegistryPassSecret: viper.GetString(registryPassSecretNameFlag),
252258
RegistryUrlVar: viper.GetString(registryUrlVariableNameFlag),
259+
FuncCliVersion: gitDescribeSuffix.ReplaceAllString(version.Kver, ""),
253260
RegistryLogin: viper.GetBool(registryLoginFlag),
254261
SelfHostedRunner: viper.GetBool(selfHostedRunnerFlag),
255262
RemoteBuild: viper.GetBool(remoteBuildFlag),
Collapse file

‎cmd/config_ci_int_test.go‎

Copy file name to clipboardExpand all lines: cmd/config_ci_int_test.go
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"knative.dev/func/pkg/ci/github"
1919
fn "knative.dev/func/pkg/functions"
2020
fnTest "knative.dev/func/pkg/testing"
21+
"knative.dev/func/pkg/version"
2122
)
2223

2324
// START: Integration Tests
@@ -77,6 +78,13 @@ func TestNewConfigCICmd_CreatesGitHubWorkflowDirectory(t *testing.T) {
7778
}
7879

7980
func TestNewConfigCICmd_WritesWorkflowFileToFSWithCorrectYAMLStructure(t *testing.T) {
81+
// Pin the CLI version so the generated workflow is deterministic,
82+
// independent of the version injected via -ldflags at build time
83+
// (which varies with the branch's most recent git tag).
84+
prev := version.Kver
85+
version.Kver = github.DefaultFuncCliVersion
86+
t.Cleanup(func() { version.Kver = prev })
87+
8088
opts := defaultIntegrationOpts(t, nil)
8189

8290
err := runConfigCiCmdIntegration(t, opts)
@@ -231,7 +239,7 @@ func assertDefaultWorkflow(t *testing.T, actualGw string) {
231239

232240
assert.Assert(t, yamlContains(actualGw, "Install func cli"))
233241
assert.Assert(t, yamlContains(actualGw, "functions-dev/action@main"))
234-
assert.Assert(t, yamlContains(actualGw, "version: knative-v1.22.0"))
242+
assert.Assert(t, yamlContains(actualGw, "version: "+github.DefaultFuncCliVersion))
235243
assert.Assert(t, yamlContains(actualGw, "name: func"))
236244

237245
assert.Assert(t, yamlContains(actualGw, "Deploy function"))
Collapse file

‎pkg/ci/github/generator_test.go‎

Copy file name to clipboardExpand all lines: pkg/ci/github/generator_test.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ func defaultOpts() opts {
566566
RegistryUserVar: github.DefaultRegistryUserVariableName,
567567
RegistryPassSecret: github.DefaultRegistryPassSecretName,
568568
RegistryUrlVar: github.DefaultRegistryUrlVariableName,
569+
FuncCliVersion: github.DefaultFuncCliVersion,
569570
RegistryLogin: github.DefaultRegistryLogin,
570571
SelfHostedRunner: github.DefaultSelfHostedRunner,
571572
RemoteBuild: github.DefaultRemoteBuild,
@@ -643,7 +644,7 @@ func assertDefaultWorkflow(t *testing.T, actualGw string) {
643644

644645
assert.Assert(t, yamlContains(actualGw, "Install func cli"))
645646
assert.Assert(t, yamlContains(actualGw, "functions-dev/action@main"))
646-
assert.Assert(t, yamlContains(actualGw, "version: knative-v1.22.0"))
647+
assert.Assert(t, yamlContains(actualGw, "version: "+github.DefaultFuncCliVersion))
647648
assert.Assert(t, yamlContains(actualGw, "name: func"))
648649

649650
assert.Assert(t, yamlContains(actualGw, "Deploy function"))
@@ -676,7 +677,7 @@ func assertSemiDefaultWorkflow(t *testing.T, actualGw string) {
676677

677678
assert.Assert(t, yamlContains(actualGw, "Install func cli"))
678679
assert.Assert(t, yamlContains(actualGw, "functions-dev/action@main"))
679-
assert.Assert(t, yamlContains(actualGw, "version: knative-v1.22.0"))
680+
assert.Assert(t, yamlContains(actualGw, "version: "+github.DefaultFuncCliVersion))
680681
assert.Assert(t, yamlContains(actualGw, "name: func"))
681682

682683
assert.Assert(t, yamlContains(actualGw, "Deploy function"))
Collapse file

‎pkg/ci/github/workflow.go‎

Copy file name to clipboardExpand all lines: pkg/ci/github/workflow.go
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var ErrWorkflowExists = errors.New("existing GitHub workflow detected, overwrite using the --force option")
1515

1616
const (
17-
defaultFuncCliVersion = "knative-v1.22.0"
17+
DefaultFuncCliVersion = "knative-v1.23.0"
1818
DefaultPlatform = "github"
1919
DefaultGitHubWorkflowDir = ".github/workflows"
2020
DefaultGitHubWorkflowFilename = "func-deploy.yaml"
@@ -45,7 +45,8 @@ type WorkflowConfig struct {
4545
RegistryLoginUrlVar,
4646
RegistryUserVar,
4747
RegistryPassSecret,
48-
RegistryUrlVar string
48+
RegistryUrlVar,
49+
FuncCliVersion string
4950
RegistryLogin,
5051
SelfHostedRunner,
5152
RemoteBuild,
@@ -74,6 +75,7 @@ func defaultWorkflowConfig() WorkflowConfig {
7475
RegistryUserVar: DefaultRegistryUserVariableName,
7576
RegistryPassSecret: DefaultRegistryPassSecretName,
7677
RegistryUrlVar: DefaultRegistryUrlVariableName,
78+
FuncCliVersion: DefaultFuncCliVersion,
7779
RegistryLogin: DefaultRegistryLogin,
7880
SelfHostedRunner: DefaultSelfHostedRunner,
7981
RemoteBuild: DefaultRemoteBuild,
@@ -111,6 +113,9 @@ func setEmptyFieldsToDefaults(defaults WorkflowConfig) WorkflowConfig {
111113
if defaults.RegistryUrlVar == "" {
112114
defaults.RegistryUrlVar = DefaultRegistryUrlVariableName
113115
}
116+
if defaults.FuncCliVersion == "" {
117+
defaults.FuncCliVersion = DefaultFuncCliVersion
118+
}
114119

115120
return defaults
116121
}
@@ -149,7 +154,7 @@ func newGitHubWorkflow(cfg WorkflowConfig, runtime string, messageWriter io.Writ
149154
steps = createRuntimeTestStep(cfg, runtime, messageWriter, steps)
150155
steps = createK8ContextStep(cfg, steps)
151156
steps = createRegistryLoginStep(cfg, steps)
152-
steps = createFuncCLIInstallStep(steps)
157+
steps = createFuncCLIInstallStep(cfg, steps)
153158

154159
steps, err := createFuncDeployStep(cfg, runtime, steps)
155160
if err != nil {
@@ -223,10 +228,10 @@ func createRegistryLoginStep(opts WorkflowConfig, steps []step) []step {
223228
return append(steps, *loginToContainerRegistry)
224229
}
225230

226-
func createFuncCLIInstallStep(steps []step) []step {
231+
func createFuncCLIInstallStep(cfg WorkflowConfig, steps []step) []step {
227232
installFuncCli := newStep("Install func cli").
228233
withUses("functions-dev/action@main").
229-
withActionConfig("version", defaultFuncCliVersion).
234+
withActionConfig("version", cfg.FuncCliVersion).
230235
withActionConfig("name", "func")
231236

232237
return append(steps, *installFuncCli)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.