Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/docker/dock…
Browse files Browse the repository at this point in the history
…er-25.0.6incompatible
  • Loading branch information
gambtho authored Sep 26, 2024
2 parents d4ea32d + 5113dd7 commit 6f423ef
Show file tree
Hide file tree
Showing 87 changed files with 1,987 additions and 347 deletions.
34 changes: 21 additions & 13 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ updates:
schedule:
interval: "weekly"
groups:
# Group updates together, so that they are all applied in a single PR.
# Grouped updates are currently in beta and is subject to change.
# xref: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#groups
k8s-go-deps:
patterns:
- "k8s.io/*"
- "sigs.k8s.io/*"
go-deps:
patterns:
- "*"
exclude-patterns:
- "k8s.io/*"
- "sigs.k8s.io/*"
# Group updates together, so that they are all applied in a single PR.
# Grouped updates are currently in beta and is subject to change.
# xref: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#groups
k8s-go-deps:
patterns:
- "k8s.io/*"
- "sigs.k8s.io/*"
go-deps:
patterns:
- "*"
exclude-patterns:
- "k8s.io/*"
- "sigs.k8s.io/*"
- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: weekly
groups:
actions:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: "/template/workflows/helm/.github/workflows"
schedule:
Expand Down
58 changes: 29 additions & 29 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]
schedule:
- cron: '33 14 * * 4'
- cron: "33 14 * * 4"

