Status Check: Validate All Workflows #384
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Status Check: Validate All Workflows" | |
| on: | |
| schedule: | |
| - cron: '0 9 * * *' # Daily at 9am UTC | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| check-status: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check workflow statuses | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const workflows = [ | |
| 'coverage.yml', | |
| 'daily-erb-lint.yml', | |
| 'daily-standardrb.yml', | |
| 'security-scan.yml', | |
| 'test-ruby.yml', | |
| 'weekly-updates.yml' | |
| ]; | |
| const getWorkflowRun = async (workflow) => { | |
| const { data } = await github.rest.actions.listWorkflowRuns({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: workflow, | |
| per_page: 1 | |
| }); | |
| return data.workflow_runs[0]; | |
| }; | |
| const statusEmoji = (status, conclusion) => { | |
| if (status === 'in_progress' || status === 'queued') return '🚴'; | |
| return { | |
| 'success': '💚', | |
| 'failure': '💀', | |
| 'cancelled': '⚠️' | |
| }[conclusion] || '❓'; | |
| }; | |
| const timeAgo = (date) => { | |
| const seconds = Math.floor((new Date() - date) / 1000); | |
| const minutes = Math.floor(seconds / 60); | |
| const hours = Math.floor(minutes / 60); | |
| const days = Math.floor(hours / 24); | |
| if (days > 0) return `${days} day${days === 1 ? '' : 's'} ago`; | |
| if (hours > 0) return `${hours} hour${hours === 1 ? '' : 's'} ago`; | |
| if (minutes > 0) return `${minutes} minute${minutes === 1 ? '' : 's'} ago`; | |
| return 'just now'; | |
| }; | |
| const results = await Promise.all( | |
| workflows.map(async (workflow) => { | |
| const run = await getWorkflowRun(workflow); | |
| if (!run) return `⏳ ${workflow} - no runs yet`; | |
| const emoji = statusEmoji(run.status, run.conclusion); | |
| const runDate = new Date(run.created_at); | |
| const ago = timeAgo(runDate); | |
| return `${emoji} [${workflow}](${run.html_url}) - ${ago}`; | |
| }) | |
| ); | |
| const report = `## Workflow Status\n\n${results.map(r => `- ${r}`).join('\n')}`; | |
| const allPassed = !results.some(r => r.includes('💀')); | |
| await core.summary.addRaw(report).write(); | |
| core.setOutput('all_passed', allPassed); | |
| console.log(report); | |
| if (!allPassed) core.warning('Some workflows have failed'); |