Skip to content

Commit a483245

Browse files
authored
feat: adds events for deployments (#105)
1 parent 6d37883 commit a483245

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
deploy:
153153
uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master
154154
needs: [discover, check, build, test, release]
155-
if: (fromJson(needs.discover.outputs.deployments)[0] != null) && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !failure() && !cancelled()
155+
if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled()
156156
with:
157157
deployments: ${{ needs.discover.outputs.deployments }}
158158
forge_version: ${{ inputs.forge_version }}

cli/cmd/cmds/deploy/deploy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/input-output-hk/catalyst-forge/cli/pkg/deployment"
7+
"github.com/input-output-hk/catalyst-forge/cli/pkg/events"
78
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
89
)
910

@@ -17,6 +18,12 @@ func (c *PushCmd) Run(ctx run.RunContext) error {
1718
return fmt.Errorf("could not load project: %w", err)
1819
}
1920

21+
eh := events.NewDefaultEventHandler(ctx.Logger)
22+
if !eh.Firing(&project, project.GetDeploymentEvents()) {
23+
ctx.Logger.Info("No deployment event is firing, skipping deployment")
24+
return nil
25+
}
26+
2027
deployer := deployment.NewGitopsDeployer(&project, &ctx.SecretStore, ctx.Logger)
2128
if err := deployer.Load(); err != nil {
2229
return fmt.Errorf("could not load deployer: %w", err)

foundry/api/blueprint.cue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ project: {
1414
}
1515
}
1616
deployment: {
17+
on: {
18+
merge: {}
19+
tag: {}
20+
}
1721
environment: "dev"
1822
modules: main: {
1923
container: "foundry-api-deployment"
2024
version: "0.1.1"
2125
values: {
2226
environment: name: "dev"
2327
server: image: {
24-
tag: _ @forge(name="GIT_COMMIT_HASH")
28+
tag: _ @forge(name="GIT_HASH_OR_TAG")
2529
}
2630
}
2731
}

lib/project/project/project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ func (p *Project) GetRelativePath() (string, error) {
8181
return relPath, nil
8282
}
8383

84+
// GetDeploymentEvents returns the deployment events for a project.
85+
func (p *Project) GetDeploymentEvents() map[string]cue.Value {
86+
events := make(map[string]cue.Value)
87+
for event := range p.Blueprint.Project.Deployment.On {
88+
config := p.RawBlueprint.Get(fmt.Sprintf("project.deployment.on.%s", event))
89+
events[event] = config
90+
}
91+
92+
return events
93+
}
94+
8495
// GetReleaseEvents returns the release events for a release.
8596
func (p *Project) GetReleaseEvents(releaseName string) map[string]cue.Value {
8697
release, ok := p.Blueprint.Project.Release[releaseName]

lib/project/schema/_embed/schema.cue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ package schema
193193
string
194194
} @go(Environment)
195195

196+
// On contains the events that trigger the deployment.
197+
on: {
198+
...
199+
} @go(On,map[string]any)
200+
196201
// Modules contains the configuration for the deployment modules for the project.
197202
// +optional
198203
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)

lib/project/schema/deployment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ type Deployment struct {
55
// Environment contains the environment to deploy the module to.
66
Environment string `json:"environment"`
77

8+
// On contains the events that trigger the deployment.
9+
On map[string]any `json:"on"`
10+
811
// Modules contains the configuration for the deployment modules for the project.
912
// +optional
1013
Modules *DeploymentModules `json:"modules"`

lib/project/schema/deployment_go_gen.cue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ package schema
99
// Environment contains the environment to deploy the module to.
1010
environment: string @go(Environment)
1111

12+
// On contains the events that trigger the deployment.
13+
on: {...} @go(On,map[string]any)
14+
1215
// Modules contains the configuration for the deployment modules for the project.
1316
// +optional
1417
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)

0 commit comments

Comments
 (0)