jobs:
analyze:
Expand All @@ -32,39 +32,39 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# 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@v2
# 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@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
7 changes: 5 additions & 2 deletions pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ func GenerateAddon(addons embed.FS, provider, addon, dest string, addonConfig Ad
if addonConfig.DraftConfig == nil {
return errors.New("DraftConfig is nil")
} else {
addonConfig.DraftConfig.ApplyDefaultVariables()
err := addonConfig.DraftConfig.ApplyDefaultVariables()
if err != nil {
return err
}
}

if err = osutil.CopyDir(addons, selectedAddonPath, addonDestPath, addonConfig.DraftConfig, templateWriter); err != nil {
if err = osutil.CopyDirWithTemplates(addons, selectedAddonPath, addonDestPath, addonConfig.DraftConfig, templateWriter); err != nil {
return err
}

Expand Down
34 changes: 32 additions & 2 deletions pkg/addons/addons_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package addons

import (
"fmt"
"github.com/Azure/draft/pkg/fixtures"
"io/ioutil"
"os"
"testing"
Expand Down Expand Up @@ -46,7 +48,8 @@ func TestGenerateHelmAddonSuccess(t *testing.T) {
Value: "host",
},
{
Name: "GENERATORLABEL",
Name: "GENERATORLABEL",
Value: "draft",
},
{
Name: "service-namespace",
Expand All @@ -69,6 +72,19 @@ func TestGenerateHelmAddonSuccess(t *testing.T) {
err = GenerateAddon(template.Addons, "azure", "webapp_routing", dir, addonConfig, templateWriter)
assert.Nil(t, err)

// Validate generated content against the fixture
generatedFilePath := fmt.Sprintf("%s/charts/templates/ingress.yaml", dir)
generatedContent, err := os.ReadFile(generatedFilePath)
assert.Nil(t, err)

fixturePath := "../fixtures/addons/helm/ingress.yaml"
if _, err := os.Stat(fixturePath); os.IsNotExist(err) {
t.Fatalf("Fixture file does not exist at path: %s", fixturePath)
}

err = fixtures.ValidateContentAgainstFixture(generatedContent, fixturePath)
assert.Nil(t, err)

assert.Nil(t, remove())
}

Expand All @@ -90,7 +106,8 @@ func TestGenerateKustomizeAddonSuccess(t *testing.T) {
Value: "host",
},
{
Name: "GENERATORLABEL",
Name: "GENERATORLABEL",
Value: "draft",
},
{
Name: "service-namespace",
Expand All @@ -113,6 +130,19 @@ func TestGenerateKustomizeAddonSuccess(t *testing.T) {
err = GenerateAddon(template.Addons, "azure", "webapp_routing", dir, addonConfig, templateWriter)
assert.Nil(t, err)

// Validate generated content against the fixture
generatedFilePath := fmt.Sprintf("%s/overlays/production/ingress.yaml", dir)
generatedContent, err := os.ReadFile(generatedFilePath)
assert.Nil(t, err)

fixturePath := "../fixtures/addons/kustomize/ingress.yaml"
if _, err := os.Stat(fixturePath); os.IsNotExist(err) {
t.Fatalf("Fixture file does not exist at path: %s", fixturePath)
}

err = fixtures.ValidateContentAgainstFixture(generatedContent, fixturePath)
assert.Nil(t, err)

assert.Nil(t, remove())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/azurePipelines/azurePipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *AzurePipelines) CreatePipelineFiles(deployType string, draftConfig *con
return fmt.Errorf("error applying default variables: %w", err)
}

if err := osutil.CopyDir(p.pipelineTemplates, srcDir, p.dest, draftConfig, templateWriter); err != nil {
if err := osutil.CopyDirWithTemplates(p.pipelineTemplates, srcDir, p.dest, draftConfig, templateWriter); err != nil {
return fmt.Errorf("error copying pipeline files: %w", err)
}

Expand Down
20 changes: 17 additions & 3 deletions pkg/azurePipelines/azurePipelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azurePipelines

import (
"fmt"
"github.com/Azure/draft/pkg/fixtures"
"os"
"testing"

Expand Down Expand Up @@ -32,15 +33,15 @@ func TestCreatePipelines(t *testing.T) {
deployType: "kustomize",
shouldError: false,
setConfig: func(dc *config.DraftConfig) {
dc.SetVariable("KUSTOMIZEPATH", "test/kustomize/overlays/production")
dc.SetVariable("KUSTOMIZEPATH", "kustomize/overlays/production")
},
},
{
name: "manifests_default_path",
deployType: "manifests",
shouldError: false,
setConfig: func(dc *config.DraftConfig) {
dc.SetVariable("PIPELINENAME", "some-other-name")
dc.SetVariable("PIPELINENAME", "testPipeline")
},
},
{
Expand Down Expand Up @@ -95,6 +96,19 @@ func TestCreatePipelines(t *testing.T) {
assert.Nil(t, err)
_, err = os.Stat(pipelineFilePath)
assert.Nil(t, err)

// Read the generated content
generatedContent, err := os.ReadFile(pipelineFilePath)
assert.Nil(t, err)

// Validate against the fixture file
fixturePath := fmt.Sprintf("../fixtures/pipelines/%s.yaml", tt.deployType)
if _, err := os.Stat(fixturePath); os.IsNotExist(err) {
t.Fatalf("Fixture file does not exist at path: %s", fixturePath)
}

err = fixtures.ValidateContentAgainstFixture(generatedContent, fixturePath)
assert.Nil(t, err)
}

err = os.RemoveAll(tempDir)
Expand Down Expand Up @@ -148,7 +162,7 @@ func newDraftConfig() *config.DraftConfig {
{
Name: "MANIFESTPATH",
Default: config.BuilderVarDefault{
Value: "manifests",
Value: "test/manifests",
},
},
{
Expand Down
25 changes: 25 additions & 0 deletions pkg/config/draftconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ package config
import (
"errors"
"fmt"
"io/fs"

log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

const draftConfigFile = "draft.yaml"

type DraftConfig struct {
TemplateName string `yaml:"templateName"`
DisplayName string `yaml:"displayName"`
Description string `yaml:"description"`
Type string `yaml:"type"`
Versions string `yaml:"versions"`
DefaultVersion string `yaml:"defaultVersion"`
Variables []*BuilderVar `yaml:"variables"`
FileNameOverrideMap map[string]string `yaml:"filenameOverrideMap"`
}
Expand All @@ -19,7 +28,9 @@ type BuilderVar struct {
Description string `yaml:"description"`
ExampleValues []string `yaml:"exampleValues"`
Type string `yaml:"type"`
Kind string `yaml:"kind"`
Value string `yaml:"value"`
Versions string `yaml:"versions"`
}

type BuilderVarDefault struct {
Expand All @@ -28,6 +39,20 @@ type BuilderVarDefault struct {
Value string `yaml:"value"`
}

func NewConfigFromFS(fileSys fs.FS, path string) (*DraftConfig, error) {
configBytes, err := fs.ReadFile(fileSys, path)
if err != nil {
return nil, err
}

var draftConfig DraftConfig
if err = yaml.Unmarshal(configBytes, &draftConfig); err != nil {
return nil, err
}

return &draftConfig, nil
}

func (d *DraftConfig) GetVariableExampleValues() map[string][]string {
variableExampleValues := make(map[string][]string)
for _, variable := range d.Variables {
Expand Down
Loading

0 comments on commit 6f423ef

Please sign in to comment.