diff --git a/e2e/actions/artifacts/.halfpipe.io b/e2e/actions/artifacts/.halfpipe.io index 0a4fb255..8bda9cdb 100644 --- a/e2e/actions/artifacts/.halfpipe.io +++ b/e2e/actions/artifacts/.halfpipe.io @@ -2,6 +2,11 @@ team: halfpipe-team pipeline: artifacts platform: actions +triggers: +- type: git + watched_paths: + - e2e/actions/artifacts + tasks: - type: run name: build diff --git a/e2e/actions/artifacts/workflowExpected.yml b/e2e/actions/artifacts/workflowExpected.yml index 36c46995..bfc8c764 100644 --- a/e2e/actions/artifacts/workflowExpected.yml +++ b/e2e/actions/artifacts/workflowExpected.yml @@ -4,6 +4,9 @@ name: artifacts push: branches: - main + paths: + - e2e/actions/artifacts** + - .github/workflows/artifacts.yml workflow_dispatch: {} env: ARTIFACTORY_PASSWORD: ${{ secrets.EE_ARTIFACTORY_PASSWORD }} diff --git a/e2e/actions/consumer-integration-test/.halfpipe.io b/e2e/actions/consumer-integration-test/.halfpipe.io index 58f4a6d3..697b4ad5 100644 --- a/e2e/actions/consumer-integration-test/.halfpipe.io +++ b/e2e/actions/consumer-integration-test/.halfpipe.io @@ -2,6 +2,11 @@ team: halfpipe-team pipeline: pipeline-name platform: actions +triggers: +- type: git + watched_paths: + - . + tasks: - type: consumer-integration-test name: c-name diff --git a/e2e/actions/consumer-integration-test/workflowExpected.yml b/e2e/actions/consumer-integration-test/workflowExpected.yml index 61948a0e..654093c0 100644 --- a/e2e/actions/consumer-integration-test/workflowExpected.yml +++ b/e2e/actions/consumer-integration-test/workflowExpected.yml @@ -4,6 +4,9 @@ name: pipeline-name push: branches: - main + paths: + - e2e/actions/consumer-integration-test** + - .github/workflows/pipeline-name.yml workflow_dispatch: {} env: ARTIFACTORY_PASSWORD: ${{ secrets.EE_ARTIFACTORY_PASSWORD }} diff --git a/e2e/concourse/artifacts/.halfpipe.io b/e2e/concourse/artifacts/.halfpipe.io index 3fbaa836..1833ae31 100644 --- a/e2e/concourse/artifacts/.halfpipe.io +++ b/e2e/concourse/artifacts/.halfpipe.io @@ -4,7 +4,7 @@ pipeline: halfpipe-e2e-artifacts triggers: - type: git watched_paths: - - e2e/concourse/artifacts + - . tasks: - type: run diff --git a/mapper/git_trigger.go b/mapper/git_trigger.go new file mode 100644 index 00000000..1302e0ef --- /dev/null +++ b/mapper/git_trigger.go @@ -0,0 +1,34 @@ +package mapper + +import ( + "github.com/springernature/halfpipe/manifest" +) + +type gitTriggerMapper struct { +} + +func (g gitTriggerMapper) Apply(original manifest.Manifest) (updated manifest.Manifest, err error) { + updated = original + updated.Triggers = g.updateGitTrigger(updated.Triggers) + return updated, nil +} + +func (g gitTriggerMapper) updateGitTrigger(triggerList manifest.TriggerList) (updated manifest.TriggerList) { + for _, trigger := range triggerList { + switch trigger := trigger.(type) { + case manifest.GitTrigger: + for i, path := range trigger.WatchedPaths { + if path == "." { + trigger.WatchedPaths[i] = trigger.BasePath + } + } + updated = append(updated, trigger) + default: + updated = append(updated, trigger) + } + } + return +} +func NewGitTriggerMapper() Mapper { + return gitTriggerMapper{} +} diff --git a/mapper/git_trigger_test.go b/mapper/git_trigger_test.go new file mode 100644 index 00000000..3af71add --- /dev/null +++ b/mapper/git_trigger_test.go @@ -0,0 +1,56 @@ +package mapper + +import ( + "github.com/springernature/halfpipe/manifest" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestGitTriggerMapper_Apply(t *testing.T) { + t.Run("does nothing on empty manifest", func(t *testing.T) { + input := manifest.Manifest{} + expected := manifest.Manifest{} + + updated, err := NewGitTriggerMapper().Apply(input) + + assert.NoError(t, err) + assert.Equal(t, expected, updated) + }) + + t.Run("does nothing when there is no dot in the watched paths", func(t *testing.T) { + input := manifest.Manifest{ + Triggers: manifest.TriggerList{ + manifest.GitTrigger{WatchedPaths: []string{"a", "b"}}, + }, + } + expected := manifest.Manifest{ + Triggers: manifest.TriggerList{ + manifest.GitTrigger{WatchedPaths: []string{"a", "b"}}, + }, + } + + updated, err := NewGitTriggerMapper().Apply(input) + + assert.NoError(t, err) + assert.Equal(t, expected, updated) + }) + + t.Run("converts dots to base path", func(t *testing.T) { + input := manifest.Manifest{ + Triggers: manifest.TriggerList{ + manifest.GitTrigger{WatchedPaths: []string{"a", "."}, BasePath: "some/path/to/something"}, + }, + } + expected := manifest.Manifest{ + Triggers: manifest.TriggerList{ + manifest.GitTrigger{WatchedPaths: []string{"a", "some/path/to/something"}, BasePath: "some/path/to/something"}, + }, + } + + updated, err := NewGitTriggerMapper().Apply(input) + + assert.NoError(t, err) + assert.Equal(t, expected, updated) + }) + +} diff --git a/mapper/mapper.go b/mapper/mapper.go index 5736c8e0..91711284 100644 --- a/mapper/mapper.go +++ b/mapper/mapper.go @@ -31,6 +31,7 @@ func New() Mapper { NewUpdatePipelineMapper(), NewNotificationsMapper(), NewCfMapper(), + NewGitTriggerMapper(), }, } }