Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for for_each meta argument #48

Merged
merged 6 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Add support for `for_each` meta argument
16 changes: 8 additions & 8 deletions examples/demo/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ togomak {
}

data "prompt" "repo_name" {
prompt = "enter repo name: "
prompt = "enter repo name: "
default = "username/repo"
}

locals {
repo = "srevinsaju/togomak"
lint_tools = ["misspell", "golangci-lint", "abcgo"]
repo = "srevinsaju/togomak"
lint_tools = ["misspell", "golangci-lint", "abcgo"]
build_types = ["amd64", "i386", "arm64"]
}

stage "lint" {
script = <<-EOT
echo 💅 running style checks for repo ${local.repo}
%{ for tool in local.lint_tools }
%{for tool in local.lint_tools}
echo "* running linter: ${tool}"
sleep 1
%{ endfor }
%{endfor}
EOT
}


stage "build" {
script = <<-EOT
echo 👷 running ${ansifmt("green", "build")}
%{ for arch in local.build_types }
%{for arch in local.build_types}
echo "* building ${local.repo} for ${arch}..."
sleep 1
%{ endfor }
%{endfor}
EOT
}

stage "deploy" {
if = data.prompt.repo_name.value == "srevinsaju/togomak"
if = data.prompt.repo_name.value == "srevinsaju/togomak"
depends_on = [stage.build]
container {
image = "hashicorp/terraform"
Expand Down
2 changes: 1 addition & 1 deletion examples/docker-entrypoint/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ togomak {

stage "apt" {
container {
image = "ubuntu:latest"
image = "ubuntu:latest"
entrypoint = ["apt"]
}
args = ["install"]
Expand Down
21 changes: 21 additions & 0 deletions examples/for-each-map/togomak.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
togomak {
version = 2
}

locals {
m = {
part1 = "You Are (Not) Alone."
part2 = "You Can (Not) Advance."
part3 = "You Can (Not) Redo."
part3-1 = "Thrice Upon a Time."
}
}


stage "movie" {
for_each = local.m
name = "example"
script = <<-EOT
echo "Evangelion ${each.key}: ${each.value}"
EOT
}
4 changes: 2 additions & 2 deletions examples/git/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ togomak {
}

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

stage "example" {
Expand Down
6 changes: 3 additions & 3 deletions examples/hooks/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ togomak {

stage "example" {
script = "echo hello world"

pre_hook {
stage{
stage {
script = "echo before the script for stage ${this.id} runs"
}
}
Expand All @@ -21,7 +21,7 @@ stage "example" {

stage "example_2" {
script = "echo bye world"

pre_hook {
stage {
script = "echo before the script for stage ${this.id} runs"
Expand Down
2 changes: 1 addition & 1 deletion examples/lifecycles/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stage "normal" {
}

stage "dont_execute" {
if = false
if = false
script = "echo this shouldnt be executed && exit 1"
}

Expand Down
2 changes: 1 addition & 1 deletion examples/pre-post/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ stage "example" {

stage "example_2" {
depends_on = [stage.example]
script = "echo hello world 2"
script = "echo hello world 2"
}
2 changes: 1 addition & 1 deletion examples/terraform/togomak.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ togomak {
}

data "tf" "this" {
source = "."
source = "."
allow_apply = true
}

Expand Down
17 changes: 5 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/bcicen/jstream v1.0.1
github.com/bmatcuk/doublestar v1.1.5
github.com/creack/pty v1.1.18
github.com/docker/cli v24.0.6+incompatible
github.com/docker/docker v24.0.2+incompatible
github.com/docker/go-connections v0.4.0
github.com/fatih/color v1.15.0
Expand All @@ -33,6 +32,8 @@ require (
github.com/zclconf/go-cty-yaml v1.0.3
golang.org/x/crypto v0.11.0
golang.org/x/text v0.11.0
google.golang.org/grpc v1.50.1
google.golang.org/protobuf v1.28.1
)

require (
Expand All @@ -45,7 +46,6 @@ require (
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -54,20 +54,13 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.14 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.100.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

require (
Expand All @@ -81,7 +74,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/djherbis/buffer v1.2.0 // indirect
github.com/djherbis/nio/v3 v3.0.1 // indirect
Expand Down Expand Up @@ -143,6 +136,6 @@ require (
gotest.tools/v3 v3.4.0 // indirect
)

replace github.com/sirupsen/logrus v1.9.0 => github.com/srevinsaju/logrus v1.10.2-0.20230616201049-4e5a7636a82f
replace github.com/sirupsen/logrus v1.9.0 => github.com/srevinsaju/logrus v1.10.3-0.20231014192105-f54cbb8bc619

replace github.com/sirupsen/logrus v1.9.2 => github.com/srevinsaju/logrus v1.10.2-0.20230616201049-4e5a7636a82f
replace github.com/sirupsen/logrus v1.9.2 => github.com/srevinsaju/logrus v1.10.3-0.20231014192105-f54cbb8bc619
17 changes: 2 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ github.com/djherbis/buffer v1.2.0 h1:PH5Dd2ss0C7CRRhQCZ2u7MssF+No9ide8Ye71nPHcrQ
github.com/djherbis/buffer v1.2.0/go.mod h1:fjnebbZjCUpPinBRD+TDwXSOeNQ7fPQWLfGQqiAiUyE=
github.com/djherbis/nio/v3 v3.0.1 h1:6wxhnuppteMa6RHA4L81Dq7ThkZH8SwnDzXDYy95vB4=
github.com/djherbis/nio/v3 v3.0.1/go.mod h1:Ng4h80pbZFMla1yKzm61cF0tqqilXZYrogmWgZxOcmg=
github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWTcc7GAneOY=
github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v24.0.2+incompatible h1:eATx+oLz9WdNVkQrr0qjQ8HvRJ4bOOxfzEo8R+dA3cg=
Expand Down Expand Up @@ -406,8 +404,6 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20230111200839-76d1ae5aea2b h1:8htHrh2bw9c7Idkb7YNac+ZpTqLMjRpI+FWu51ltaQc=
github.com/google/pprof v0.0.0-20230111200839-76d1ae5aea2b/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -520,8 +516,6 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
Expand Down Expand Up @@ -581,8 +575,8 @@ github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:s
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/srevinsaju/logrus v1.10.2-0.20230616201049-4e5a7636a82f h1:fqDRPqbyG4oiL4x03rD5xxnOPTuKScc1Azs3e6xVFb4=
github.com/srevinsaju/logrus v1.10.2-0.20230616201049-4e5a7636a82f/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/srevinsaju/logrus v1.10.3-0.20231014192105-f54cbb8bc619 h1:YDqV1sOerHY5It8hZRqRpRWSKjaKSmbhxp5cjvMtsGY=
github.com/srevinsaju/logrus v1.10.3-0.20231014192105-f54cbb8bc619/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand All @@ -608,13 +602,6 @@ github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
1 change: 1 addition & 0 deletions pkg/ci/runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

const ThisBlock = "this"
const EachBlock = "each"

type Retryable interface {
// CanRetry decides if the runnable can be retried
Expand Down
4 changes: 2 additions & 2 deletions pkg/ci/stage_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (s *Stage) BeforeRun(ctx context.Context, opts ...runnable.Option) hcl.Diag

for _, hook := range s.PreHook {
diags = diags.Extend(
(&Stage{fmt.Sprintf("%s.pre", s.Identifier()), hook.Stage, nil}).Run(ctx, opts...),
(&Stage{fmt.Sprintf("%s.pre", s.Id), nil, hook.Stage, nil}).Run(ctx, opts...),
)
}
return diags
Expand All @@ -31,7 +31,7 @@ func (s *Stage) AfterRun(ctx context.Context, opts ...runnable.Option) hcl.Diagn

for _, hook := range s.PostHook {
diags = diags.Extend(
(&Stage{fmt.Sprintf("%s.pre", s.Identifier()), hook.Stage, nil}).Run(ctx, opts...),
(&Stage{fmt.Sprintf("%s.pre", s.Id), nil, hook.Stage, nil}).Run(ctx, opts...),
)
}
return diags
Expand Down
Loading
Loading