Skip to content

Commit

Permalink
Fix depends_on (#77)
Browse files Browse the repository at this point in the history
* Attempt to fix depends_on, which can be an array or a string.

* Update test

* More test fixes.

* More fixes.

* Final test fixes.

* Version bump.

* Tabs instead of spaces
  • Loading branch information
TBoshoven committed May 11, 2021
1 parent 71edc9a commit 1e66bcd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog

0.9.4 (TBoshoven)
-----------------

1. Fix space-separation in step keys.
2. Fix parsing when `depends_on` is a string instead of an array.

0.9.3 (boyntoni)
----------------

1. Generate unique keys for project steps, and add support for depends_on.
1. Generate unique keys for project steps, and add support for `depends_on`.


0.9.2 (mowies)
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.9.3:
- jwplayer/buildpipe#v0.9.4:
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.9.3}"
buildpipe_version="${BUILDKITE_PLUGIN_BUILDPIPE_VERSION:-0.9.4}"
is_test="${BUILDKITE_PLUGIN_BUILDPIPE_TEST_MODE:-false}"

if [[ "$is_test" == "false" ]]; then
Expand Down
11 changes: 8 additions & 3 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ func generateProjectSteps(steps []interface{}, step interface{}, projects []Proj

// Unique project level key, if present
if val, ok := stepCopyMap["key"]; ok {
stepCopyMap["key"] = fmt.Sprintf("%s %s", val, project.Label)
stepCopyMap["key"] = fmt.Sprintf("%s:%s", val, project.Label)
}

// If the step includes a depends_on clause, we need to validate whether each dependency
// is a project-scoped step. If so, the dependency has the current project name added
// to it to match the unique key given above.
if val, ok := stepCopyMap["depends_on"]; ok {
dependencyList := val.([]interface{})
// depends_on can be an array or a string
dependencyList, ok := val.([]interface{})
if !ok {
dependencyList = []interface{}{val}
stepCopyMap["depends_on"] = dependencyList
}

for i, dependency := range dependencyList {
depStr := dependency.(string)

if step := findStepByKey(steps, depStr); step != nil {
if isProjectScopeStep(step) {
dependencyList[i] = fmt.Sprintf("%s %s", depStr, project.Label)
dependencyList[i] = fmt.Sprintf("%s:%s", depStr, project.Label)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/dynamic_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ steps: # the same schema as regular buildkite pipeline steps
branches: "master"
concurrency: 1
concurrency_group: deploy-prd
depends_on:
- deploy-stg
depends_on: deploy-stg
env:
BUILDPIPE_SCOPE: project
command:
Expand Down
10 changes: 5 additions & 5 deletions tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ steps:
BUILDPIPE_SCOPE: project
TEST_ENV_PIPELINE: test-pipeline
TEST_ENV_PROJECT: test-project
key: test project1
key: test:project1
label: test project1
- wait
- agents:
Expand All @@ -61,7 +61,7 @@ steps:
- make publish-image
depends_on:
- bootstrap
- test project1
- test:project1
env:
BUILDPIPE_PROJECT_LABEL: project1
BUILDPIPE_PROJECT_PATH: project1/
Expand All @@ -79,7 +79,7 @@ steps:
- make publish-image
depends_on:
- bootstrap
- test project2
- test:project2
env:
BUILDPIPE_PROJECT_LABEL: project2
BUILDPIPE_PROJECT_PATH: project2/
Expand All @@ -106,7 +106,7 @@ steps:
BUILDPIPE_PROJECT_PATH: project2/
BUILDPIPE_SCOPE: project
TEST_ENV_PIPELINE: test-pipeline
key: deploy-stg project2
key: deploy-stg:project2
label: deploy-stg project2
- wait
- block: ':rocket: Release!'
Expand All @@ -119,7 +119,7 @@ steps:
concurrency: 1
concurrency_group: deploy-prd
depends_on:
- deploy-stg project2
- deploy-stg:project2
env:
BUILDPIPE_PROJECT_LABEL: project2
BUILDPIPE_PROJECT_PATH: project2/
Expand Down

0 comments on commit 1e66bcd

Please sign in to comment.