MCPcopy Create free account
hub / github.com/github/gh-aw / ValidateLockSchemaCompatibility

Function ValidateLockSchemaCompatibility

pkg/workflow/lock_validation.go:37–68  ·  view source on GitHub ↗

ValidateLockSchemaCompatibility validates that a lock file's schema is compatible. Returns an error with actionable guidance if incompatible.

(content string, lockFilePath string)

Source from the content-addressed store, hash-verified

35// ValidateLockSchemaCompatibility validates that a lock file's schema is compatible.
36// Returns an error with actionable guidance if incompatible.
37func ValidateLockSchemaCompatibility(content string, lockFilePath string) error {
38 metadata, isLegacy, err := ExtractMetadataFromLockFile(content)
39 if err != nil {
40 return fmt.Errorf("failed to extract metadata from %s: %w", lockFilePath, err)
41 }
42
43 // Legacy files (no schema version) are supported for backward compatibility
44 if isLegacy {
45 lockSchemaLog.Printf("Legacy lock file accepted: %s", lockFilePath)
46 return nil
47 }
48
49 // Missing metadata entirely is suspicious
50 if metadata == nil {
51 return fmt.Errorf("lock file %s is missing required metadata. This file may be corrupted or manually edited.\n\nTo fix this, recompile the workflow:\n gh aw compile %s",
52 lockFilePath,
53 strings.TrimSuffix(lockFilePath, ".lock.yml")+".md")
54 }
55
56 // Check schema compatibility
57 if !IsSchemaVersionSupported(metadata.SchemaVersion) {
58 // Future version detected
59 return fmt.Errorf("lock file %s uses unsupported schema version '%s'.\n\nThis file was generated by a newer version of gh-aw that uses incompatible features.\n\nSupported versions: %s\n\nTo fix this:\n 1. Upgrade gh-aw: gh extension upgrade gh-aw\n 2. Or downgrade the lock file by editing the source .md file and recompiling:\n gh aw compile %s",
60 lockFilePath,
61 metadata.SchemaVersion,
62 formatSupportedVersions(),
63 strings.TrimSuffix(lockFilePath, ".lock.yml")+".md")
64 }
65
66 lockSchemaLog.Printf("Lock file schema validated: %s (version=%s)", lockFilePath, metadata.SchemaVersion)
67 return nil
68}
69
70// ValidateActionSHAsInLockFile validates action SHAs in a lock file and emits warnings
71func ValidateActionSHAsInLockFile(ctx context.Context, lockFilePath string, cache *ActionCache, verbose bool) error {

Calls 5

IsSchemaVersionSupportedFunction · 0.85
formatSupportedVersionsFunction · 0.85
ErrorfMethod · 0.45
PrintfMethod · 0.45