Skip to content

Commit

Permalink
Merge pull request #44 from srevinsaju/develop
Browse files Browse the repository at this point in the history
v1.6.0
  • Loading branch information
srevinsaju authored Sep 25, 2023
2 parents 3017549 + 677e2b5 commit 88bebc4
Show file tree
Hide file tree
Showing 92 changed files with 2,904 additions and 1,401 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- 'v1'
- 'develop'

permissions:
contents: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ on:
schedule:
- cron: '33 12 * * *'
push:
branches: [ "v1" ]
branches: [ "v1", "develop" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "v1" ]
branches: [ "v1", "develop" ]

env:
# Use docker.io for Docker Hub if empty
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/mdbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- "v1"
- "develop"

jobs:
docs:
Expand All @@ -30,4 +31,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/book
destination_dir: v1
destination_dir: ${{ vars.GITHUB_REF_NAME }}
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ builds:
- amd64
- arm64

release:
prerelease: auto

nfpms:
- maintainer: Srevin Saju
description: A CI/CD which works everywhere, even on your local environment.
Expand Down
49 changes: 32 additions & 17 deletions cmd/togomak/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package main
import (
"fmt"
"github.com/mattn/go-isatty"
"github.com/srevinsaju/togomak/v1/pkg/behavior"
"github.com/srevinsaju/togomak/v1/pkg/cache"
"github.com/srevinsaju/togomak/v1/pkg/conductor"
"github.com/srevinsaju/togomak/v1/pkg/filter"
"github.com/srevinsaju/togomak/v1/pkg/meta"
"github.com/srevinsaju/togomak/v1/pkg/orchestra"
"github.com/srevinsaju/togomak/v1/pkg/path"
"github.com/urfave/cli/v2"
"os"
)
Expand Down Expand Up @@ -158,7 +162,7 @@ func initPipeline(ctx *cli.Context) error {
return nil
}

