Skip to content

Commit

Permalink
chore: merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Sep 30, 2024
2 parents e939def + b2bdf3a commit fda1f08
Show file tree
Hide file tree
Showing 26 changed files with 242 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand All @@ -47,7 +47,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
uses: github/codeql-action/init@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
uses: github/codeql-action/autobuild@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -72,4 +72,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
uses: github/codeql-action/analyze@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9
4 changes: 2 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand All @@ -62,7 +62,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
# ensures we fetch tag history for the repository
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
# ensures we fetch tag history for the repository
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand All @@ -36,7 +36,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
2 changes: 1 addition & 1 deletion api/types/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"strings"

"github.com/buildkite/yaml"
json "github.com/ghodss/yaml"
"gopkg.in/yaml.v3"
)

// ToString is a helper function to convert
Expand Down
2 changes: 1 addition & 1 deletion compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"strings"
"time"

yml "github.com/buildkite/yaml"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-retryablehttp"
yml "gopkg.in/yaml.v3"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/internal"
Expand Down
124 changes: 121 additions & 3 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"testing"
"time"

yml "github.com/buildkite/yaml"
"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"
"github.com/google/go-github/v65/github"
"github.com/urfave/cli/v2"
yml "gopkg.in/yaml.v3"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/internal"
Expand Down Expand Up @@ -2056,7 +2056,7 @@ func Test_client_modifyConfig(t *testing.T) {
Name: "docker",
Pull: "always",
Parameters: map[string]interface{}{
"init_options": map[string]interface{}{
"init_options": map[interface{}]interface{}{
"get_plugins": "true",
},
},
Expand Down Expand Up @@ -2089,7 +2089,7 @@ func Test_client_modifyConfig(t *testing.T) {
Name: "docker",
Pull: "always",
Parameters: map[string]interface{}{
"init_options": map[string]interface{}{
"init_options": map[interface{}]interface{}{
"get_plugins": "true",
},
},
Expand Down Expand Up @@ -3292,6 +3292,123 @@ func Test_CompileLite(t *testing.T) {
},
wantErr: false,
},
{
name: "render_inline with stages and env in template",
args: args{
file: "testdata/inline_with_stages_env.yml",
pipelineType: "",
substitute: true,
},
want: &yaml.Build{
Version: "1",
Metadata: yaml.Metadata{
RenderInline: true,
Environment: []string{"steps", "services", "secrets"},
},
Templates: []*yaml.Template{
{
Name: "golang",
Source: "github.example.com/github/octocat/golang_inline_stages_env.yml",
Format: "golang",
Type: "github",
Variables: map[string]any{
"image": string("golang:latest"),
"VELA_TEMPLATE_NAME": string("golang"),
},
},
},
Environment: raw.StringSliceMap{"DONT": "break"},
Stages: []*yaml.Stage{
{
Name: "test",
Needs: []string{"clone"},
Steps: []*yaml.Step{
{
Commands: raw.StringSlice{"echo from inline"},
Image: "alpine",
Name: "test",
Pull: "not_present",
},
{
Commands: raw.StringSlice{"echo from inline ruleset"},
Image: "alpine",
Name: "ruleset",
Pull: "not_present",
Ruleset: yaml.Ruleset{
If: yaml.Rules{
Event: []string{"push"},
Branch: []string{"main"},
},
Matcher: "filepath",
Operator: "and",
},
},
},
},
{
Name: "golang_foo",
Needs: []string{"clone"},
Steps: []*yaml.Step{
{
Commands: raw.StringSlice{"echo hello from foo"},
Image: "golang:latest",
Name: "golang_foo",
Pull: "not_present",
Ruleset: yaml.Ruleset{
If: yaml.Rules{
Event: []string{"tag"},
Tag: []string{"v*"},
},
Matcher: "filepath",
Operator: "and",
},
},
},
},
{
Name: "golang_bar",
Needs: []string{"clone"},
Steps: []*yaml.Step{
{
Commands: raw.StringSlice{"echo hello from bar"},
Image: "golang:latest",
Name: "golang_bar",
Pull: "not_present",
Ruleset: yaml.Ruleset{
If: yaml.Rules{
Event: []string{"tag"},
Tag: []string{"v*"},
},
Matcher: "filepath",
Operator: "and",
},
},
},
},
{
Name: "golang_star",
Needs: []string{"clone"},
Steps: []*yaml.Step{
{
Commands: raw.StringSlice{"echo hello from star"},
Image: "golang:latest",
Name: "golang_star",
Pull: "not_present",
Ruleset: yaml.Ruleset{
If: yaml.Rules{
Event: []string{"tag"},
Tag: []string{"v*"},
},
Matcher: "filepath",
Operator: "and",
},
},
},
},
},
},
wantErr: false,
},
{
name: "render_inline with stages - ruleset",
args: args{
Expand Down Expand Up @@ -3827,6 +3944,7 @@ func Test_CompileLite(t *testing.T) {
Metadata: yaml.Metadata{
Environment: []string{"steps", "services", "secrets"},
},
Environment: raw.StringSliceMap{},
Stages: []*yaml.Stage{
{
Name: "foo",
Expand Down
4 changes: 2 additions & 2 deletions compiler/native/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func TestNative_ExpandStepsMulti(t *testing.T) {
"auth_method": "token",
"username": "octocat",
"items": []interface{}{
map[string]interface{}{"path": "docker", "source": "secret/docker"},
map[interface{}]interface{}{"path": "docker", "source": "secret/docker"},
},
},
},
Expand All @@ -610,7 +610,7 @@ func TestNative_ExpandStepsMulti(t *testing.T) {
"auth_method": "token",
"username": "octocat",
"items": []interface{}{
map[string]interface{}{"path": "docker", "source": "secret/docker"},
map[interface{}]interface{}{"path": "docker", "source": "secret/docker"},
},
},
},
Expand Down
17 changes: 16 additions & 1 deletion compiler/native/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"io"
"os"

"gopkg.in/yaml.v3"
"github.com/buildkite/yaml"

"github.com/go-vela/server/compiler/template/native"
"github.com/go-vela/server/compiler/template/starlark"
"github.com/go-vela/types/constants"
typesRaw "github.com/go-vela/types/raw"
types "github.com/go-vela/types/yaml"
)

Expand Down Expand Up @@ -100,6 +101,13 @@ func (c *client) Parse(v interface{}, pipelineType string, template *types.Templ
return nil, nil, fmt.Errorf("unable to parse config: unrecognized pipeline_type of %s", c.repo.GetPipelineType())
}

// initializing Environment to prevent nil error
// as it may be modified later via templates, if
// none are defined in the base pipeline
if p.Environment == nil {
p.Environment = typesRaw.StringSliceMap{}
}

return p, raw, nil
}

Expand All @@ -113,6 +121,13 @@ func ParseBytes(data []byte) (*types.Build, []byte, error) {
return nil, data, fmt.Errorf("unable to unmarshal yaml: %w", err)
}

// initializing Environment to prevent nil error
// as it may be modified later via templates, if
// none are defined in the base pipeline
if config.Environment == nil {
config.Environment = typesRaw.StringSliceMap{}
}

return config, data, nil
}

Expand Down
Loading

0 comments on commit fda1f08

Please sign in to comment.