Skip to content

Commit b8b23d9

Browse files
committed
feat: added parameter to enable/disable deployment tracking
1 parent c6f111b commit b8b23d9

File tree

8 files changed

+52
-38
lines changed

8 files changed

+52
-38
lines changed

.github/workflows/pull-request.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
go-version: ${{ matrix.go-version }}
2020
id: go
2121

22-
- name: Install Task
23-
uses: arduino/setup-task@v1
24-
with:
25-
repo-token: ${{ secrets.GITHUB_TOKEN }}
26-
2722
- name: Set up Go modules cache
2823
uses: actions/cache@v3
2924
env:
@@ -47,7 +42,7 @@ jobs:
4742
args: --issues-exit-code=0
4843

4944
- name: Run tests
50-
run: task cover
45+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
5146

5247
- name: Build binary
5348
uses: goreleaser/goreleaser-action@v3

Taskfile.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ tasks:
55
cmd: golangci-lint run
66

77
build:
8+
env:
9+
GORELEASER_CURRENT_TAG: v0.0.0
810
cmd: goreleaser build --snapshot --single-target --rm-dist --clean
911

1012
test:
1113
cmd: go test -race ./...
12-
13-
cover:
14-
cmd: go test -race -coverprofile=coverage.out -covermode=atomic ./...

internal/config.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ package internal
22

33
// BaseConfig is the base honeycomb config.
44
type BaseConfig struct {
5-
ApiKey string `mapstructure:"api_key"`
6-
DataSet string `mapstructure:"dataset"`
7-
Type string `mapstructure:"type"`
8-
Url string `mapstructure:"url"`
5+
ApiKey string `mapstructure:"api_key"`
6+
DataSet string `mapstructure:"dataset"`
7+
Type string `mapstructure:"type"`
8+
Url string `mapstructure:"url"`
9+
TrackDeployments bool `mapstructure:"track_deployments"`
910
}
1011

1112
type GlobalConfig struct {
1213
BaseConfig `mapstructure:",squash"`
1314
}
1415

1516
type SiteConfig struct {
16-
BaseConfig `mapstructure:",squash"`
17-
Components map[string]*SiteComponentConfig `mapstructure:"-"`
17+
BaseConfig `mapstructure:",squash"`
18+
SiteComponents map[string]*SiteComponentConfig `mapstructure:"-"`
1819
}
1920

2021
func (c *SiteConfig) extendGlobalConfig(g *GlobalConfig) *SiteConfig {
2122
cfg := &SiteConfig{
22-
BaseConfig: g.BaseConfig,
23-
Components: c.Components,
23+
BaseConfig: g.BaseConfig,
24+
SiteComponents: c.SiteComponents,
2425
}
2526

2627
if c.ApiKey != "" {
@@ -36,6 +37,10 @@ func (c *SiteConfig) extendGlobalConfig(g *GlobalConfig) *SiteConfig {
3637
cfg.Url = c.Url
3738
}
3839

40+
if c.TrackDeployments != false {
41+
cfg.TrackDeployments = c.TrackDeployments
42+
}
43+
3944
return cfg
4045
}
4146

@@ -49,9 +54,6 @@ func (c *SiteComponentConfig) extendSiteConfig(s *SiteConfig) *SiteComponentConf
4954
BaseConfig: s.BaseConfig,
5055
}
5156

52-
if c.ApiKey != "" {
53-
cfg.ApiKey = c.ApiKey
54-
}
5557
if c.DataSet != "" {
5658
cfg.DataSet = c.DataSet
5759
}
@@ -62,6 +64,10 @@ func (c *SiteComponentConfig) extendSiteConfig(s *SiteConfig) *SiteComponentConf
6264
cfg.Url = c.Url
6365
}
6466

67+
if c.TrackDeployments != false {
68+
cfg.TrackDeployments = c.TrackDeployments
69+
}
70+
6571
return cfg
6672
}
6773

internal/plugin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (p *HoneycombPlugin) getSiteComponentConfig(site, name string) *SiteCompone
5858
return nil
5959
}
6060

61-
cfg, ok := siteCfg.Components[name]
61+
cfg, ok := siteCfg.SiteComponents[name]
6262
if !ok {
6363
cfg = &SiteComponentConfig{}
6464
}
@@ -100,7 +100,7 @@ func (p *HoneycombPlugin) SetGlobalConfig(data map[string]any) error {
100100

101101
func (p *HoneycombPlugin) SetSiteConfig(site string, data map[string]any) error {
102102
cfg := SiteConfig{
103-
Components: map[string]*SiteComponentConfig{},
103+
SiteComponents: map[string]*SiteComponentConfig{},
104104
}
105105
if err := mapstructure.Decode(data, &cfg); err != nil {
106106
return err
@@ -118,11 +118,11 @@ func (p *HoneycombPlugin) SetSiteComponentConfig(site string, component string,
118118
siteCfg, ok := p.siteConfigs[site]
119119
if !ok {
120120
siteCfg = &SiteConfig{
121-
Components: map[string]*SiteComponentConfig{},
121+
SiteComponents: map[string]*SiteComponentConfig{},
122122
}
123123
p.siteConfigs[site] = siteCfg
124124
}
125-
siteCfg.Components[component] = &cfg
125+
siteCfg.SiteComponents[component] = &cfg
126126

127127
return nil
128128
}

internal/schemas/global-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
},
1414
"url": {
1515
"type": "string"
16+
},
17+
"track_deployments": {
18+
"type": "boolean",
19+
"description": "Whether to track release deployments in Honeycomb.",
20+
"default": false
1621
}
1722
}
1823
}

internal/schemas/site-component-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
},
1414
"url": {
1515
"type": "string"
16+
},
17+
"track_deployments": {
18+
"type": "boolean",
19+
"description": "Whether to track release deployments in Honeycomb.",
20+
"default": false
1621
}
1722
}
1823
}

internal/schemas/site-config.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"type": "object",
33
"description": "Site Honeycomb configuration.",
44
"properties": {
5-
"api_key": {
6-
"type": "string"
7-
},
85
"dataset": {
96
"type": "string"
107
},
@@ -13,6 +10,11 @@
1310
},
1411
"url": {
1512
"type": "string"
13+
},
14+
"track_deployments": {
15+
"type": "boolean",
16+
"description": "Whether to track release deployments in Honeycomb.",
17+
"default": false
1618
}
1719
}
1820
}

internal/templates/resources.tmpl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
resource "honeycombio_marker" "{{ .ComponentName }}" {
2-
dataset = "{{ .Config.DataSet }}"
3-
message = "{{ .Version }}"
4-
{{ if .Config.Type }}
5-
type = "{{ .Config.Type }}"
6-
{{ end }}
7-
{{ if .Config.Url }}
8-
url = "{{ .Config.Url }}"
9-
{{ end }}
1+
{{ if .Config.TrackDeployments }}
2+
resource "honeycombio_marker" "{{ .ComponentName }}" {
3+
dataset = "{{ .Config.DataSet }}"
4+
message = "{{ .Version }}"
5+
{{ if .Config.Type }}
6+
type = "{{ .Config.Type }}"
7+
{{ end }}
8+
{{ if .Config.Url }}
9+
url = "{{ .Config.Url }}"
10+
{{ end }}
1011

11-
depends_on = [module.{{ .ComponentName }}]
12-
}
12+
depends_on = [module.{{ .ComponentName }}]
13+
}
14+
{{ end}}

0 commit comments

Comments
 (0)