Skip to content

Commit

Permalink
Revert "Revert "Merge branch 'master' into abap-environment-update-ad…
Browse files Browse the repository at this point in the history
…don-product""

This reverts commit 363c038.
  • Loading branch information
Ran Li committed Feb 15, 2024
1 parent 48be8a0 commit 6e05b2e
Show file tree
Hide file tree
Showing 111 changed files with 2,515 additions and 3,213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'

- name: Install Groovy
run: sudo apt-get update && sudo apt-get install groovy -y
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: styfle/[email protected]
- uses: actions/stale@v8
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Thank you for your contribution! This issue is stale because it has been open 60 days with no activity. In order to keep it open, please remove stale label or add a comment within the next 10 days. If you need a Piper team member to remove the stale label make sure to add `@SAP/jenkins-library-team` to your comment.'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-go-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- name: Perform update
run: |
git checkout -B gh-action-update-golang-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-go-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- env:
CGO_ENABLED: 0
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/verify-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: styfle/[email protected]
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
Expand All @@ -63,8 +63,8 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
# action requires go@1.19
go-version: '1.20.x'
# action requires go@1.20
- name: checkout
uses: actions/checkout@v4
with:
Expand All @@ -79,7 +79,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
Expand All @@ -99,7 +99,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.19.x'
go-version: '1.20.x'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
Expand Down
15 changes: 15 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
quiet: false
mockname: "{{.InterfaceName}}"
filename: "{{.InterfaceName}}.go"
outpkg: mocks
packages:
github.com/influxdata/influxdb-client-go/v2:
config:
dir: pkg/influx/mocks
interfaces:
Client:
github.com/influxdata/influxdb-client-go/v2/api:
config:
dir: pkg/influx/mocks
interfaces:
WriteAPIBlocking:
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 AS build-env
FROM golang:1.20 AS build-env
COPY . /build
WORKDIR /build

