forked from kyma-project/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Scaffold Command (kyma-project#1859)
* feat: Add Scaffold Command * feat: Add Docs * feat: Add Docs * docs(scaffold.go): Fix Long Description * trigger build * docs(scaffold.go): Update Md Files * Update cmd/kyma/alpha/create/scaffold/scaffold.go Co-authored-by: Małgorzata Świeca <[email protected]> * Update cmd/kyma/alpha/create/scaffold/scaffold.go Co-authored-by: Małgorzata Świeca <[email protected]> * Update cmd/kyma/alpha/create/scaffold/scaffold.go Co-authored-by: Małgorzata Świeca <[email protected]> * Update docs/gen-docs/kyma_alpha_create.md Co-authored-by: Małgorzata Świeca <[email protected]> * Update cmd/kyma/alpha/create/scaffold/scaffold.go Co-authored-by: Małgorzata Świeca <[email protected]> * docs(scaffold.go): Update Md Files * Merge Latest Changes * Fix E2E Test * scaffold.go: Fix Manifest and Default CR Generation * default_cr.go: Fix Lint * default_cr.go: Fix Metadata Case Sensitivity Issue * scaffold.go: Fix Empty Directory Issue * test-e2e-create-scaffold.yml: Add Newline At The End * opts.go: Fix Overwrite Validation * scaffold.go: Update Command Help * Update Docs * retrigger jobs * Refactoring * Refactoring * Refactoring * Refactoring * Refactoring * Refactoring * Refactoring * Refactoring * Refactoring * Add tests (WIP) * Add tests (WIP) * Add tests (WIP) * Add tests (WIP) * Add tests (WIP) * Add tests (WIP) * Add tests (WIP) * Review fix * Apply suggestions from code review Co-authored-by: Oleksandr Meteiko <[email protected]> * Review fix * Review fix * Review fix * Review fix * Review fix * Review fix * Review fix * Review fix --------- Co-authored-by: Małgorzata Świeca <[email protected]> Co-authored-by: Benjamin Lindner <[email protected]> Co-authored-by: Tomasz Smelcerz <[email protected]> Co-authored-by: Oleksandr Meteiko <[email protected]>
- Loading branch information
1 parent
539e188
commit f1ed885
Showing
18 changed files
with
1,420 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: TestSuite E2E. Scaffold Creation | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- 'release-**' | ||
pull_request: | ||
branches: | ||
- main | ||
- 'release-**' | ||
paths: | ||
- 'go.mod' | ||
- 'go.sum' | ||
- '**.go' | ||
jobs: | ||
e2e: | ||
name: "Run E2E tests" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Kyma CLI | ||
uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache-dependency-path: 'go.sum' | ||
- name: Build Kyma CLI | ||
run: | | ||
make resolve validate build-linux | ||
chmod +x ./bin/kyma-linux | ||
ls -la ./bin | ||
mv ./bin/kyma-linux /usr/local/bin/kyma | ||
timeout-minutes: 10 | ||
- name: Run create scaffold test | ||
run: | | ||
make -C tests/e2e test-create-scaffold | ||
timeout-minutes: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package scaffold | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/kyma-project/cli/internal/cli" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Options specifies the flags for the scaffold command | ||
type Options struct { | ||
*cli.Options | ||
|
||
Overwrite bool | ||
Directory string | ||
|
||
ModuleConfigFile string | ||
ManifestFile string | ||
SecurityConfigFile string | ||
DefaultCRFile string | ||
|
||
ModuleName string | ||
ModuleVersion string | ||
ModuleChannel string | ||
} | ||
|
||
func (o *Options) securityConfigFileConfigured() bool { | ||
return o.SecurityConfigFile != "" | ||
} | ||
|
||
func (o *Options) defaultCRFileConfigured() bool { | ||
return o.DefaultCRFile != "" | ||
} | ||
|
||
var ( | ||
errDirNotExists = errors.New("provided directory does not exist") | ||
errNotDirectory = errors.New("provided path is not a directory") | ||
errModuleConfigExists = errors.New("module config file already exists. use --overwrite flag to overwrite it") | ||
errModuleNameEmpty = errors.New("--module-name flag must not be empty") | ||
errModuleVersionEmpty = errors.New("--module-version flag must not be empty") | ||
errModuleChannelEmpty = errors.New("--module-channel flag must not be empty") | ||
errManifestFileEmpty = errors.New("--gen-manifest flag must not be empty") | ||
errModuleConfigEmpty = errors.New("--module-config flag must not be empty") | ||
errManifestCreation = errors.New("could not generate manifest") | ||
errDefaultCRCreationFailed = errors.New("could not generate default CR") | ||
errModuleConfigCreationFailed = errors.New("could not generate module config") | ||
errSecurityConfigCreationFailed = errors.New("could not generate security config") | ||
) | ||
|
||
// NewOptions creates options with default values | ||
func NewOptions(o *cli.Options) *Options { | ||
return &Options{Options: o} | ||
} | ||
|
||
func (o *Options) Validate() error { | ||
if o.ModuleName == "" { | ||
return errModuleNameEmpty | ||
} | ||
|
||
if o.ModuleVersion == "" { | ||
return errModuleVersionEmpty | ||
} | ||
|
||
if o.ModuleChannel == "" { | ||
return errModuleChannelEmpty | ||
} | ||
|
||
err := o.validateDirectory() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if o.ModuleConfigFile == "" { | ||
return errModuleConfigEmpty | ||
} | ||
|
||
if o.ManifestFile == "" { | ||
return errManifestFileEmpty | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (o *Options) validateDirectory() error { | ||
fi, err := os.Stat(o.Directory) | ||
|
||
if err != nil { | ||
if errors.Is(err, os.ErrNotExist) { | ||
return fmt.Errorf("%w: %s", errDirNotExists, o.Directory) | ||
} | ||
return err | ||
} | ||
|
||
if !fi.IsDir() { | ||
return fmt.Errorf("%w: %s", errNotDirectory, o.Directory) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (o *Options) getCompleteFilePath(fileName string) string { | ||
return path.Join(o.Directory, fileName) | ||
} |
Oops, something went wrong.