func newConfigFromCliContext(ctx *cli.Context) orchestra.Config {
func newConfigFromCliContext(ctx *cli.Context) conductor.Config {
owd, err := os.Getwd()
if err != nil {
panic(err)
Expand All @@ -178,28 +182,36 @@ func newConfigFromCliContext(ctx *cli.Context) orchestra.Config {
hostname = "localhost"
}

var stages []orchestra.ConfigPipelineStage
var stages []filter.Item
for _, stage := range ctx.Args().Slice() {
stages = append(stages, orchestra.NewConfigPipelineStage(stage))
stages = append(stages, filter.NewFilterItem(stage))
}
cfg := orchestra.Config{
Owd: owd,
Dir: dir,
cfg := conductor.Config{

Child: ctx.Bool("child"),
Parent: ctx.String("parent"),
ParentParams: ctx.StringSlice("parent-param"),
Behavior: &behavior.Behavior{
Unattended: ctx.Bool("unattended") || ctx.Bool("ci"),
Ci: ctx.Bool("ci"),
DryRun: ctx.Bool("dry-run"),

Ci: ctx.Bool("ci"),
Unattended: ctx.Bool("unattended") || ctx.Bool("ci"),
Child: behavior.Child{
Enabled: ctx.Bool("child"),
Parent: ctx.String("parent"),
ParentParams: ctx.StringSlice("parent-param"),
},
},

Paths: &path.Path{
Pipeline: pipelineFilePath,
Cwd: dir,
Owd: owd,
},
User: os.Getenv("USER"),
Hostname: hostname,
Verbosity: verboseCount,
Pipeline: orchestra.ConfigPipeline{
Stages: stages,
FilePath: pipelineFilePath,
DryRun: ctx.Bool("dry-run"),
Interface: conductor.Interface{Verbosity: verboseCount},
Pipeline: conductor.ConfigPipeline{
Filtered: stages,

DryRun: ctx.Bool("dry-run"),
},
}
return cfg
Expand All @@ -208,7 +220,10 @@ func newConfigFromCliContext(ctx *cli.Context) orchestra.Config {
func run(ctx *cli.Context) error {
cfg := newConfigFromCliContext(ctx)

os.Exit(orchestra.Orchestra(cfg))
t := conductor.NewTogomak(cfg)
v := orchestra.Perform(t)
t.Destroy()
os.Exit(v)
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions examples/functions/togomak.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
togomak {
version = 2
}


stage "home" {
script = "echo ${env("HOME")}"
}

stage "non_existent_env" {
script = "echo ${env("THIS_SHOULD_NOT_EXIST", "env does not exist")}"
}
1 change: 1 addition & 0 deletions examples/git/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ togomak {

data "git" "repo" {
url = "https://github.com/srevinsaju/togomak"
branch = "v1"
files = ["togomak.hcl"]
}

Expand Down
8 changes: 4 additions & 4 deletions examples/hooks/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ stage "example" {
script = "echo hello world"

pre_hook {
stage "echo" {
stage{
script = "echo before the script for stage ${this.id} runs"
}
}

post_hook {
stage "echo" {
stage {
script = "echo the script for ${this.id} done with status ${this.status}"
}
}
Expand All @@ -23,13 +23,13 @@ stage "example_2" {
script = "echo bye world"

pre_hook {
stage "echo" {
stage {
script = "echo before the script for stage ${this.id} runs"
}
}

post_hook {
stage "echo" {
stage {
script = "echo the script for ${this.id} done with status ${this.status}"
}
}
Expand Down
4 changes: 4 additions & 0 deletions examples/import/module/togomak.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
togomak {
version = 2
}

stage "another_stage" {
script = "echo this is coming from module"
}
Expand Down
4 changes: 4 additions & 0 deletions examples/multiple-files/stage1.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
togomak {
version = 2
}

stage "example" {
name = "example"
script = "echo hello world"
Expand Down
4 changes: 4 additions & 0 deletions examples/multiple-files/stage2.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
togomak {
version = 2
}

stage "example_2" {
script = "echo bye world"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
togomak {
version = 1
version = 2
}

stage "echo" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
togomak {
version = 1
version = 2
}

stage "echo" {
Expand Down
6 changes: 3 additions & 3 deletions examples/recursive/togomak.hcl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
togomak {
version = 1
version = 2
}


macro "hello" {
source = "./hello.hcl"
source = "./hello"
}
macro "bye" {
source = "./bye.hcl"
source = "./bye"
}

stage "hello_phase" {
Expand Down
40 changes: 40 additions & 0 deletions pkg/behavior/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package behavior

type Child struct {
// Enabled is the flag to indicate whether the program is running in child mode
Enabled bool

// Parent is the flag to indicate whether the program is running in parent mode
Parent string

// ParentParams is the list of parameters to be passed to the parent
ParentParams []string
}

type Behavior struct {
initialized bool

// Unattended is the flag to indicate whether the program is running in unattended mode
Unattended bool

// Ci is the flag to indicate whether the program is running in CI mode
Ci bool

// Child is the flag to indicate whether the program is running in child mode
Child Child

DryRun bool
}

func NewDefaultBehavior() Behavior {
return Behavior{
Unattended: false,
Ci: false,
DryRun: true,
Child: Child{
Enabled: false,
Parent: "",
ParentParams: []string{},
},
}
}
29 changes: 24 additions & 5 deletions pkg/blocks/data/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package data

import (
"context"
"fmt"
"github.com/hashicorp/hcl/v2"
"github.com/srevinsaju/togomak/v1/pkg/c"
"github.com/srevinsaju/togomak/v1/pkg/global"
"github.com/zclconf/go-cty/cty"
"os"
)
Expand All @@ -20,6 +21,7 @@ type EnvProvider struct {

keyParsed string
def string
defOk bool
ctx context.Context
}

Expand Down Expand Up @@ -48,7 +50,7 @@ func (e *EnvProvider) New() Provider {
}
}

func (e *EnvProvider) Attributes(ctx context.Context, id string) (map[string]cty.Value, hcl.Diagnostics) {
func (e *EnvProvider) Attributes(ctx context.Context, id string, opts ...ProviderOption) (map[string]cty.Value, hcl.Diagnostics) {
return map[string]cty.Value{
EnvProviderAttrKey: cty.StringVal(e.keyParsed),
EnvProviderAttrDefault: cty.StringVal(e.def),
Expand Down Expand Up @@ -76,45 +78,62 @@ func (e *EnvProvider) Schema() *hcl.BodySchema {

}

func (e *EnvProvider) DecodeBody(body hcl.Body) hcl.Diagnostics {
func (e *EnvProvider) DecodeBody(body hcl.Body, opts ...ProviderOption) hcl.Diagnostics {
if !e.initialized {
panic("provider not initialized")
}
var diags hcl.Diagnostics
hclContext := e.ctx.Value(c.TogomakContextHclEval).(*hcl.EvalContext)
hclContext := global.HclEvalContext()

schema := e.Schema()
content, d := body.Content(schema)
diags = diags.Extend(d)

attr := content.Attributes["key"]
var key cty.Value

global.EvalContextMutex.RLock()
key, d = attr.Expr.Value(hclContext)
global.EvalContextMutex.RUnlock()
diags = diags.Extend(d)

e.keyParsed = key.AsString()

attr, ok := content.Attributes["default"]
if !ok {
e.defOk = false
e.def = ""
return diags
}

global.EvalContextMutex.RLock()
key, d = attr.Expr.Value(hclContext)
global.EvalContextMutex.RUnlock()
diags = diags.Extend(d)

e.def = key.AsString()
e.defOk = true

return diags

}

func (e *EnvProvider) Value(ctx context.Context, id string) (string, hcl.Diagnostics) {
func (e *EnvProvider) Value(ctx context.Context, id string, opts ...ProviderOption) (string, hcl.Diagnostics) {
if !e.initialized {
panic("provider not initialized")
}
v, exists := os.LookupEnv(e.keyParsed)
if exists {
return v, nil
}
if !e.defOk {
return "", hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "environment variable not found",
Detail: fmt.Sprintf("environment variable %s not found", e.keyParsed),
},
}
}
return e.def, nil
}
Loading

0 comments on commit 88bebc4

Please sign in to comment.