From cd446e4de181e393d25a7363470efe30ac11810c Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Fri, 17 Jan 2025 12:39:47 -0800 Subject: [PATCH 1/2] feat(cli): performs dry-runs on deployments --- .github/workflows/ci.yml | 24 +++++++------- .github/workflows/deploy.yml | 8 ++--- .github/workflows/docs.yml | 8 ++--- .github/workflows/release.yml | 8 ++--- .github/workflows/run.yml | 8 ++--- cli/cmd/cmds/deploy/{deploy.go => push.go} | 7 ++-- cli/pkg/deployment/gitops.go | 37 ++++++++++++++-------- cli/pkg/deployment/kcl.go | 2 +- cli/pkg/deployment/kcl_test.go | 4 +-- foundry/api/blueprint.cue | 10 +++--- 10 files changed, 63 insertions(+), 53 deletions(-) rename cli/cmd/cmds/deploy/{deploy.go => push.go} (89%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8407571..811f1125 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,12 +41,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@master + uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@master + uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -61,14 +61,14 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@master + uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run with: skip_docker: 'true' skip_github: 'true' skip_earthly: ${{ steps.local.outputs.skip }} - name: Discovery id: discovery - uses: input-output-hk/catalyst-forge/actions/discovery@master + uses: input-output-hk/catalyst-forge/actions/discovery@deploy-dry-run with: filters: | ${{ env.FORGE_REGEX_CHECK }} @@ -80,7 +80,7 @@ jobs: ${{ env.FORGE_REGEX_PUBLISH }} check: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run needs: [discover] if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -92,7 +92,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} build: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run needs: [discover, check] if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -104,7 +104,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} package: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run needs: [discover, check, build] if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -116,7 +116,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} test: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run needs: [discover, check, build, package] if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -128,7 +128,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} docs: - uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@deploy-dry-run needs: [discover, check, build, test] if: (fromJson(needs.discover.outputs.earthfiles)['^docs(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -138,7 +138,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} release: - uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@deploy-dry-run needs: [discover, check, build, test] if: (fromJson(needs.discover.outputs.releases)[0] != null) && !failure() && !cancelled() with: @@ -150,7 +150,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} deploy: - uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master + uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@deploy-dry-run needs: [discover, check, build, test, release] if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() with: @@ -162,7 +162,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} final: - needs: [check, build, package, test, release] + needs: [check, build, package, test, release, deploy] if: ${{ always() && (contains(needs.*.result, 'failure') || !failure() && !cancelled()) }} runs-on: ubuntu-latest steps: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 026cd7a4..9610e697 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,12 +41,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@master + uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@master + uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -61,11 +61,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@master + uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Deploy - uses: input-output-hk/catalyst-forge/actions/run@master + uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run with: command: deploy push args: ${{ matrix.deployment }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 80361cee..e9d6b51f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -44,12 +44,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@master + uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@master + uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -64,11 +64,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@master + uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Run - uses: input-output-hk/catalyst-forge/actions/run@master + uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run with: command: run args: --artifact ${{ env.OUTPUT }} ${{ matrix.earthfile }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68f50458..ed8b665d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,12 +45,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@master + uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@master + uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -65,11 +65,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@master + uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Release - uses: input-output-hk/catalyst-forge/actions/run@master + uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run with: command: release args: ${{ matrix.release.project }} ${{ matrix.release.name }} diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 2556a60c..7774acce 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -42,12 +42,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@master + uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@master + uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -62,11 +62,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@master + uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Run - uses: input-output-hk/catalyst-forge/actions/run@master + uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run with: command: run args: ${{ matrix.earthfile }} diff --git a/cli/cmd/cmds/deploy/deploy.go b/cli/cmd/cmds/deploy/push.go similarity index 89% rename from cli/cmd/cmds/deploy/deploy.go rename to cli/cmd/cmds/deploy/push.go index ea87587d..43b1a19a 100644 --- a/cli/cmd/cmds/deploy/deploy.go +++ b/cli/cmd/cmds/deploy/push.go @@ -19,13 +19,14 @@ func (c *PushCmd) Run(ctx run.RunContext) error { return fmt.Errorf("could not load project: %w", err) } + var dryrun bool eh := events.NewDefaultEventHandler(ctx.Logger) if !eh.Firing(&project, project.GetDeploymentEvents()) && !c.Force { - ctx.Logger.Info("No deployment event is firing, skipping deployment") - return nil + ctx.Logger.Info("No deployment event is firing, performing dry-run") + dryrun = true } - deployer := deployment.NewGitopsDeployer(&project, &ctx.SecretStore, ctx.Logger) + deployer := deployment.NewGitopsDeployer(&project, &ctx.SecretStore, ctx.Logger, dryrun) if err := deployer.Load(); err != nil { return fmt.Errorf("could not load deployer: %w", err) } diff --git a/cli/pkg/deployment/gitops.go b/cli/pkg/deployment/gitops.go index 16198540..aa1b4dcc 100644 --- a/cli/pkg/deployment/gitops.go +++ b/cli/pkg/deployment/gitops.go @@ -45,6 +45,7 @@ func (g gitRemote) Push(repo *git.Repository, o *git.PushOptions) error { // GitopsDeployer is a deployer that deploys projects to a GitOps repository. type GitopsDeployer struct { + dryrun bool fs billy.Filesystem repo *git.Repository kcl KCLRunner @@ -108,21 +109,29 @@ func (g *GitopsDeployer) Deploy() error { } } - changes, err := g.hasChanges() - if err != nil { - return fmt.Errorf("could not check if worktree has changes: %w", err) - } else if !changes { - return ErrNoChanges - } + if !g.dryrun { + changes, err := g.hasChanges() + if err != nil { + return fmt.Errorf("could not check if worktree has changes: %w", err) + } else if !changes { + return ErrNoChanges + } - g.logger.Info("Committing changes", "path", bundlePath) - if err := g.commit(); err != nil { - return fmt.Errorf("could not commit changes: %w", err) - } + g.logger.Info("Committing changes", "path", bundlePath) + if err := g.commit(); err != nil { + return fmt.Errorf("could not commit changes: %w", err) + } - g.logger.Info("Pushing changes") - if err := g.push(); err != nil { - return fmt.Errorf("could not push changes: %w", err) + g.logger.Info("Pushing changes") + if err := g.push(); err != nil { + return fmt.Errorf("could not push changes: %w", err) + } + } else { + g.logger.Info("Dry-run: not committing or pushing changes") + g.logger.Info("Dumping manifests") + for _, r := range result { + fmt.Print(r.Manifests) + } } return nil @@ -245,12 +254,14 @@ func NewGitopsDeployer( project *project.Project, store *secrets.SecretStore, logger *slog.Logger, + dryrun bool, ) GitopsDeployer { if logger == nil { logger = slog.New(slog.NewTextHandler(io.Discard, nil)) } return GitopsDeployer{ + dryrun: dryrun, fs: memfs.New(), kcl: NewKCLRunner(logger), logger: logger, diff --git a/cli/pkg/deployment/kcl.go b/cli/pkg/deployment/kcl.go index 487a20fa..77023327 100644 --- a/cli/pkg/deployment/kcl.go +++ b/cli/pkg/deployment/kcl.go @@ -147,7 +147,7 @@ func encodeValues(ctx *cue.Context, module schema.Module) ([]byte, error) { // run runs a KCL module with the given module container and arguments. func (k *KCLRunner) run(container string, moduleArgs KCLModuleArgs) ([]byte, error) { - args := []string{"run", "-q"} + args := []string{"run", "-q", "--no_style"} args = append(args, moduleArgs.Serialize()...) args = append(args, fmt.Sprintf("oci://%s", container)) diff --git a/cli/pkg/deployment/kcl_test.go b/cli/pkg/deployment/kcl_test.go index 801aac33..e2c1c663 100644 --- a/cli/pkg/deployment/kcl_test.go +++ b/cli/pkg/deployment/kcl_test.go @@ -140,8 +140,8 @@ func TestKCLRunnerRunDeployment(t *testing.T) { assert.Equal(t, "key: value\n", r.result["main"].Values) assert.Equal(t, "output", r.result["support"].Manifests) assert.Equal(t, "key1: value1\n", r.result["support"].Values) - assert.Contains(t, r.calls, "run -q -D name= -D namespace=default -D values={\"key\":\"value\"} -D 1.0.0 oci://test.com/module") - assert.Contains(t, r.calls, "run -q -D name= -D namespace=default -D values={\"key1\":\"value1\"} -D 1.0.0 oci://test.com/module1") + assert.Contains(t, r.calls, "run -q --no_style -D name= -D namespace=default -D values={\"key\":\"value\"} -D 1.0.0 oci://test.com/module") + assert.Contains(t, r.calls, "run -q --no_style -D name= -D namespace=default -D values={\"key1\":\"value1\"} -D 1.0.0 oci://test.com/module1") }, }, { diff --git a/foundry/api/blueprint.cue b/foundry/api/blueprint.cue index 3937a1f7..da8f400b 100644 --- a/foundry/api/blueprint.cue +++ b/foundry/api/blueprint.cue @@ -15,9 +15,8 @@ project: { } deployment: { on: { - //merge: {} - //tag: {} - always: {} + merge: {} + tag: {} } environment: "dev" modules: { @@ -47,9 +46,8 @@ project: { release: { docker: { on: { - //merge: {} - //tag: {} - always: {} + merge: {} + tag: {} } config: { tag: _ @forge(name="GIT_HASH_OR_TAG") From 5540473bfb14af58bb0c242a001720c8feaa1918 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Fri, 17 Jan 2025 12:52:16 -0800 Subject: [PATCH 2/2] wip: cleanup --- .github/workflows/ci.yml | 22 +++++++++++----------- .github/workflows/deploy.yml | 8 ++++---- .github/workflows/docs.yml | 8 ++++---- .github/workflows/release.yml | 8 ++++---- .github/workflows/run.yml | 8 ++++---- cli/pkg/deployment/gitops_test.go | 26 +++++++++++++++++++++++++- 6 files changed, 52 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 811f1125..5851710a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,12 +41,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install@master if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install-local@master if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -61,14 +61,14 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/setup@master with: skip_docker: 'true' skip_github: 'true' skip_earthly: ${{ steps.local.outputs.skip }} - name: Discovery id: discovery - uses: input-output-hk/catalyst-forge/actions/discovery@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/discovery@master with: filters: | ${{ env.FORGE_REGEX_CHECK }} @@ -80,7 +80,7 @@ jobs: ${{ env.FORGE_REGEX_PUBLISH }} check: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master needs: [discover] if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -92,7 +92,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} build: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master needs: [discover, check] if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -104,7 +104,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} package: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master needs: [discover, check, build] if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -116,7 +116,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} test: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master needs: [discover, check, build, package] if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -128,7 +128,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} docs: - uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@master needs: [discover, check, build, test] if: (fromJson(needs.discover.outputs.earthfiles)['^docs(-.*)?$'] != null) && !failure() && !cancelled() with: @@ -138,7 +138,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} release: - uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@master needs: [discover, check, build, test] if: (fromJson(needs.discover.outputs.releases)[0] != null) && !failure() && !cancelled() with: @@ -150,7 +150,7 @@ jobs: earthly_token: ${{ secrets.earthly_token }} deploy: - uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@deploy-dry-run + uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master needs: [discover, check, build, test, release] if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() with: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9610e697..026cd7a4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,12 +41,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install@master if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install-local@master if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -61,11 +61,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/setup@master with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Deploy - uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/run@master with: command: deploy push args: ${{ matrix.deployment }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e9d6b51f..80361cee 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -44,12 +44,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install@master if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install-local@master if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -64,11 +64,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/setup@master with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Run - uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/run@master with: command: run args: --artifact ${{ env.OUTPUT }} ${{ matrix.earthfile }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed8b665d..68f50458 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,12 +45,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install@master if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install-local@master if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -65,11 +65,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/setup@master with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Release - uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/run@master with: command: release args: ${{ matrix.release.project }} ${{ matrix.release.name }} diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 7774acce..2556a60c 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -42,12 +42,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Forge - uses: input-output-hk/catalyst-forge/actions/install@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install@master if: ${{ inputs.forge_version != 'local' }} with: version: ${{ inputs.forge_version }} - name: Install Local Forge - uses: input-output-hk/catalyst-forge/actions/install-local@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/install-local@master if: ${{ inputs.forge_version == 'local' }} with: earthly_token: ${{ secrets.earthly_token }} @@ -62,11 +62,11 @@ jobs: echo "skip=false" >> $GITHUB_OUTPUT fi - name: Setup CI - uses: input-output-hk/catalyst-forge/actions/setup@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/setup@master with: skip_earthly: ${{ steps.local.outputs.skip }} - name: Run - uses: input-output-hk/catalyst-forge/actions/run@deploy-dry-run + uses: input-output-hk/catalyst-forge/actions/run@master with: command: run args: ${{ matrix.earthfile }} diff --git a/cli/pkg/deployment/gitops_test.go b/cli/pkg/deployment/gitops_test.go index 08b14304..5b95b66f 100644 --- a/cli/pkg/deployment/gitops_test.go +++ b/cli/pkg/deployment/gitops_test.go @@ -76,6 +76,7 @@ func TestDeploy(t *testing.T) { project projectParams yaml string execFail bool + dryrun bool setup func(*testing.T, *GitopsDeployer, *testutils.InMemRepo) validate func(*testing.T, *GitopsDeployer, mockGitRemote, *testutils.InMemRepo) expectErr bool @@ -87,6 +88,7 @@ func TestDeploy(t *testing.T) { project: defaultParams, yaml: "yaml", execFail: false, + dryrun: false, setup: func(t *testing.T, deployer *GitopsDeployer, repo *testutils.InMemRepo) { deployer.token = "test" repo.MkdirAll(t, "deploy/dev/apps") @@ -106,6 +108,27 @@ func TestDeploy(t *testing.T) { expectErr: false, expectedErr: "", }, + { + name: "dry-run", + mock: mockGitRemote{}, + project: defaultParams, + yaml: "yaml", + execFail: false, + dryrun: true, + setup: func(t *testing.T, deployer *GitopsDeployer, repo *testutils.InMemRepo) { + deployer.token = "test" + repo.MkdirAll(t, "deploy/dev/apps") + }, + validate: func(t *testing.T, deployer *GitopsDeployer, mock mockGitRemote, repo *testutils.InMemRepo) { + assert.True(t, repo.Exists(t, "deploy/dev/apps/test/main.yaml"), "main.yaml does not exist") + assert.Equal(t, repo.ReadFile(t, "deploy/dev/apps/test/main.yaml"), []byte("yaml"), "main.yaml content is incorrect") + + _, err := repo.Repo.Head() + require.Error(t, err) // No commit should be made + }, + expectErr: false, + expectedErr: "", + }, { name: "no changes", mock: mockGitRemote{}, @@ -138,7 +161,8 @@ func TestDeploy(t *testing.T) { repo := testutils.NewInMemRepo(t) var calls []string deployer := GitopsDeployer{ - fs: repo.Fs, + dryrun: tt.dryrun, + fs: repo.Fs, kcl: KCLRunner{ logger: testutils.NewNoopLogger(), kcl: newWrappedExecuterMock(tt.yaml, &calls, tt.execFail),