Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): remove dead ci-master-status workflow (#65473)

Raúl Negrón-Otero72eb2da04086
diff --git a/.github/scripts/master-ci-status.js b/.github/scripts/master-ci-status.js
deleted file mode 100644
index 30be62d4534f..000000000000
--- a/.github/scripts/master-ci-status.js
+++ /dev/null
@@ -1,184 +0,0 @@
-// Master CI Status - Latching alarm model for tracking CI failures on master
-//
-// State structure:
-// {
-// channel: string, // Slack channel ID
-// ts: string, // Slack message timestamp (thread parent)
-// since: string, // ISO timestamp of incident start
-// sha_ts: {[sha]: number}, // sha -> commit timestamp (epoch ms)
-// fail_ts: {[workflow]: number}, // workflow -> timestamp of last failure
-// ok_ts: {[workflow]: number} // workflow -> timestamp of last success
-// }
-//
-// A workflow is "known failing" iff fail_ts[w] > ok_ts[w]
-// Resolution occurs when no workflows are known failing
-
-const STATE_FILE = '.master-ci-incident'
-
-async function getCommitTimestamp(github, context, sha) {
- const { data } = await github.rest.repos.getCommit({
- owner: context.repo.owner,
- repo: context.repo.repo,
- ref: sha,
- })
- const iso = data.commit.committer?.date ?? data.commit.author?.date
- return new Date(iso).getTime()
-}
-
-function getFailingWorkflows(state) {
- return Object.entries(state.fail_ts)
- .filter(([wf, ts]) => ts > (state.ok_ts[wf] ?? 0))
- .map(([wf]) => wf)
-}
-
-function pruneOldShas(state) {
- // Remove sha_ts entries older than the minimum ok_ts.
- // Once all workflows have passed on a commit newer than a SHA,
- // that SHA's timestamp is no longer needed for ordering comparisons.
- const okTimestamps = Object.values(state.ok_ts)
- if (okTimestamps.length === 0) return
-
- const minOkTs = Math.min(...okTimestamps)
- for (const sha of Object.keys(state.sha_ts)) {
- if (state.sha_ts[sha] < minOkTs) {
- delete state.sha_ts[sha]
- }
- }
-}
-
-function handleFailure(state, event, commitTs, core, fs) {
- const isNew = !state
-
- if (isNew) {
- state = {
- // Use the failing commit's timestamp as incident start, not wall clock.
- // This ensures pendingWorkflows check compares against when the failure
- // was authored, not when we detected it (which could be much later).
- since: new Date(commitTs).toISOString(),
- sha_ts: { [event.head_sha]: commitTs },
- fail_ts: { [event.name]: commitTs },
- ok_ts: {},
- }
- } else {
- // Record this SHA's timestamp
- state.sha_ts[event.head_sha] = commitTs
- // Update fail_ts: max of current and new timestamp
- state.fail_ts[event.name] = Math.max(state.fail_ts[event.name] ?? 0, commitTs)
- }
-
- const failing = getFailingWorkflows(state)
- pruneOldShas(state)
- fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2))
-
- core.setOutput('action', isNew ? 'create' : 'update')
- core.setOutput('failing_workflows', failing.join(', '))
- core.setOutput('failing_count', String(failing.length))
- core.setOutput('commit_count', String(Object.keys(state.sha_ts).length))
- core.setOutput('save_cache', 'true')
- // Delete old caches when creating new incident to prevent divergent cache branches
- core.setOutput('delete_old_caches', isNew ? 'true' : 'false')
-
- console.log(`Action: ${isNew ? 'create' : 'update'}`)
- console.log(`Failing workflows: ${failing.join(', ')}`)
- console.log(`State:`, JSON.stringify(state, null, 2))
-}
-
-function handleSuccess(state, event, commitTs, core, fs) {
- if (!state) {
- core.setOutput('action', 'none')
- core.setOutput('save_cache', 'false')
- console.log('No incident exists, nothing to do')
- return
- }
-
- // Check if this workflow was failing before this success
- const wasFailing =
- (state.fail_ts[event.name] ?? 0) > (state.ok_ts[event.name] ?? 0) && commitTs > (state.fail_ts[event.name] ?? 0)
-
- // Record this SHA's timestamp
- state.sha_ts[event.head_sha] = commitTs
- // Update ok_ts: max of current and new timestamp
- state.ok_ts[event.name] = Math.max(state.ok_ts[event.name] ?? 0, commitTs)
-
- const failing = getFailingWorkflows(state)
-
- // Check all required workflows have passed since incident start
- const requiredWorkflows = (process.env.REQUIRED_WORKFLOWS || '').split(',').filter(Boolean)
- const incidentStart = new Date(state.since).getTime()
- const pendingWorkflows = requiredWorkflows.filter((wf) => (state.ok_ts[wf] ?? 0) < incidentStart)
- const resolved = failing.length === 0 && pendingWorkflows.length === 0
-
- if (resolved) {
- state.resolved = true
- }
-
- pruneOldShas(state)
- fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2))
-
- core.setOutput('action', wasFailing ? 'resolve' : 'none')
- core.setOutput('recovered_workflow', wasFailing ? event.name : '')
- core.setOutput('still_failing', failing.join(', '))
- core.setOutput('commit_count', String(Object.keys(state.sha_ts).length))
- core.setOutput('resolved', resolved ? 'true' : 'false')
- core.setOutput('since', state.since)
- core.setOutput('channel', state.channel || '')
- core.setOutput('ts', state.ts || '')
- // Only save cache when state changes meaningfully:
- // - when a failing workflow recovers (wasFailing => action='resolve'), or
- // - when the incident becomes fully resolved (resolved=true)
- // Avoid saving on plain 'none' to prevent creating divergent cache branches.
- core.setOutput('save_cache', wasFailing || resolved ? 'true' : 'false')
-
- console.log(`Action: ${wasFailing ? 'resolve' : 'none'}`)
- console.log(`Recovered: ${wasFailing ? event.name : 'none'}`)
- console.log(`Still failing: ${failing.join(', ') || 'none'}`)
- console.log(`Pending (not passed since incident): ${pendingWorkflows.join(', ') || 'none'}`)
- console.log(`State:`, JSON.stringify(state, null, 2))
-}
-
-module.exports = async ({ github, context, core }) => {
- const fs = require('fs')
- const event = context.payload.workflow_run
- const conclusion = event.conclusion
-
- console.log(`Processing ${event.name} (${conclusion}) for ${event.head_sha.substring(0, 7)}`)
-
- // Read existing state
- let state = null
- if (fs.existsSync(STATE_FILE)) {
- try {
- const raw = JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'))
- // If incident was already resolved, treat as no incident
- if (raw.resolved) {
- console.log('Found resolved incident, treating as no active incident')
- } else {
- // Ensure required fields exist (handles old format or corrupted state)
- state = {
- ...raw,
- sha_ts: raw.sha_ts || {},
- fail_ts: raw.fail_ts || {},
- ok_ts: raw.ok_ts || {},
- }
- console.log('Loaded existing incident state')
- }
- } catch (e) {
- console.log('Failed to parse state file, treating as no incident')
- }
- }
-
- // Get commit timestamp from GitHub API
- const commitTs = await getCommitTimestamp(github, context, event.head_sha)
- console.log(`Commit timestamp: ${new Date(commitTs).toISOString()}`)
-
- // Handle based on conclusion
- if (conclusion === 'failure' || conclusion === 'timed_out') {
- handleFailure(state, event, commitTs, core, fs)
- } else if (conclusion === 'success') {
- handleSuccess(state, event, commitTs, core, fs)
- } else {
- // Ignore cancelled, skipped, etc. - no state change
- core.setOutput('action', 'none')
- core.setOutput('save_cache', 'false')
- console.log(`Ignoring ${conclusion} conclusion`)
- }
-}
diff --git a/.github/scripts/master-ci-status.test.js b/.github/scripts/master-ci-status.test.js
deleted file mode 100644
index b904d963553a..000000000000
--- a/.github/scripts/master-ci-status.test.js
+++ /dev/null
@@ -1,510 +0,0 @@
-const fs = require('fs')
-
-jest.mock('fs')
-
-const masterCiStatus = require('./master-ci-status')
-
-const STATE_FILE = '.master-ci-incident'
-
-// Timestamps for testing (in order: T1 < T2 < T3 < T4)
-const T1 = 1700000000000 // oldest
-const T2 = 1700001000000
-const T3 = 1700002000000
-const T4 = 1700003000000 // newest
-
-function createMocks() {
- const outputs = {}
- const core = {
- setOutput: jest.fn((key, value) => {
- outputs[key] = value
- }),
- }
- return { core, outputs }
-}
-
-function createContext(name, conclusion, headSha) {
- return {
- repo: { owner: 'PostHog', repo: 'posthog' },
- payload: {
- workflow_run: {
- name,
- conclusion,
- head_sha: headSha,
- },
- },
- }
-}
-
-function createGithubMock(commitTs) {
- return {
- rest: {
- repos: {
- getCommit: jest.fn().mockResolvedValue({
- data: {
- commit: {
- committer: { date: new Date(commitTs).toISOString() },
- },
- },
- }),
- },
- },
- }
-}
-
-describe('master-ci-status', () => {
- beforeEach(() => {
- jest.clearAllMocks()
- fs.existsSync.mockReturnValue(false)
- fs.readFileSync.mockReturnValue('{}')
- fs.writeFileSync.mockImplementation(() => {})
- })
-
- describe('new incident (no existing state)', () => {
- it('creates incident on first failure', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'failure', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('create')
- expect(outputs.failing_workflows).toBe('Backend CI')
- expect(outputs.failing_count).toBe('1')
- expect(outputs.commit_count).toBe('1')
- expect(outputs.save_cache).toBe('true')
- expect(outputs.delete_old_caches).toBe('true')
-
- // Verify state was written with timestamps
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.fail_ts['Backend CI']).toBe(T1)
- expect(writtenState.sha_ts['abc1234']).toBe(T1)
- })
-
- it('creates incident on timed_out', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'timed_out', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('create')
- expect(outputs.failing_workflows).toBe('Backend CI')
- })
-
- it('does nothing on success with no incident', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'success', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('none')
- expect(outputs.save_cache).toBe('false')
- })
-
- it('ignores cancelled workflows', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'cancelled', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('none')
- expect(outputs.save_cache).toBe('false')
- })
-
- it('ignores skipped workflows', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'skipped', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('none')
- expect(outputs.save_cache).toBe('false')
- })
- })
-
- describe('existing incident', () => {
- const existingState = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { abc1234: T1 },
- fail_ts: { 'Backend CI': T1 },
- ok_ts: {},
- }
-
- beforeEach(() => {
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(existingState))
- })
-
- it('updates on second failure (same workflow, newer commit)', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T2) // Newer commit
- const context = createContext('Backend CI', 'failure', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('update')
- expect(outputs.failing_workflows).toBe('Backend CI')
- expect(outputs.failing_count).toBe('1')
- expect(outputs.commit_count).toBe('2')
- expect(outputs.delete_old_caches).toBe('false') // Only delete on create
-
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.fail_ts['Backend CI']).toBe(T2) // Updated to newer
- })
-
- it('updates on failure of different workflow', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T2)
- const context = createContext('Frontend CI', 'failure', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('update')
- expect(outputs.failing_workflows).toContain('Backend CI')
- expect(outputs.failing_workflows).toContain('Frontend CI')
- expect(outputs.failing_count).toBe('2')
- })
-
- it('does not resolve when different workflow succeeds', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T2)
- const context = createContext('Frontend CI', 'success', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('none')
- expect(outputs.resolved).toBe('false')
- expect(outputs.still_failing).toBe('Backend CI')
- expect(outputs.save_cache).toBe('false') // Don't save on 'none' to prevent divergent branches
- })
-
- it('resolves when failing workflow succeeds on newer commit', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T2) // Newer than T1
- const context = createContext('Backend CI', 'success', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('resolve')
- expect(outputs.resolved).toBe('true')
- expect(outputs.still_failing).toBe('')
- expect(outputs.save_cache).toBe('true') // Save to persist resolved state
- })
-
- it('does NOT resolve when failing workflow succeeds on older commit', async () => {
- // State: Backend CI failed at T2
- fs.readFileSync.mockReturnValue(
- JSON.stringify({
- ...existingState,
- fail_ts: { 'Backend CI': T2 },
- })
- )
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1) // Older than T2
- const context = createContext('Backend CI', 'success', 'older123')
-
- await masterCiStatus({ github, context, core })
-
- // T1 < T2, so ok_ts (T1) is not > fail_ts (T2), still failing
- expect(outputs.action).toBe('none')
- expect(outputs.resolved).toBe('false')
- expect(outputs.still_failing).toBe('Backend CI')
- })
-
- it('does not resolve when success is on same timestamp as failure', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1) // Same as fail timestamp
- const context = createContext('Backend CI', 'success', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- // Success must be strictly newer than failure to count as recovery
- expect(outputs.action).toBe('none')
- })
- })
-
- describe('multiple workflows failing', () => {
- const multiFailState = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { abc1234: T1, def5678: T2 },
- fail_ts: { 'Backend CI': T1, 'Frontend CI': T2 },
- ok_ts: {},
- }
-
- beforeEach(() => {
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(multiFailState))
- })
-
- it('clears one workflow but not the other', async () => {
- const { core, outputs } = createMocks()
- const github = createGithubMock(T3) // Newer than both T1 and T2
- const context = createContext('Backend CI', 'success', 'ghi9012')
-
- await masterCiStatus({ github, context, core })
-
- // Backend CI recovered, but Frontend CI still failing
- expect(outputs.action).toBe('resolve')
- expect(outputs.recovered_workflow).toBe('Backend CI')
- expect(outputs.resolved).toBe('false')
- expect(outputs.still_failing).toBe('Frontend CI')
- })
-
- it('resolves when all workflows cleared', async () => {
- // Backend CI already cleared
- fs.readFileSync.mockReturnValue(
- JSON.stringify({
- ...multiFailState,
- ok_ts: { 'Backend CI': T3 },
- })
- )
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T4) // Newer than T2
- const context = createContext('Frontend CI', 'success', 'jkl3456')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('resolve')
- expect(outputs.resolved).toBe('true')
- })
- })
-
- describe('out-of-order events (timestamp-based)', () => {
- it('older failure does not overwrite newer failure timestamp', async () => {
- const stateWithNewerFailure = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { abc1234: T1, def5678: T2 },
- fail_ts: { 'Backend CI': T2 }, // Failed at T2
- ok_ts: {},
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(stateWithNewerFailure))
-
- const { core } = createMocks()
- const github = createGithubMock(T1) // Older commit
- const context = createContext('Backend CI', 'failure', 'abc1234')
-
- await masterCiStatus({ github, context, core })
-
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.fail_ts['Backend CI']).toBe(T2) // Still T2, not T1
- })
-
- it('older success does not overwrite newer success timestamp', async () => {
- const stateWithNewerSuccess = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { abc1234: T1, def5678: T2, ghi9012: T3 },
- fail_ts: { 'Backend CI': T1 },
- ok_ts: { 'Backend CI': T3 }, // Succeeded at T3
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(stateWithNewerSuccess))
-
- const { core } = createMocks()
- const github = createGithubMock(T2) // Older than T3
- const context = createContext('Backend CI', 'success', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.ok_ts['Backend CI']).toBe(T3) // Still T3, not T2
- })
-
- it('newer success clears older failure', async () => {
- const state = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { abc1234: T1 },
- fail_ts: { 'Backend CI': T1 },
- ok_ts: {},
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(state))
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T2) // Newer than T1
- const context = createContext('Backend CI', 'success', 'def5678')
-
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('resolve')
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.ok_ts['Backend CI']).toBe(T2)
- })
- })
-
- describe('state validation', () => {
- it('handles missing fields gracefully', async () => {
- // Old format or corrupted state
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(
- JSON.stringify({
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- // Missing sha_ts, fail_ts, ok_ts
- })
- )
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'success', 'abc1234')
-
- // Should not throw
- await masterCiStatus({ github, context, core })
-
- // No failures tracked, so nothing to recover from
- expect(outputs.action).toBe('none')
- expect(outputs.resolved).toBe('true') // No failures = resolved
- })
-
- it('handles JSON parse error', async () => {
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue('not valid json')
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T1)
- const context = createContext('Backend CI', 'failure', 'abc1234')
-
- // Should not throw, treat as new incident
- await masterCiStatus({ github, context, core })
-
- expect(outputs.action).toBe('create')
- })
- })
-
- describe('state pruning', () => {
- it('prunes old SHAs after success clears them', async () => {
- // State with multiple SHAs and one workflow with ok_ts
- const state = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { sha1: T1, sha2: T2, sha3: T3 },
- fail_ts: { 'Backend CI': T3 },
- ok_ts: { 'Frontend CI': T2 }, // Frontend passed at T2
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(state))
-
- const { core } = createMocks()
- const github = createGithubMock(T4)
- const context = createContext('Backend CI', 'success', 'sha4')
-
- await masterCiStatus({ github, context, core })
-
- // After Backend CI succeeds at T4, ok_ts has Frontend CI: T2, Backend CI: T4
- // min(ok_ts) = T2, so sha1 (T1 < T2) should be pruned
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.sha_ts.sha1).toBeUndefined() // Pruned (T1 < T2)
- expect(writtenState.sha_ts.sha2).toBe(T2) // Kept (T2 >= T2)
- expect(writtenState.sha_ts.sha3).toBe(T3) // Kept (T3 > T2)
- expect(writtenState.sha_ts.sha4).toBe(T4) // New SHA added
- })
-
- it('does not prune when no ok_ts exists', async () => {
- const state = {
- channel: 'C123',
- ts: '123.456',
- since: '2025-01-01T00:00:00Z',
- sha_ts: { sha1: T1, sha2: T2 },
- fail_ts: { 'Backend CI': T2 },
- ok_ts: {},
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(state))
-
- const { core } = createMocks()
- const github = createGithubMock(T3)
- const context = createContext('Frontend CI', 'failure', 'sha3')
-
- await masterCiStatus({ github, context, core })
-
- const writtenState = JSON.parse(fs.writeFileSync.mock.calls[0][1])
- expect(writtenState.sha_ts.sha1).toBe(T1) // Still there
- expect(writtenState.sha_ts.sha2).toBe(T2) // Still there
- expect(writtenState.sha_ts.sha3).toBe(T3) // New SHA added
- })
- })
-
- describe('required workflows check', () => {
- // Use T1 as incident start so T2/T3/T4 are all after it
- const incidentStartTs = T1
- const incidentStart = new Date(incidentStartTs).toISOString()
-
- beforeEach(() => {
- process.env.REQUIRED_WORKFLOWS = 'Backend CI,Frontend CI'
- })
-
- afterEach(() => {
- delete process.env.REQUIRED_WORKFLOWS
- })
-
- it('does not fully resolve if required workflow has not passed since incident', async () => {
- const state = {
- channel: 'C123',
- ts: '123.456',
- since: incidentStart,
- sha_ts: { abc: T2 },
- fail_ts: { 'Backend CI': T2 },
- ok_ts: { 'Frontend CI': T1 - 1000 }, // Passed BEFORE incident
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(state))
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T4)
- const context = createContext('Backend CI', 'success', 'sha4')
-
- await masterCiStatus({ github, context, core })
-
- // Backend CI recovered, but Frontend CI hasn't passed since incident
- expect(outputs.action).toBe('resolve')
- expect(outputs.resolved).toBe('false') // Not fully resolved
- })
-
- it('fully resolves when all required workflows passed since incident', async () => {
- const state = {
- channel: 'C123',
- ts: '123.456',
- since: incidentStart,
- sha_ts: { abc: T2 },
- fail_ts: { 'Backend CI': T2 },
- ok_ts: { 'Frontend CI': T3 }, // Passed AFTER incident (T3 > T1)
- }
-
- fs.existsSync.mockReturnValue(true)
- fs.readFileSync.mockReturnValue(JSON.stringify(state))
-
- const { core, outputs } = createMocks()
- const github = createGithubMock(T4)
- const context = createContext('Backend CI', 'success', 'sha4')
-
- await masterCiStatus({ github, context, core })
-
- // Both required workflows have passed since incident
- expect(outputs.action).toBe('resolve')
- expect(outputs.resolved).toBe('true')
- })
- })
-})
diff --git a/.github/workflows/ci-master-status.yml b/.github/workflows/ci-master-status.yml
deleted file mode 100644
index 3d0e41e88192..000000000000
--- a/.github/workflows/ci-master-status.yml
+++ /dev/null
@@ -1,263 +0,0 @@
-name: Master CI Status
-
-on:
- workflow_run:
- workflows:
- - 'Backend CI'
- - 'Node.js CI'
- - 'Frontend CI'
- - 'Storybook'
- - 'Security'
- - 'Dagster CI'
- - 'E2E CI Playwright'
- - 'Rust CI'
- - 'LLM Services CI'
- branches: [master]
- types: [completed]
-
-env:
- SLACK_CHANNEL: 'C09ADEV3AJD'
- # Keep in sync with workflow_run.workflows trigger above
- REQUIRED_WORKFLOWS: 'Backend CI,Node.js CI,Frontend CI,Storybook,Security,Dagster CI,E2E CI Playwright,Rust CI,LLM Services CI'
-
-permissions:
- contents: read
- actions: write
-
-jobs:
- check-master-status:
- runs-on: ubuntu-latest
- timeout-minutes: 5
- if: github.event.workflow_run.event == 'push'
- steps:
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
-
- - name: Restore incident state
- uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
- with:
- path: .master-ci-incident
- # Use prefix matching to get the most recently saved cache
- key: master-ci-incident-${{ github.run_id }}
- restore-keys: master-ci-incident-
-
- - name: Read incident state
- id: incident
- run: |
- if [ -f .master-ci-incident ]; then
- echo "exists=true" >> $GITHUB_OUTPUT
- echo "channel=$(jq -r '.channel // empty' .master-ci-incident)" >> $GITHUB_OUTPUT
- echo "ts=$(jq -r '.ts // empty' .master-ci-incident)" >> $GITHUB_OUTPUT
- else
- echo "exists=false" >> $GITHUB_OUTPUT
- fi
-
- - name: Process workflow event
- id: process
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
- with:
- script: |
- const script = require('./.github/scripts/master-ci-status.js');
- await script({ github, context, core });
-
- - name: Get commit info
- id: commit
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
- with:
- script: |
- const sha = '${{ github.event.workflow_run.head_sha }}';
- const { data: commit } = await github.rest.repos.getCommit({
- owner: context.repo.owner,
- repo: context.repo.repo,
- ref: sha
- });
- core.setOutput('short_sha', sha.substring(0, 7));
- const message = commit.commit.message.split('\n')[0].substring(0, 50);
- // Escape quotes and backslashes for YAML
- const escapedMessage = message.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
- core.setOutput('message', escapedMessage);
- core.setOutput('author', commit.author?.login || commit.commit.author.name);
- core.setOutput('url', commit.html_url);
-
- # ============ SLACK: CREATE ============
-
- - name: Post new incident to Slack
- if: steps.process.outputs.action == 'create'
- id: slack_new
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.postMessage
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- errors: true
- payload: |
- channel: "${{ env.SLACK_CHANNEL }}"
- text: ":red_circle: Master is red (1 workflow failing)"
- blocks:
- - type: "section"
- text:
- type: "mrkdwn"
- text: ":red_circle: *Master is red* (1 workflow failing)"
- - type: "section"
- fields:
- - type: "mrkdwn"
- text: "*Failing*\n${{ github.event.workflow_run.name }}"
- - type: "mrkdwn"
- text: "*Author*\n${{ steps.commit.outputs.author }}"
- - type: "section"
- text:
- type: "mrkdwn"
- text: "*Commit*\n<${{ steps.commit.outputs.url }}|${{ steps.commit.outputs.short_sha }}> ${{ steps.commit.outputs.message }}"
- - type: "actions"
- elements:
- - type: "button"
- text:
- type: "plain_text"
- text: "View run"
- url: "${{ github.event.workflow_run.html_url }}"
-
- - name: Save Slack info to state
- if: steps.process.outputs.action == 'create'
- env:
- SLACK_CHANNEL_ID: ${{ steps.slack_new.outputs.channel_id }}
- SLACK_TS: ${{ steps.slack_new.outputs.ts }}
- run: |
- jq \
- --arg channel "$SLACK_CHANNEL_ID" \
- --arg ts "$SLACK_TS" \
- '. + {channel: $channel, ts: $ts}' \
- .master-ci-incident > .master-ci-incident.tmp
- mv .master-ci-incident.tmp .master-ci-incident
-
- # ============ SLACK: UPDATE ============
-
- - name: Update Slack message
- if: steps.process.outputs.action == 'update'
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.update
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- errors: true
- payload: |
- channel: "${{ steps.incident.outputs.channel }}"
- ts: "${{ steps.incident.outputs.ts }}"
- text: ":red_circle: Master is red (${{ steps.process.outputs.failing_count }} workflow(s) failing)"
- blocks:
- - type: "section"
- text:
- type: "mrkdwn"
- text: ":red_circle: *Master is red* (${{ steps.process.outputs.failing_count }} workflow(s) failing)"
- - type: "section"
- fields:
- - type: "mrkdwn"
- text: "*Failing*\n${{ steps.process.outputs.failing_workflows }}"
- - type: "mrkdwn"
- text: "*Commits*\n${{ steps.process.outputs.commit_count }}"
- - type: "section"
- text:
- type: "mrkdwn"
- text: "*Latest*\n<${{ steps.commit.outputs.url }}|${{ steps.commit.outputs.short_sha }}> ${{ steps.commit.outputs.message }} (${{ steps.commit.outputs.author }})"
- - type: "actions"
- elements:
- - type: "button"
- text:
- type: "plain_text"
- text: "View run"
- url: "${{ github.event.workflow_run.html_url }}"
-
- - name: Thread reply with failure
- if: steps.process.outputs.action == 'update'
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.postMessage
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- payload: |
- channel: "${{ steps.incident.outputs.channel }}"
- thread_ts: "${{ steps.incident.outputs.ts }}"
- text: "Also failing: *${{ github.event.workflow_run.name }}* (${{ steps.commit.outputs.short_sha }})\n<${{ github.event.workflow_run.html_url }}|View run>"
-
- # ============ SLACK: RESOLVE ============
-
- - name: Thread reply with recovery
- if: steps.process.outputs.action == 'resolve' && steps.process.outputs.resolved == 'false'
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.postMessage
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- payload: |
- channel: "${{ steps.incident.outputs.channel }}"
- thread_ts: "${{ steps.incident.outputs.ts }}"
- text: ":white_check_mark: Resolved: *${{ steps.process.outputs.recovered_workflow }}* (${{ steps.commit.outputs.short_sha }})"
-
- - name: Calculate duration
- if: steps.process.outputs.resolved == 'true'
- id: duration
- env:
- INCIDENT_SINCE: ${{ steps.process.outputs.since }}
- run: |
- since="$INCIDENT_SINCE"
- now=$(date +%s)
- then=$(date -d "$since" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$since" +%s 2>/dev/null || echo "$now")
- mins=$(( (now - then) / 60 ))
- echo "mins=$mins" >> $GITHUB_OUTPUT
-
- - name: Update Slack to resolved
- if: steps.process.outputs.resolved == 'true'
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.update
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- errors: true
- payload: |
- channel: "${{ steps.process.outputs.channel }}"
- ts: "${{ steps.process.outputs.ts }}"
- text: "Master recovered :v: (was red for ~${{ steps.duration.outputs.mins }} min)"
- blocks:
- - type: "section"
- text:
- type: "mrkdwn"
- text: "*Master recovered* :v: (was red for ~${{ steps.duration.outputs.mins }} min, ${{ steps.process.outputs.commit_count }} commits affected)"
- - type: "section"
- fields:
- - type: "mrkdwn"
- text: "*Resolved by*\n${{ github.event.workflow_run.name }} passed"
- - type: "mrkdwn"
- text: "*Author*\n${{ steps.commit.outputs.author }}"
- - type: "section"
- text:
- type: "mrkdwn"
- text: "*Commit*\n<${{ steps.commit.outputs.url }}|${{ steps.commit.outputs.short_sha }}> ${{ steps.commit.outputs.message }}"
-
- - name: Thread reply with resolution
- if: steps.process.outputs.resolved == 'true'
- uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
- with:
- method: chat.postMessage
- token: ${{ secrets.SLACK_BOT_TOKEN }}
- payload: |
- channel: "${{ steps.process.outputs.channel }}"
- thread_ts: "${{ steps.process.outputs.ts }}"
- text: ":white_check_mark: Resolved: *${{ github.event.workflow_run.name }}* passed (${{ steps.commit.outputs.short_sha }})"
-
- # ============ CACHE ============
- # Use unique keys to avoid race conditions where concurrent runs
- # delete the cache before saving (see logs showing "Cache not found")
-
- - name: Delete old caches on new incident
- if: steps.process.outputs.delete_old_caches == 'true'
- continue-on-error: true
- env:
- GH_TOKEN: ${{ github.token }}
- run: |
- # Delete ALL old incident caches to prevent divergent cache branches
- # This ensures the new incident cache becomes the single source of truth
- echo "Deleting old incident caches..."
- gh cache list --key master-ci-incident- --json id,key -q '.[] | "\(.id) \(.key)"' | while read id key; do
- echo "Deleting cache: $key"
- gh cache delete "$id" || true
- done
-
- - name: Save incident to cache
- if: steps.process.outputs.save_cache == 'true'
- uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
- with:
- path: .master-ci-incident
- key: master-ci-incident-${{ github.run_id }}