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

Function ExtractStopTimeFromLockFile

pkg/workflow/stop_after.go:144–193  ·  view source on GitHub ↗

ExtractStopTimeFromLockFile extracts the STOP_TIME value from a compiled workflow lock file

(lockFilePath string)

Source from the content-addressed store, hash-verified

142
143// ExtractStopTimeFromLockFile extracts the STOP_TIME value from a compiled workflow lock file
144func ExtractStopTimeFromLockFile(lockFilePath string) string {
145 content, err := os.ReadFile(lockFilePath)
146 if err != nil {
147 return ""
148 }
149
150 contentStr := string(content)
151
152 // Try to extract from metadata first
153 metadata, isLegacy, err := ExtractMetadataFromLockFile(contentStr)
154
155 // If metadata extraction failed with an error (malformed JSON), log warning but don't fall back
156 // This is different from no metadata (which is intentional for legacy files)
157 if err != nil {
158 stopAfterLog.Printf("Warning: Failed to parse metadata from %s: %v. Falling back to legacy extraction.", lockFilePath, err)
159 // Malformed metadata - fall through to legacy extraction as a safety measure
160 // but this indicates a potential issue with the lock file
161 } else if metadata != nil && metadata.StopTime != "" {
162 // Successfully extracted stop time from metadata
163 stopAfterLog.Printf("Extracted stop time from metadata: %s", metadata.StopTime)
164 return metadata.StopTime
165 }
166
167 // Validate lock file schema compatibility before parsing
168 // Non-critical operation - continue even if validation fails
169 if err := ValidateLockSchemaCompatibility(contentStr, lockFilePath); err != nil {
170 stopAfterLog.Printf("Warning: Lock file schema validation failed for %s: %v", lockFilePath, err)
171 // Continue anyway for legacy compatibility
172 }
173
174 // Legacy fallback: Look for GH_AW_STOP_TIME in the workflow body
175 // Use legacy method if: no metadata, legacy format, metadata exists but stop_time is empty, or metadata was malformed
176 if err != nil || metadata == nil || isLegacy || metadata.StopTime == "" {
177 lines := strings.SplitSeq(contentStr, "\n")
178 for line := range lines {
179 // Look for GH_AW_STOP_TIME: YYYY-MM-DD HH:MM:SS
180 // This is in the env section of the stop time check job
181 if strings.Contains(line, "GH_AW_STOP_TIME:") {
182 prefix := "GH_AW_STOP_TIME:"
183 if _, after, ok := strings.Cut(line, prefix); ok {
184 extracted := strings.TrimSpace(after)
185 // Strip surrounding quotes added by newer compiler versions
186 extracted = strings.Trim(extracted, "\"")
187 return extracted
188 }
189 }
190 }
191 }
192 return ""
193}
194
195// extractSkipIfMatchFromOn extracts the skip-if-match value from the on: section
196func (c *Compiler) extractSkipIfMatchFromOn(frontmatter map[string]any, workflowData ...*WorkflowData) (*SkipIfMatchConfig, error) {

Callers 3

GetWorkflowStatusesFunction · 0.92

Calls 3

PrintfMethod · 0.45

Tested by 1