Repository navigation
feat(artifacts): CI summaries, docs, and changelog #3594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Erik Osterman (Cloud Posse) (osterman)
wants to merge
23
commits into
osterman/artifacts-discovery-steps
from
osterman/artifacts-ci-docs
+9,705
−515
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f9ad720
feat(artifacts): add CI summaries, outputs, and entry-point tests (A10)
osterman ed1d552
docs(artifacts): document artifacts commands, catalogs, step, CI summ…
osterman e4e5f73
fix(artifacts): fix CI failures on Linux and Windows
osterman e73a0e4
test(artifacts): compare the workflow step source on slash form for W…
osterman e2f2fe3
fix(artifacts): address CodeRabbit review findings
osterman e07d8d1
ci: stop the floci go e2e job depending on apt
osterman 313c41a
fix(artifacts): rerecord catalog and scaffold help casts
osterman 8620dc2
fix(artifacts): claim qualified CI outputs per name and trim the comp…
osterman f4ab7cc
fix: isolate artifact steps and clean up shell sessions
osterman c1ba5b9
test(process): measure pipe drain after helper startup
osterman 51292a5
fix(artifacts): confine validation and isolate task retries
osterman 35c91b6
fix: preserve successful automation and compare artifact wire results
osterman 56e5dee
test(process): verify drain deadline independently of startup
osterman 9e964a7
test(step): adopt main's process-tree timeout test
osterman feaf0f9
test(auth): make the OIDC retry timeout case deterministic
osterman 3805966
test(artifacts): use a generated ci.Reporter mock in report tests
osterman 9bcc807
fix(manifest): wrap include-root confinement failures with a manifest…
osterman 3d0da2d
refactor(manifest): move scaffold include confinement out of pkg/utils
osterman 21170c9
docs(artifacts): exclude catalog commands from CI reporting and artif…
osterman e7d47f8
test(manifest): cover scaffold include publication-root boundary
osterman 82b8ee4
test(step): use a generated mock for the detailed artifact service
osterman 5b05b0c
test(artifacts): cover scaffold, confinement, parallel fork and repor…
osterman 4174834
fix(artifacts): preserve historical L8 merge resolutions after rebase
osterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package artifacts | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/cloudposse/atmos/pkg/artifact" | ||
| "github.com/cloudposse/atmos/pkg/artifact/invoke" | ||
| "github.com/cloudposse/atmos/pkg/artifactwire/wiretest" | ||
| runnerstep "github.com/cloudposse/atmos/pkg/runner/step" | ||
| "github.com/cloudposse/atmos/pkg/schema" | ||
| ) | ||
|
|
||
| // TestCLIAndArtifactStepReportTheSamePublication runs the same publication through the real | ||
| // command and through the artifact step against real local repositories, and compares the | ||
| // structured output of the command with the step's typed result and named outputs. | ||
| func TestCLIAndArtifactStepReportTheSamePublication(t *testing.T) { | ||
| f := wiretest.New(t) | ||
| h, _ := newHarness(t) | ||
| atmosConfigPtr = f.Config | ||
| newService = func(*schema.AtmosConfiguration, ServiceOptions) (artifact.Service, error) { return f.Recorder, nil } | ||
|
|
||
| cli := h.run("publish", f.Source, "--repository="+wiretest.Alias, "--name="+wiretest.Name, "--version="+wiretest.Version, | ||
| "--labels=team=platform", "--format=json") | ||
| require.NoError(t, cli.err) | ||
| var fromCLI invoke.Result | ||
| require.NoError(t, json.Unmarshal([]byte(cli.stdout), &fromCLI)) | ||
|
|
||
| // The step publishes to a sibling repository, so it is a fresh creation with the same content. | ||
| sibling := wiretest.New(t) | ||
| vars := runnerstep.NewVariables() | ||
| vars.SetAtmosConfig(sibling.Config) | ||
| step := &schema.WorkflowStep{ | ||
| Name: "publish", Type: schema.TaskTypeArtifact, Action: "publish", Source: sibling.Source, Repository: wiretest.Alias, | ||
| ArtifactName: wiretest.Name, Version: wiretest.Version, Metadata: &schema.ArtifactStepMetadata{Labels: map[string]string{"team": "platform"}}, | ||
| } | ||
| result, err := (&runnerstep.ArtifactHandler{}).Execute(context.Background(), step, vars) | ||
| require.NoError(t, err) | ||
| fromStep, ok := result.Metadata[runnerstep.ArtifactMetadataKey].(*invoke.Result) | ||
| require.True(t, ok) | ||
|
|
||
| // SizeMeasured is internal state omitted from JSON; compare the public wire values while | ||
| // independently checking that the typed step remembers the measurement. | ||
| assert.True(t, fromStep.SizeMeasured) | ||
| cliOperation, err := json.Marshal(f.Normalize(&fromCLI.OperationResult)) | ||
| require.NoError(t, err) | ||
| stepOperation, err := json.Marshal(sibling.Normalize(&fromStep.OperationResult)) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, string(cliOperation), string(stepOperation), "the command and the step report the same result") | ||
| assert.Equal(t, fromCLI.Record, fromStep.Record) | ||
|
|
||
| var named map[string]any | ||
| require.NoError(t, json.Unmarshal([]byte(cli.stdout), &named)) | ||
| require.Contains(t, result.Outputs, "size") | ||
| require.Contains(t, named, "size") | ||
| for name, value := range result.Outputs { | ||
| if name == "location" { | ||
| continue // Rooted in each fixture's own repository directory. | ||
| } | ||
| if name == "size" { | ||
| assert.EqualValues(t, fromCLI.Size, mustSize(t, value), "size") | ||
| continue | ||
| } | ||
| assert.Equal(t, value, named[name], "named output %q has the same name and value in the command's structured output", name) | ||
| } | ||
| assert.Contains(t, named, "location") | ||
| } | ||
|
|
||
| func mustSize(t *testing.T, value string) int64 { | ||
| t.Helper() | ||
| var size int64 | ||
| require.NoError(t, json.Unmarshal([]byte(value), &size)) | ||
| return size | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| package artifacts | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "go.uber.org/mock/gomock" | ||
|
|
||
| errUtils "github.com/cloudposse/atmos/errors" | ||
| "github.com/cloudposse/atmos/pkg/artifact" | ||
| _ "github.com/cloudposse/atmos/pkg/ci/providers/generic" // Register the generic CI provider, as the binary does. | ||
| "github.com/cloudposse/atmos/pkg/schema" | ||
| ) | ||
|
|
||
| // ciReportFiles enables CI reporting on the harness and points the generic CI provider at files. | ||
| func ciReportFiles(t *testing.T, h *harness) (summary, outputs string) { | ||
| t.Helper() | ||
| dir := t.TempDir() | ||
| summary, outputs = filepath.Join(dir, "summary.md"), filepath.Join(dir, "output.txt") | ||
| // A real CI runner advertises its own provider, which would receive the output instead of the files. | ||
| t.Setenv("GITHUB_ACTIONS", "") | ||
| t.Setenv("ATMOS_CI", "true") | ||
| t.Setenv("ATMOS_CI_SUMMARY", summary) | ||
| t.Setenv("ATMOS_CI_OUTPUT", outputs) | ||
| h.config.CI.Enabled = true | ||
| return summary, outputs | ||
| } | ||
|
|
||
| func contentOf(t *testing.T, path string) string { | ||
| t.Helper() | ||
| content, err := os.ReadFile(path) | ||
| if os.IsNotExist(err) { | ||
| return "" | ||
| } | ||
| require.NoError(t, err) | ||
| return string(content) | ||
| } | ||
|
|
||
| // The harness service is a strict mock: every report below is built from the result the operation | ||
| // returned, so an extra metadata or evidence request would fail the test as an unexpected call. | ||
| func TestCommandWritesOneReportAndKeepsStructuredStdoutValid(t *testing.T) { | ||
| h, svc := newHarness(t) | ||
| summary, outputs := ciReportFiles(t, h) | ||
| svc.EXPECT().Publish(gomock.Any(), gomock.Any()).Return(operation(artifact.ActionPublish, artifact.OutcomeCreated), nil) | ||
|
|
||
| got := h.run("publish", "./dist", "--repository=dir", "--name=team/app", "--version=1.0.0", "--format=json") | ||
|
|
||
| require.NoError(t, got.err) | ||
| var envelope map[string]any | ||
| require.NoError(t, json.Unmarshal([]byte(got.stdout), &envelope), "stdout stays a valid JSON document") | ||
| assert.Equal(t, "created", envelope["outcome"]) | ||
| assert.NotContains(t, got.stdout, "## Artifacts", "the report never goes to stdout") | ||
|
|
||
| assert.Equal(t, 1, strings.Count(contentOf(t, summary), "### ✅ 1. Publish `team/app:1.0.0`")) | ||
| assert.Contains(t, contentOf(t, outputs), "artifact_ref=team/app:1.0.0\n") | ||
| assert.Contains(t, contentOf(t, outputs), "artifact_resolved_digest="+string(manifestDigest)+"\n") | ||
| } | ||
|
|
||
| func TestFailedCommandReportsTheFailureAndStaysFailed(t *testing.T) { | ||
| h, svc := newHarness(t) | ||
| summary, _ := ciReportFiles(t, h) | ||
| failure := artifact.OperationResult{OperationID: "op-9", Action: artifact.ActionVerify, Repository: "dir", Requested: "team/app:1.0.0"} | ||
| svc.EXPECT().Verify(gomock.Any(), gomock.Any()).Return( | ||
| &artifact.VerifyResult{Operation: failure, Verification: artifact.VerificationResult{Status: artifact.VerificationUnchecked}}, | ||
| errors.Join(errUtils.ErrArtifactVerificationFailed, errors.New("no permitted signature")), | ||
| ) | ||
|
|
||
| got := h.run("verify", "team/app:1.0.0", "--repository=dir", "--format=json") | ||
|
|
||
| require.ErrorIs(t, got.err, errUtils.ErrArtifactVerificationFailed, "reporting never turns a verification failure into success") | ||
| content := contentOf(t, summary) | ||
| assert.Contains(t, content, "1 operation: 1 failed.") | ||
| assert.Contains(t, content, "no permitted signature") | ||
| assert.Contains(t, content, "No trust configuration was supplied", "an unchecked signature is never reported as verified") | ||
| } | ||
|
|
||
| func TestReportingFailurePreservesTheSuccessfulExitStatus(t *testing.T) { | ||
| cases := map[string]func(t *testing.T, h *harness){ | ||
| "template failure": func(t *testing.T, h *harness) { | ||
| h.config.CI.Templates.BasePath = t.TempDir() | ||
| h.config.CI.Templates.Artifacts = map[string]string{"summary": "does-not-exist.md"} | ||
| }, | ||
| "provider failure": func(t *testing.T, _ *harness) { | ||
| t.Setenv("ATMOS_CI_SUMMARY", filepath.Join(t.TempDir(), "missing-dir", "summary.md")) | ||
| t.Setenv("ATMOS_CI_OUTPUT", filepath.Join(t.TempDir(), "missing-dir", "output.txt")) | ||
| }, | ||
| } | ||
| for name, breakReporting := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| h, svc := newHarness(t) | ||
| ciReportFiles(t, h) | ||
| breakReporting(t, h) | ||
| svc.EXPECT().Publish(gomock.Any(), gomock.Any()).Return(operation(artifact.ActionPublish, artifact.OutcomeCreated), nil) | ||
|
|
||
| got := h.run("publish", "./dist", "--repository=dir", "--name=team/app", "--version=1.0.0", "--format=json") | ||
|
|
||
| require.NoError(t, got.err, "a reporting error is logged and never changes the exit status") | ||
| assert.Contains(t, got.stdout, `"outcome": "created"`) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestListQueryIsReportedOnce(t *testing.T) { | ||
| h, svc := newHarness(t) | ||
| summary, _ := ciReportFiles(t, h) | ||
| svc.EXPECT().List(gomock.Any(), gomock.Any()).Return(&artifact.ListResult{Artifacts: []artifact.ListEntry{ | ||
| {Name: "team/app", Version: "1.0.0", Kind: "files"}, | ||
| }}, nil) | ||
|
|
||
| got := h.run("list", "--format=json") | ||
|
|
||
| require.NoError(t, got.err) | ||
| assert.Equal(t, 1, strings.Count(contentOf(t, summary), "## Artifacts")) | ||
| assert.Contains(t, contentOf(t, summary), "Listed 1 artifact.") | ||
| } | ||
|
|
||
| func TestDisabledReportingWritesNothing(t *testing.T) { | ||
| h, svc := newHarness(t) | ||
| summary, outputs := ciReportFiles(t, h) | ||
| h.config.CI.Enabled = false | ||
| svc.EXPECT().Publish(gomock.Any(), gomock.Any()).Return(operation(artifact.ActionPublish, artifact.OutcomeCreated), nil) | ||
|
|
||
| got := h.run("publish", "./dist", "--repository=dir", "--name=team/app", "--version=1.0.0", "--format=json") | ||
|
|
||
| require.NoError(t, got.err) | ||
| assert.Empty(t, contentOf(t, summary)) | ||
| assert.Empty(t, contentOf(t, outputs)) | ||
| } | ||
|
|
||
| // A failure before the service runs still reaches the CI report, so the job summary shows a failed | ||
| // row instead of nothing. | ||
| func TestPreServiceFailuresAreReported(t *testing.T) { | ||
| failConstruction := func(*schema.AtmosConfiguration, ServiceOptions) (artifact.Service, error) { | ||
| return nil, errUtils.ErrArtifactConfigInvalid | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| setup func(h *harness) | ||
| args []string | ||
| want error | ||
| }{ | ||
| {"publish without a repository", func(*harness) {}, []string{"publish", "./dist", "--name=team/app", "--version=1.0.0"}, errUtils.ErrRequiredFlagNotProvided}, | ||
| {"publish with a failing service construction", func(*harness) { newService = failConstruction }, []string{"publish", "./dist", "-r", "dir", "--name=team/app", "--version=1.0.0"}, errUtils.ErrArtifactConfigInvalid}, | ||
| {"inspect with a failing service construction", func(*harness) { newService = failConstruction }, []string{"inspect", "team/app:1", "-r", "dir"}, errUtils.ErrArtifactConfigInvalid}, | ||
| {"list with invalid labels", func(*harness) {}, []string{"list", "--labels=nope"}, errUtils.ErrInvalidFlag}, | ||
| {"search with a failing service construction", func(*harness) { newService = failConstruction }, []string{"search", "vpc", "-r", "dir"}, errUtils.ErrArtifactConfigInvalid}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| h, _ := newHarness(t) | ||
| summary, outputs := ciReportFiles(t, h) | ||
| tt.setup(h) | ||
|
|
||
| got := h.run(tt.args...) | ||
|
|
||
| require.ErrorIs(t, got.err, tt.want) | ||
| content := contentOf(t, summary) | ||
| assert.Contains(t, content, "1 operation: 1 failed.") | ||
| assert.Contains(t, content, "❌ Failed") | ||
| assert.Empty(t, contentOf(t, outputs), "a failure with no result writes no output variables") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestMissingConfigurationIsReported(t *testing.T) { | ||
| h, _ := newHarness(t) | ||
| summary, _ := ciReportFiles(t, h) | ||
| // The report session follows the loaded configuration, so a missing one has nothing to report to. | ||
| atmosConfigPtr = nil | ||
| got := h.run("inspect", "team/app:1", "-r", "dir", "--format=json") | ||
| require.ErrorIs(t, got.err, errUtils.ErrArtifactConfigInvalid) | ||
| assert.Empty(t, contentOf(t, summary)) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.