Expand Down
2 changes: 1 addition & 1 deletion cmd/batsExecuteTests.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func runBatsExecuteTests(config *batsExecuteTestsOptions, telemetryData *telemet
func (b *batsExecuteTestsUtilsBundle) CloneRepo(URL string) error {
// ToDo: BatsExecute test needs to check if the repo can come from a
// enterprise github instance and needs ca-cert handelling seperately
_, err := pipergit.PlainClone("", "", URL, "bats-core", []byte{})
_, err := pipergit.PlainClone("", "", URL, "", "bats-core", []byte{})
return err

}
41 changes: 14 additions & 27 deletions cmd/checkIfStepActive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"io"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/SAP/jenkins-library/pkg/config"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/bmatcuk/doublestar"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

type checkStepActiveCommandOptions struct {
Expand Down Expand Up @@ -63,6 +63,9 @@ func checkIfStepActive(utils piperutils.FileUtils) error {
if checkStepActiveOptions.stageName == "" {
return errors.New("stage name must not be empty")
}
if checkStepActiveOptions.v1Active {
log.Entry().Warning("Please do not use --useV1 flag since it is deprecated and will be removed in future releases")
}
var pConfig config.Config

// load project config and defaults
Expand All @@ -78,31 +81,15 @@ func checkIfStepActive(utils piperutils.FileUtils) error {
}
defer stageConfigFile.Close()

var runSteps map[string]map[string]bool
var runStages map[string]bool

// load and evaluate step conditions
if checkStepActiveOptions.v1Active {
runConfig := config.RunConfig{StageConfigFile: stageConfigFile}
runConfigV1 := &config.RunConfigV1{RunConfig: runConfig}
err = runConfigV1.InitRunConfigV1(projectConfig, utils, GeneralConfig.EnvRootPath)
if err != nil {
return err
}
runSteps = runConfigV1.RunSteps
runStages = runConfigV1.RunStages
} else {
log.Entry().Warning("This step is using deprecated format of stage conditions which will be removed in Jan 2024. " +
"To avoid pipeline breakage, please call checkIfStepActive command with --useV1 flag.",
)
runConfig := &config.RunConfig{StageConfigFile: stageConfigFile}
err = runConfig.InitRunConfig(projectConfig, nil, nil, nil, nil, doublestar.Glob, checkStepActiveOptions.openFile)
if err != nil {
return err
}
runSteps = runConfig.RunSteps
runStages = runConfig.RunStages
runConfig := config.RunConfig{StageConfigFile: stageConfigFile}
runConfigV1 := &config.RunConfigV1{RunConfig: runConfig}
err = runConfigV1.InitRunConfigV1(projectConfig, utils, GeneralConfig.EnvRootPath)
if err != nil {
return err
}
runSteps := runConfigV1.RunSteps
runStages := runConfigV1.RunStages

log.Entry().Debugf("RunSteps: %v", runSteps)
log.Entry().Debugf("RunStages: %v", runStages)
Expand Down Expand Up @@ -149,7 +136,7 @@ func addCheckStepActiveFlags(cmd *cobra.Command) {
"Default config of piper pipeline stages")
cmd.Flags().StringVar(&checkStepActiveOptions.stepName, "step", "", "Name of the step being checked")
cmd.Flags().StringVar(&checkStepActiveOptions.stageName, "stage", "", "Name of the stage in which contains the step being checked")
cmd.Flags().BoolVar(&checkStepActiveOptions.v1Active, "useV1", false, "Use new CRD-style stage configuration")
cmd.Flags().BoolVar(&checkStepActiveOptions.v1Active, "useV1", false, "Use new CRD-style stage configuration (deprecated)")
cmd.Flags().StringVar(&checkStepActiveOptions.stageOutputFile, "stageOutputFile", "", "Defines a file path. If set, the stage output will be written to the defined file")
cmd.Flags().StringVar(&checkStepActiveOptions.stepOutputFile, "stepOutputFile", "", "Defines a file path. If set, the step output will be written to the defined file")
_ = cmd.MarkFlagRequired("step")
Expand Down
13 changes: 8 additions & 5 deletions cmd/checkIfStepActive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ stages:
steps:`
case "stage-config.yml":
fileContent = `
stages:
testStage:
stepConditions:
testStep:
config: testConfig`
spec:
stages:
- name: testStage
displayName: testStage
steps:
- name: testStep
conditions:
- configKey: testConfig`
case ".pipeline/config.yml":
fileContent = `
steps:
Expand Down
17 changes: 17 additions & 0 deletions cmd/cnbBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ func runCnbBuild(config *cnbBuildOptions, telemetry *buildpacks.Telemetry, image
}
commonPipelineEnvironment.container.imageNames = append(commonPipelineEnvironment.container.imageNames, imageNameAlias)

if config.ExpandBuildEnvVars {
config.BuildEnvVars = expandEnvVars(config.BuildEnvVars)
}

if config.BuildEnvVars != nil && len(config.BuildEnvVars) > 0 {
log.Entry().Infof("Setting custom environment variables: '%v'", config.BuildEnvVars)
imageSummary.AddEnv(config.BuildEnvVars)
Expand Down Expand Up @@ -619,6 +623,19 @@ func runCnbBuild(config *cnbBuildOptions, telemetry *buildpacks.Telemetry, image
return nil
}

func expandEnvVars(envVars map[string]any) map[string]any {
expandedEnvVars := map[string]any{}
for key, value := range envVars {
valueString, valueIsString := value.(string)
if valueIsString {
expandedEnvVars[key] = os.ExpandEnv(valueString)
} else {
expandedEnvVars[key] = value
}
}
return expandedEnvVars
}

func createInitialTelemetrySegment(config *cnbBuildOptions, utils cnbutils.BuildUtils) *buildpacks.Segment {
telemetrySegment := buildpacks.NewSegment()
projectPath, _, _ := config.resolvePath(utils) // ignore error here, telemetry problems should not fail the build
Expand Down
11 changes: 11 additions & 0 deletions cmd/cnbBuild_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions cmd/cnbBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,17 @@ func TestRunCnbBuild(t *testing.T) {
assert.Equal(t, "my-image:0.0.1", commonPipelineEnvironment.container.imageNameTag)
})

t.Run("success case (custom buildpacks and custom env variables, renaming docker conf file, additional tag)", func(t *testing.T) {
t.Parallel()
t.Run("success case (custom buildpacks and custom env variables with expand, renaming docker conf file, additional tag)", func(t *testing.T) {
t.Setenv("BAR", "BAZZ")
config := cnbBuildOptions{
ContainerImageName: "my-image",
ContainerImageTag: "0.0.1",
ContainerRegistryURL: imageRegistry,
DockerConfigJSON: "/path/to/test.json",
Buildpacks: []string{"test"},
ExpandBuildEnvVars: true,
BuildEnvVars: map[string]interface{}{
"FOO": "BAR",
"FOO": "${BAR}",
},
AdditionalTags: []string{"latest"},
}
Expand All @@ -269,6 +270,8 @@ func TestRunCnbBuild(t *testing.T) {

copiedFileExists, _ := utils.FileExists("/tmp/config.json")
assert.True(t, copiedFileExists)

assetBuildEnv(t, utils, "FOO", "BAZZ")
})

t.Run("success case (custom buildpacks, pre and post buildpacks and custom env variables, renaming docker conf file, additional tag)", func(t *testing.T) {
Expand All @@ -281,8 +284,9 @@ func TestRunCnbBuild(t *testing.T) {
PreBuildpacks: []string{"pre-test"},
PostBuildpacks: []string{"post-test"},
Buildpacks: []string{"test"},
ExpandBuildEnvVars: false,
BuildEnvVars: map[string]interface{}{
"FOO": "BAR",
"FOO": "${BAR}",
},
AdditionalTags: []string{"latest"},
}
Expand All @@ -304,6 +308,8 @@ func TestRunCnbBuild(t *testing.T) {

copiedFileExists, _ := utils.FileExists("/tmp/config.json")
assert.True(t, copiedFileExists)

assetBuildEnv(t, utils, "FOO", "${BAR}")
})

t.Run("success case (custom pre and post buildpacks and custom env variables, renaming docker conf file, additional tag)", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 6e05b2e

Please sign in to comment.