Skip to content

Commit

Permalink
Merge branch 'main' into fix-tests-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha authored Nov 25, 2024
2 parents 0993219 + 4b30800 commit c75b43a
Show file tree
Hide file tree
Showing 213 changed files with 2,276 additions and 953 deletions.
123 changes: 123 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
language: "en-US"
tone_instructions: "Maintain a conversational spartan tone that is supportive in all responses."
early_access: true
enable_free_tier: true
reviews:
profile: "chill"
request_changes_workflow: true
high_level_summary: true
high_level_summary_placeholder: "@auto-summary"
auto_title_placeholder: "@auto-title"
review_status: false
commit_status: false
poem: false
collapse_walkthrough: true
sequence_diagrams: true
changed_files_summary: true
labeling_instructions:
- label: "patch"
instructions: "Apply when the PR contains changes that fix existing functionality."
- label: "minor"
instructions: "Apply when changes introduce new functionality but are non-breaking."
- label: "major"
instructions: "Apply when changes introduce new functionality that causes breaking changes requiring the user to update their configuration."
- label: "no-release"
instructions: "Apply this label when the PR contains changes only to documentation, website content, or other non-Go code. Changes that do not affect the Go code or the application functionality fall under this category."
#path_filters:
# - "!dist/**"
# - "src/**"
#path_instructions:
# - path: "**/*.js"
# instructions: "Check for consistent coding styles and ES6+ syntax adherence."
abort_on_close: true
auto_review:
enabled: true
auto_incremental_review: true
ignore_title_keywords:
- "WIP"
- "test"
#labels:
# - "ready-for-review"
drafts: false
base_branches:
- "main"
tools:
ast-grep:
rule_dirs:
- "rules"
util_dirs:
- "utils"
essential_rules: true
packages:
- "javascript"
- "typescript"
shellcheck:
enabled: true
ruff:
enabled: true
markdownlint:
enabled: true
github-checks:
enabled: true
timeout_ms: 90000
languagetool:
enabled: true
enabled_rules:
- "EN_QUOTES"
level: "picky"
biome:
enabled: true
hadolint:
enabled: true
swiftlint:
enabled: false
config_file: ".swiftlint.yml"
phpstan:
enabled: true
level: "max"
golangci-lint:
enabled: true
config_file: ".golangci.yaml"
yamllint:
enabled: true
gitleaks:
enabled: true
checkov:
enabled: true
detekt:
enabled: false
config_file: "detekt.yml"
eslint:
enabled: true
rubocop:
enabled: false
buf:
enabled: true
regal:
enabled: true
actionlint:
enabled: true
pmd:
enabled: false
config_file: "pmd.xml"
cppcheck:
enabled: false
semgrep:
enabled: false
config_file: ".semgrep.yaml"
circleci:
enabled: false
chat:
auto_reply: true
knowledge_base:
opt_out: false
learnings:
scope: "auto"
issues:
scope: "auto"
linear:
team_keys:
- "DEV"
pull_requests:
scope: "auto"
35 changes: 33 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,43 @@ jobs:
--config=${{ github.workspace }}/examples/.tflint.hcl
fail_on_error: true

# run other demo tests
validate:
name: "[validate] ${{ matrix.demo-folder }}"
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
demo-folder:
- demo-context
- demo-localstack
- demo-stacks
- demo-helmfile
- quick-start-advanced
- quick-start-simple

timeout-minutes: 20
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Validate YAML Schema
uses: InoUno/[email protected]
with:
root: "examples/${{ matrix.demo-folder }}/stacks"
schemaMapping: |
{
"https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json": [
"examples/${{ matrix.demo-folder }}/stacks/**/*.yaml",
"examples/${{ matrix.demo-folder }}/stacks/**/*.yml"
]
}
release:
needs: [test, lint, mock, k3s, localstack, docker]
needs: [test, lint, mock, k3s, localstack, docker, validate]
if: github.event_name == 'push'
uses: cloudposse/.github/.github/workflows/shared-go-auto-release.yml@main
with:
publish: false
format: binary
secrets: inherit

19 changes: 18 additions & 1 deletion atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "./examples/quick-start-advanced"
base_path: "./"

vendor:
# Path to vendor configuration file or directory containing vendor files
# Supports both absolute and relative paths
# If a directory is specified, all .yaml files in the directory will be processed in lexicographical order
# Can also be set using 'ATMOS_VENDOR_BASE_PATH' ENV var, or '--vendor-base-path' command-line argument
# Examples:
# base_path: "./vendor.yaml" # Single file
# base_path: "./vendor.d/" # Directory containing multiple .yaml files
base_path: "./vendor.yaml"

components:
terraform:
Expand Down Expand Up @@ -297,6 +307,13 @@ integrations:
steps:
- run: terraform apply $PLANFILE

# GitHub integration
github:
gitops:
opentofu-version: 1.8.4
terraform-version: 1.9.8
infracost-enabled: false

