ValidateLockSchemaCompatibility validates that a lock file's schema is compatible. Returns an error with actionable guidance if incompatible.
(content string, lockFilePath string)
| 35 | // ValidateLockSchemaCompatibility validates that a lock file's schema is compatible. |
| 36 | // Returns an error with actionable guidance if incompatible. |
| 37 | func 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 |
| 71 | func ValidateActionSHAsInLockFile(ctx context.Context, lockFilePath string, cache *ActionCache, verbose bool) error { |