Skip to content

Commit be8f8e5

Browse files
authored
Fix workflow timestamp check to use frontmatter hash when .md is newer (#13299)
1 parent 740afd9 commit be8f8e5

2 files changed

Lines changed: 264 additions & 145 deletions

File tree

actions/setup/js/check_workflow_timestamp_api.cjs

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,67 @@ async function main() {
130130

131131
// Check if workflow file is newer than lock file
132132
if (workflowTime > lockTime) {
133-
// Clear case: workflow file is newer - needs recompilation
134-
await compareFrontmatterHashes(); // Log for diagnostic purposes
135-
const warningMessage = `Lock file '${lockFilePath}' is outdated! The workflow file '${workflowMdPath}' has been modified more recently. Run 'gh aw compile' to regenerate the lock file.`;
136-
137-
// Format timestamps and commits for display
138-
const workflowTimestamp = workflowDate.toISOString();
139-
const lockTimestamp = lockDate.toISOString();
140-
141-
// Add summary to GitHub Step Summary
142-
let summary = core.summary
143-
.addRaw("### ⚠️ Workflow Lock File Warning\n\n")
144-
.addRaw("**WARNING**: Lock file is outdated and needs to be regenerated.\n\n")
145-
.addRaw("**Files:**\n")
146-
.addRaw(`- Source: \`${workflowMdPath}\`\n`)
147-
.addRaw(` - Last commit: ${workflowTimestamp}\n`)
148-
.addRaw(` - Commit SHA: [\`${workflowCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${workflowCommit.sha})\n`)
149-
.addRaw(`- Lock: \`${lockFilePath}\`\n`)
150-
.addRaw(` - Last commit: ${lockTimestamp}\n`)
151-
.addRaw(` - Commit SHA: [\`${lockCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${lockCommit.sha})\n\n`)
152-
.addRaw("**Action Required:** Run `gh aw compile` to regenerate the lock file.\n\n");
153-
154-
await summary.write();
155-
156-
// Fail the step to prevent workflow from running with outdated configuration
157-
core.setFailed(warningMessage);
133+
// Workflow file is newer - check frontmatter hash to determine if recompilation needed
134+
core.info("Workflow file is newer - checking frontmatter hash");
135+
const hashComparison = await compareFrontmatterHashes();
136+
137+
if (!hashComparison) {
138+
// Could not compute hash - be conservative and fail
139+
core.warning("Could not compare frontmatter hashes - assuming lock file is outdated");
140+
const warningMessage = `Lock file '${lockFilePath}' is outdated! The workflow file '${workflowMdPath}' has been modified more recently. Run 'gh aw compile' to regenerate the lock file.`;
141+
142+
// Format timestamps and commits for display
143+
const workflowTimestamp = workflowDate.toISOString();
144+
const lockTimestamp = lockDate.toISOString();
145+
146+
// Add summary to GitHub Step Summary
147+
let summary = core.summary
148+
.addRaw("### ⚠️ Workflow Lock File Warning\n\n")
149+
.addRaw("**WARNING**: Lock file is outdated and needs to be regenerated.\n\n")
150+
.addRaw("**Files:**\n")
151+
.addRaw(`- Source: \`${workflowMdPath}\`\n`)
152+
.addRaw(` - Last commit: ${workflowTimestamp}\n`)
153+
.addRaw(` - Commit SHA: [\`${workflowCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${workflowCommit.sha})\n`)
154+
.addRaw(`- Lock: \`${lockFilePath}\`\n`)
155+
.addRaw(` - Last commit: ${lockTimestamp}\n`)
156+
.addRaw(` - Commit SHA: [\`${lockCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${lockCommit.sha})\n\n`)
157+
.addRaw("**Action Required:** Run `gh aw compile` to regenerate the lock file.\n\n");
158+
159+
await summary.write();
160+
161+
// Fail the step to prevent workflow from running with outdated configuration
162+
core.setFailed(warningMessage);
163+
} else if (hashComparison.match) {
164+
// Hashes match - lock file is up to date despite timestamp difference
165+
core.info("✅ Lock file is up to date (frontmatter hashes match despite timestamp difference)");
166+
} else {
167+
// Hashes differ - lock file needs recompilation
168+
const warningMessage = `Lock file '${lockFilePath}' is outdated! The workflow file '${workflowMdPath}' frontmatter has changed. Run 'gh aw compile' to regenerate the lock file.`;
169+
170+
// Format timestamps and commits for display
171+
const workflowTimestamp = workflowDate.toISOString();
172+
const lockTimestamp = lockDate.toISOString();
173+
174+
// Add summary to GitHub Step Summary
175+
let summary = core.summary
176+
.addRaw("### ⚠️ Workflow Lock File Warning\n\n")
177+
.addRaw("**WARNING**: Lock file is outdated (frontmatter hash mismatch).\n\n")
178+
.addRaw("**Files:**\n")
179+
.addRaw(`- Source: \`${workflowMdPath}\`\n`)
180+
.addRaw(` - Last commit: ${workflowTimestamp}\n`)
181+
.addRaw(` - Commit SHA: [\`${workflowCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${workflowCommit.sha})\n`)
182+
.addRaw(` - Frontmatter hash: \`${hashComparison.recomputedHash.substring(0, 12)}...\`\n`)
183+
.addRaw(`- Lock: \`${lockFilePath}\`\n`)
184+
.addRaw(` - Last commit: ${lockTimestamp}\n`)
185+
.addRaw(` - Commit SHA: [\`${lockCommit.sha.substring(0, 7)}\`](https://github.com/${owner}/${repo}/commit/${lockCommit.sha})\n`)
186+
.addRaw(` - Stored hash: \`${hashComparison.storedHash.substring(0, 12)}...\`\n\n`)
187+
.addRaw("**Action Required:** Run `gh aw compile` to regenerate the lock file.\n\n");
188+
189+
await summary.write();
190+
191+
// Fail the step to prevent workflow from running with outdated configuration
192+
core.setFailed(warningMessage);
193+
}
158194
} else if (workflowCommit.sha === lockCommit.sha) {
159195
// Same commit - definitely up to date
160196
core.info("✅ Lock file is up to date (same commit)");
@@ -173,7 +209,7 @@ async function main() {
173209
core.info("✅ Lock file is up to date (hashes match)");
174210
} else {
175211
// Hashes differ - lock file needs recompilation
176-
const warningMessage = `Lock file '${lockFilePath}' is outdated! Frontmatter hash mismatch detected. Run 'gh aw compile' to regenerate the lock file.`;
212+
const warningMessage = `Lock file '${lockFilePath}' is outdated! The workflow file '${workflowMdPath}' frontmatter has changed. Run 'gh aw compile' to regenerate the lock file.`;
177213

178214
// Format timestamps and commits for display
179215
const workflowTimestamp = workflowDate.toISOString();

0 commit comments

Comments
 (0)