# Validation schemas (for validating atmos stacks and components)
schemas:
# https://json-schema.org
Expand Down
26 changes: 22 additions & 4 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -164,11 +165,28 @@ func preCustomCommand(
parentCommand *cobra.Command,
commandConfig *schema.Command,
) {
var err error

var sb strings.Builder
if len(args) != len(commandConfig.Arguments) {
err = fmt.Errorf("invalid number of arguments, %d argument(s) required", len(commandConfig.Arguments))
u.LogErrorAndExit(schema.CliConfiguration{}, err)
if len(commandConfig.Arguments) == 0 {
u.LogError(schema.CliConfiguration{}, errors.New("invalid command"))
sb.WriteString("Available command(s):\n")
for i, c := range commandConfig.Commands {
sb.WriteString(fmt.Sprintf("%d. %s %s %s\n", i+1, parentCommand.Use, commandConfig.Name, c.Name))
}
u.LogInfo(schema.CliConfiguration{}, sb.String())
os.Exit(1)
}
sb.WriteString(fmt.Sprintf("Command requires %d argument(s):\n", len(commandConfig.Arguments)))
for i, arg := range commandConfig.Arguments {
if arg.Name == "" {
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New("invalid argument configuration: empty argument name"))
}
sb.WriteString(fmt.Sprintf(" %d. %s\n", i+1, arg.Name))
}
if len(args) > 0 {
sb.WriteString(fmt.Sprintf("\nReceived %d argument(s): %s", len(args), strings.Join(args, ", ")))
}
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New(sb.String()))
}

// no "steps" means a sub command should be specified
Expand Down
2 changes: 2 additions & 0 deletions cmd/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ func init() {

describeStacksCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command: atmos describe stacks --process-templates=false")

describeStacksCmd.PersistentFlags().Bool("include-empty-stacks", false, "Include stacks with no components in the output: atmos describe stacks --include-empty-stacks")

describeCmd.AddCommand(describeStacksCmd)
}
41 changes: 34 additions & 7 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"runtime"

"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
"golang.org/x/term"

cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
Expand Down Expand Up @@ -37,26 +39,41 @@ var docsCmd = &cobra.Command{
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}

// Detect terminal width if not specified in `atmos.yaml`
// The default screen width is 120 characters, but uses maxWidth if set and greater than zero
maxWidth := cliConfig.Settings.Docs.MaxWidth
defaultWidth := 120
screenWidth := defaultWidth

// Detect terminal width and use it by default if available
if term.IsTerminal(int(os.Stdout.Fd())) {
termWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
if err == nil && termWidth > 0 {
// Adjusted for subtle padding effect at the terminal boundaries
screenWidth = termWidth - 2
}
}

if maxWidth > 0 {
screenWidth = min(maxWidth, screenWidth)
}

// Construct the full path to the Terraform component by combining the Atmos base path, Terraform base path, and component name
componentPath := path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, info.Component)

componentPathExists, err := u.IsDirectory(componentPath)
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}
if !componentPathExists {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'",
info.Component,
componentPath,
))
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath))
}

readmePath := path.Join(componentPath, "README.md")
if _, err := os.Stat(readmePath); err != nil {
if os.IsNotExist(err) {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("No README found for component: %s", info.Component))
} else {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("Component %s not found", info.Component))
}
}

Expand All @@ -65,7 +82,17 @@ var docsCmd = &cobra.Command{
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}

componentDocs, err := glamour.Render(string(readmeContent), "dark")
r, err := glamour.NewTermRenderer(
glamour.WithColorProfile(lipgloss.ColorProfile()),
glamour.WithAutoStyle(),
glamour.WithPreservedNewLines(),
glamour.WithWordWrap(screenWidth),
)
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("failed to initialize markdown renderer: %w", err))
}

componentDocs, err := r.Render(string(readmeContent))
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/pflag"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/internal/tui/templates"
tuiUtils "github.com/cloudposse/atmos/internal/tui/utils"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
Expand Down Expand Up @@ -107,12 +108,17 @@ func Execute() error {
}

func init() {
// Add template function for wrapped flag usages
cobra.AddTemplateFunc("wrappedFlagUsages", templates.WrappedFlagUsages)

RootCmd.PersistentFlags().String("redirect-stderr", "", "File descriptor to redirect 'stderr' to. "+
"Errors can be redirected to any file or any standard file descriptor (including '/dev/null'): atmos <command> --redirect-stderr /dev/stdout")

RootCmd.PersistentFlags().String("logs-level", "Info", "Logs level. Supported log levels are Trace, Debug, Info, Warning, Off. If the log level is set to Off, Atmos will not log any messages")
RootCmd.PersistentFlags().String("logs-file", "/dev/stdout", "The file to write Atmos logs to. Logs can be written to any file or any standard file descriptor, including '/dev/stdout', '/dev/stderr' and '/dev/null'")

// Set custom usage template
templates.SetCustomUsageFunc(RootCmd)
cobra.OnInitialize(initConfig)
}

Expand All @@ -131,6 +137,7 @@ func initConfig() {
}

b.HelpFunc(command, strings)
command.Usage()
})
}

Expand Down
Loading

0 comments on commit c75b43a

Please sign in to comment.