Skip to content

Commit

Permalink
Allow notifications (#93)
Browse files Browse the repository at this point in the history
* Allow notifications

* bump version
  • Loading branch information
oallenj authored Jul 17, 2023
1 parent d25d553 commit d7e375c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

0.10.3 (oallenj)
------------------

1. Allow buildpipe to use buildkite's notification.

0.10.2 (oallenj)
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Example
steps:
- label: ":buildkite:"
plugins:
- jwplayer/buildpipe#v0.10.2:
- jwplayer/buildpipe#v0.10.3:
dynamic_pipeline: dynamic_pipeline.yml
```
Expand Down
2 changes: 1 addition & 1 deletion hooks/command
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

buildpipe_version="${BUILDKITE_PLUGIN_BUILDPIPE_VERSION:-0.10.2}"
buildpipe_version="${BUILDKITE_PLUGIN_BUILDPIPE_VERSION:-0.10.3}"
is_test="${BUILDKITE_PLUGIN_BUILDPIPE_TEST_MODE:-false}"

if [[ "$is_test" == "false" ]]; then
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
Projects []Project `yaml:"projects"`
Steps []interface{} `yaml:"steps"`
Env map[string]string `yaml:"env"`
Notify []interface{} `yaml:"notify"`
}

func NewConfig(filename string) *Config {
Expand Down Expand Up @@ -54,7 +55,7 @@ func projectsFromBuildProjects(buildProjects string, projects []Project) []Proje
for _, projectName := range projectNames {
for _, configProject := range projects {
if projectName == configProject.Label {
affectedProjects = append(affectedProjects, configProject)
affectedProjects = append(affectedProjects, configProject)
}
}
}
Expand All @@ -71,7 +72,7 @@ func main() {
log.SetLevel(ll)

config := NewConfig(os.Getenv(pluginPrefix + "DYNAMIC_PIPELINE"))
buildProjects := os.Getenv(pluginPrefix+"BUILD_PROJECTS")
buildProjects := os.Getenv(pluginPrefix + "BUILD_PROJECTS")

var affectedProjects []Project
if len(buildProjects) > 0 {
Expand All @@ -90,7 +91,7 @@ func main() {
}
}

pipeline := generatePipeline(config.Steps, config.Env, affectedProjects)
pipeline := generatePipeline(config.Steps, config.Notify, config.Env, affectedProjects)

uploadPipeline(*pipeline)
}
8 changes: 5 additions & 3 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

type Pipeline struct {
Steps []interface{} `yaml:"steps"`
Steps []interface{} `yaml:"steps"`
Notify []interface{} `yaml:"notify,omitempty"`
}

func generateProjectSteps(steps []interface{}, step interface{}, projects []Project) []interface{} {
Expand Down Expand Up @@ -92,7 +93,7 @@ func findStepByKey(steps []interface{}, stepKey string) map[interface{}]interfac
return nil
}

func generatePipeline(steps []interface{}, pipelineEnv map[string]string, projects []Project) *Pipeline {
func generatePipeline(steps []interface{}, notify []interface{}, pipelineEnv map[string]string, projects []Project) *Pipeline {
generatedSteps := make([]interface{}, 0)

for _, step := range steps {
Expand Down Expand Up @@ -127,7 +128,8 @@ func generatePipeline(steps []interface{}, pipelineEnv map[string]string, projec
}

return &Pipeline{
Steps: generatedSteps,
Steps: generatedSteps,
Notify: notify,
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/dynamic_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ steps: # the same schema as regular buildkite pipeline steps
command:
- cd $$BUILDPIPE_PROJECT_PATH
- make deploy-prod
notify:
- email: "[email protected]"
2 changes: 2 additions & 0 deletions tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,7 @@ steps:
BUILDPIPE_SCOPE: project
TEST_ENV_PIPELINE: test-pipeline
label: deploy-prd project2
notify:
- email: [email protected]
EOM
}

0 comments on commit d7e375c

Please sign in to comment.