Migrate lock commands to independent objects
This commit is contained in:
@@ -35,8 +35,8 @@ func buildHelperArtifactCatalog(cfg *config.Config, m *manifest.Manifest) (*arti
|
||||
return catalog, nil
|
||||
}
|
||||
|
||||
func writeArtifactList(out io.Writer, cfg *config.Config, catalog *artifacts.ArtifactCatalog, locks *effectiveLocks, publishedRemoteState map[string]string) {
|
||||
lockSet := lockSourceSet(locks.All)
|
||||
func writeArtifactList(out io.Writer, cfg *config.Config, catalog *artifacts.ArtifactCatalog, locks []artifacts.RemoteLock, publishedRemoteState map[string]string) {
|
||||
lockSet := remoteLockSourceSet(locks)
|
||||
fmt.Fprintln(out, "Built-in:")
|
||||
for _, transcript := range artifacts.RuntimeTranscriptArtifacts() {
|
||||
writeArtifactLine(out, transcript.SourceID, lockSet)
|
||||
@@ -71,7 +71,7 @@ func writeArtifactList(out io.Writer, cfg *config.Config, catalog *artifacts.Art
|
||||
}
|
||||
}
|
||||
|
||||
func writeConfiguredArtifactLine(out io.Writer, source, state, provenance string, lockSet map[string]config.PublishLockRule, origins map[string]config.ArtifactFamilyMemberOrigin) {
|
||||
func writeConfiguredArtifactLine(out io.Writer, source, state, provenance string, lockSet map[string]struct{}, origins map[string]config.ArtifactFamilyMemberOrigin) {
|
||||
parts := []string{source, "planned", state}
|
||||
if key, ok := artifactpolicy.ParseConfiguredSource(source); ok {
|
||||
if origin, family := origins[key]; family {
|
||||
@@ -87,7 +87,7 @@ func writeConfiguredArtifactLine(out io.Writer, source, state, provenance string
|
||||
fmt.Fprintf(out, "- %s\n", strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func writeExtractionArtifactLine(out io.Writer, source, state, provenance string, lockSet map[string]config.PublishLockRule) {
|
||||
func writeExtractionArtifactLine(out io.Writer, source, state, provenance string, lockSet map[string]struct{}) {
|
||||
parts := []string{source, "planned", state}
|
||||
if strings.TrimSpace(provenance) != "" {
|
||||
parts = append(parts, "provenance="+strings.TrimSpace(provenance))
|
||||
@@ -98,7 +98,7 @@ func writeExtractionArtifactLine(out io.Writer, source, state, provenance string
|
||||
fmt.Fprintf(out, "- %s\n", strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func writeArtifactLine(out io.Writer, source string, lockSet map[string]config.PublishLockRule) {
|
||||
func writeArtifactLine(out io.Writer, source string, lockSet map[string]struct{}) {
|
||||
parts := []string{source}
|
||||
if _, ok := lockSet[source]; ok {
|
||||
parts = append(parts, "locked")
|
||||
@@ -106,7 +106,7 @@ func writeArtifactLine(out io.Writer, source string, lockSet map[string]config.P
|
||||
fmt.Fprintf(out, "- %s\n", strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func writePublishedOutputLine(out io.Writer, rule config.PublishOutputRule, catalog *artifacts.ArtifactCatalog, lockSet map[string]config.PublishLockRule, remoteState map[string]string) {
|
||||
func writePublishedOutputLine(out io.Writer, rule config.PublishOutputRule, catalog *artifacts.ArtifactCatalog, lockSet map[string]struct{}, remoteState map[string]string) {
|
||||
source := strings.TrimSpace(rule.Source)
|
||||
parts := []string{source}
|
||||
if _, ok := lockSet[source]; ok {
|
||||
@@ -127,6 +127,14 @@ func writePublishedOutputLine(out io.Writer, rule config.PublishOutputRule, cata
|
||||
fmt.Fprintf(out, "- %s\n", strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func remoteLockSourceSet(locks []artifacts.RemoteLock) map[string]struct{} {
|
||||
out := make(map[string]struct{}, len(locks))
|
||||
for _, lock := range locks {
|
||||
out[lock.Source] = struct{}{}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func unresolvedRemotePublishedOutputAvailability(cfg *config.Config, catalog *artifacts.ArtifactCatalog, state string) map[string]string {
|
||||
out := map[string]string{}
|
||||
for _, rule := range cfg.Pipeline.Publish.Outputs {
|
||||
@@ -151,6 +159,7 @@ func remotePublishedOutputAvailabilityForCurrent(
|
||||
if current == nil || current.Commit == nil {
|
||||
return unresolvedRemotePublishedOutputAvailability(cfg, catalog, "remote=missing")
|
||||
}
|
||||
outcomes := committedPublishOutputOutcomes(current.Manifest)
|
||||
out := map[string]string{}
|
||||
for _, rule := range cfg.Pipeline.Publish.Outputs {
|
||||
source := strings.TrimSpace(rule.Source)
|
||||
@@ -159,26 +168,31 @@ func remotePublishedOutputAvailabilityForCurrent(
|
||||
out[publishedOutputRemoteStateKey(source, "")] = "remote=error"
|
||||
continue
|
||||
}
|
||||
outcome := outcomes[source]
|
||||
state := ""
|
||||
if outcome != "" {
|
||||
state = "outcome=" + outcome + " "
|
||||
}
|
||||
declaration, ok := committedPublishedOutput(current.Commit, source)
|
||||
if !ok {
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = "remote=missing"
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=missing"
|
||||
continue
|
||||
}
|
||||
identity, err := artifacts.ParseImmutableRunObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
||||
if err != nil {
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = "remote=error"
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=error"
|
||||
continue
|
||||
}
|
||||
exists, err := store.Exists(ctx, declaration.DestinationKey)
|
||||
if err != nil {
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = "remote=error"
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=error"
|
||||
continue
|
||||
}
|
||||
if !exists {
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = "remote=missing"
|
||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=missing"
|
||||
continue
|
||||
}
|
||||
state := "remote=published"
|
||||
state += "remote=published"
|
||||
if identity.RunID != current.RunID {
|
||||
state += " origin_run=" + identity.RunID
|
||||
}
|
||||
@@ -187,6 +201,43 @@ func remotePublishedOutputAvailabilityForCurrent(
|
||||
return out
|
||||
}
|
||||
|
||||
func committedPublishOutputOutcomes(m *manifest.Manifest) map[string]string {
|
||||
out := map[string]string{}
|
||||
if m == nil || m.Stages["publish"] == nil {
|
||||
return out
|
||||
}
|
||||
raw := m.Stages["publish"].Metadata["publish_output_outcomes"]
|
||||
appendOutcome := func(item map[string]any) {
|
||||
source, sourceOK := item["source"].(string)
|
||||
status, statusOK := item["status"].(string)
|
||||
if sourceOK && statusOK && isPublishOutputOutcome(status) {
|
||||
out[source] = status
|
||||
}
|
||||
}
|
||||
switch items := raw.(type) {
|
||||
case []any:
|
||||
for _, rawItem := range items {
|
||||
if item, ok := rawItem.(map[string]any); ok {
|
||||
appendOutcome(item)
|
||||
}
|
||||
}
|
||||
case []map[string]any:
|
||||
for _, item := range items {
|
||||
appendOutcome(item)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func isPublishOutputOutcome(status string) bool {
|
||||
switch status {
|
||||
case "published", "carried_locked", "locked_unpublished", "optional_missing", "unselected":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func committedPublishedOutput(commit *artifacts.RemoteCommitManifest, source string) (artifacts.RemoteArtifact, bool) {
|
||||
if commit == nil {
|
||||
return artifacts.RemoteArtifact{}, false
|
||||
|
||||
Reference in New Issue
Block a user