fix(build): write CI metadata for final artifacts
This commit is contained in:
parent
47dcc3dc93
commit
845565c502
2 changed files with 38 additions and 14 deletions
|
|
@ -155,12 +155,6 @@ func runProjectBuild(ctx context.Context, buildType string, ciMode bool, targets
|
|||
return err
|
||||
}
|
||||
|
||||
if ciMode {
|
||||
if err := writeArtifactMetadata(filesystem, binaryName, artifacts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if verbose && !ciMode {
|
||||
cli.Print("%s %s\n", buildSuccessStyle.Render(i18n.T("common.label.success")), i18n.T("cmd.build.built_artifacts", map[string]any{"Count": len(artifacts)}))
|
||||
cli.Blank()
|
||||
|
|
@ -268,14 +262,10 @@ func runProjectBuild(ctx context.Context, buildType string, ciMode bool, targets
|
|||
|
||||
// Output results
|
||||
if ciMode {
|
||||
// Determine which artifacts to output (prefer checksummed > archived > raw)
|
||||
var outputArtifacts []build.Artifact
|
||||
if len(checksummedArtifacts) > 0 {
|
||||
outputArtifacts = checksummedArtifacts
|
||||
} else if len(archivedArtifacts) > 0 {
|
||||
outputArtifacts = archivedArtifacts
|
||||
} else {
|
||||
outputArtifacts = artifacts
|
||||
// Determine which artifacts to output (prefer checksummed > archived > raw).
|
||||
outputArtifacts := selectOutputArtifacts(artifacts, archivedArtifacts, checksummedArtifacts)
|
||||
if err := writeArtifactMetadata(filesystem, binaryName, outputArtifacts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// JSON output for CI
|
||||
|
|
@ -296,6 +286,19 @@ func runProjectBuild(ctx context.Context, buildType string, ciMode bool, targets
|
|||
return nil
|
||||
}
|
||||
|
||||
// selectOutputArtifacts chooses the final artifact list for CI output.
|
||||
//
|
||||
// output := selectOutputArtifacts(rawArtifacts, archivedArtifacts, checksummedArtifacts)
|
||||
func selectOutputArtifacts(rawArtifacts, archivedArtifacts, checksummedArtifacts []build.Artifact) []build.Artifact {
|
||||
if len(checksummedArtifacts) > 0 {
|
||||
return checksummedArtifacts
|
||||
}
|
||||
if len(archivedArtifacts) > 0 {
|
||||
return archivedArtifacts
|
||||
}
|
||||
return rawArtifacts
|
||||
}
|
||||
|
||||
// writeArtifactMetadata writes artifact_meta.json files next to built artifacts when CI metadata is available.
|
||||
func writeArtifactMetadata(filesystem io.Medium, buildName string, artifacts []build.Artifact) error {
|
||||
ci := build.DetectCI()
|
||||
|
|
|
|||
|
|
@ -141,3 +141,24 @@ func TestBuildCmd_writeArtifactMetadata_Good(t *testing.T) {
|
|||
verifyArtifactMeta(ax.Join(linuxDir, "artifact_meta.json"), "linux", "amd64")
|
||||
verifyArtifactMeta(ax.Join(windowsDir, "artifact_meta.json"), "windows", "amd64")
|
||||
}
|
||||
|
||||
func TestBuildCmd_selectOutputArtifacts_Good(t *testing.T) {
|
||||
rawArtifacts := []build.Artifact{{Path: "dist/raw"}}
|
||||
archivedArtifacts := []build.Artifact{{Path: "dist/raw.tar.gz"}}
|
||||
checksummedArtifacts := []build.Artifact{{Path: "dist/raw.tar.gz", Checksum: "abc123"}}
|
||||
|
||||
t.Run("prefers checksummed artifacts", func(t *testing.T) {
|
||||
selected := selectOutputArtifacts(rawArtifacts, archivedArtifacts, checksummedArtifacts)
|
||||
assert.Equal(t, checksummedArtifacts, selected)
|
||||
})
|
||||
|
||||
t.Run("falls back to archived artifacts", func(t *testing.T) {
|
||||
selected := selectOutputArtifacts(rawArtifacts, archivedArtifacts, nil)
|
||||
assert.Equal(t, archivedArtifacts, selected)
|
||||
})
|
||||
|
||||
t.Run("falls back to raw artifacts", func(t *testing.T) {
|
||||
selected := selectOutputArtifacts(rawArtifacts, nil, nil)
|
||||
assert.Equal(t, rawArtifacts, selected)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue