Skip to content
126 changes: 79 additions & 47 deletions .github/workflows/update-e2e-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ jobs:
with:
ref: main

- name: Get job statuses and update README
- name: Get job statuses
id: get-status
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

// Get the triggering workflow run or latest run
let runId;
if (context.payload.workflow_run) {
Expand All @@ -43,12 +42,15 @@ jobs:
});
if (runs.data.workflow_runs.length === 0) {
console.log('No workflow runs found');
core.setOutput('found', 'false');
return;
}
runId = runs.data.workflow_runs[0].id;
}

console.log(`Processing workflow run: ${runId}`);
core.setOutput('run-id', runId);
core.setOutput('run-url', `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`);

// Get jobs for this run
const jobs = await github.rest.actions.listJobsForWorkflowRun({
Expand All @@ -57,60 +59,90 @@ jobs:
run_id: runId
});

// Map job names to their status badges
// Map job names to their status
const jobStatusMap = {
'Python OpenAI Agent': { key: 'python-openai', label: 'Python OpenAI' },
'Node.js OpenAI Agent': { key: 'nodejs-openai', label: 'Node.js OpenAI' },
'.NET Semantic Kernel Agent': { key: 'dotnet-sk', label: '.NET Semantic Kernel' },
'.NET Agent Framework Agent': { key: 'dotnet-af', label: '.NET Agent Framework' }
'Python OpenAI Agent': 'python-openai',
'Node.js OpenAI Agent': 'nodejs-openai',
'.NET Semantic Kernel Agent': 'dotnet-sk',
'.NET Agent Framework Agent': 'dotnet-af'
};

const statuses = {};
for (const job of jobs.data.jobs) {
const mapping = jobStatusMap[job.name];
if (mapping) {
const conclusion = job.conclusion || job.status;
let badge;
if (conclusion === 'success') {
badge = `![${mapping.label}](https://img.shields.io/badge/${encodeURIComponent(mapping.label)}-passing-brightgreen)`;
} else if (conclusion === 'failure') {
badge = `![${mapping.label}](https://img.shields.io/badge/${encodeURIComponent(mapping.label)}-failing-red)`;
} else if (conclusion === 'in_progress' || job.status === 'in_progress') {
badge = `![${mapping.label}](https://img.shields.io/badge/${encodeURIComponent(mapping.label)}-running-yellow)`;
} else {
badge = `![${mapping.label}](https://img.shields.io/badge/${encodeURIComponent(mapping.label)}-pending-lightgrey)`;
}
statuses[mapping.key] = badge;
console.log(`${job.name}: ${conclusion} -> ${badge}`);
const key = jobStatusMap[job.name];
if (key) {
const conclusion = job.conclusion || job.status || 'unknown';
core.setOutput(key, conclusion);
console.log(`${job.name}: ${conclusion}`);
}
}

// Read current README
let readme = fs.readFileSync('README.md', 'utf8');

// Generate new status table
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const newTable = `## E2E Test Status
core.setOutput('found', 'true');
Comment thread
rahuldevikar761 marked this conversation as resolved.
Outdated
core.setOutput('date', new Date().toISOString().split('T')[0]);

| Sample | Status |
|--------|--------|
| Python OpenAI | ${statuses['python-openai'] || '![Python OpenAI](https://img.shields.io/badge/Python%20OpenAI-unknown-lightgrey)'} |
| Node.js OpenAI | ${statuses['nodejs-openai'] || '![Node.js OpenAI](https://img.shields.io/badge/Node.js%20OpenAI-unknown-lightgrey)'} |
| .NET Semantic Kernel | ${statuses['dotnet-sk'] || '![.NET SK](https://img.shields.io/badge/.NET%20SK-unknown-lightgrey)'} |
| .NET Agent Framework | ${statuses['dotnet-af'] || '![.NET AF](https://img.shields.io/badge/.NET%20AF-unknown-lightgrey)'} |
- name: Update README
if: steps.get-status.outputs.found == 'true'
env:
PYTHON_STATUS: ${{ steps.get-status.outputs.python-openai }}
NODEJS_STATUS: ${{ steps.get-status.outputs.nodejs-openai }}
DOTNET_SK_STATUS: ${{ steps.get-status.outputs.dotnet-sk }}
DOTNET_AF_STATUS: ${{ steps.get-status.outputs.dotnet-af }}
RUN_URL: ${{ steps.get-status.outputs.run-url }}
UPDATE_DATE: ${{ steps.get-status.outputs.date }}
run: |
python3 << 'EOF'
import os
import re

def create_badge(name, status):
encoded_name = name.replace(' ', '%20').replace('.', '%2E')
Comment thread
rahuldevikar761 marked this conversation as resolved.
Outdated
if status == 'success':
return f'![{name}](https://img.shields.io/badge/{encoded_name}-passing-brightgreen)'
elif status == 'failure':
return f'![{name}](https://img.shields.io/badge/{encoded_name}-failing-red)'
elif status == 'in_progress':
return f'![{name}](https://img.shields.io/badge/{encoded_name}-running-yellow)'
else:
return f'![{name}](https://img.shields.io/badge/{encoded_name}-unknown-lightgrey)'

python_badge = create_badge('Python OpenAI', os.environ.get('PYTHON_STATUS', 'unknown'))
nodejs_badge = create_badge('Node.js OpenAI', os.environ.get('NODEJS_STATUS', 'unknown'))
dotnet_sk_badge = create_badge('.NET SK', os.environ.get('DOTNET_SK_STATUS', 'unknown'))
dotnet_af_badge = create_badge('.NET AF', os.environ.get('DOTNET_AF_STATUS', 'unknown'))
run_url = os.environ.get('RUN_URL', '#')
update_date = os.environ.get('UPDATE_DATE', 'unknown')
Comment thread
rahuldevikar761 marked this conversation as resolved.
Outdated

new_section = f'''## E2E Test Status

*Last updated: ${new Date().toISOString().split('T')[0]} | [View Run](${runUrl})*`;

// Replace the status section
const statusRegex = /## E2E Test Status[\s\S]*?\n(?=\n>|$)/;
if (statusRegex.test(readme)) {
readme = readme.replace(statusRegex, newTable + '\n');
}

fs.writeFileSync('README.md', readme);
console.log('README updated successfully');
| Sample | Status |
|--------|--------|
| Python OpenAI | {python_badge} |
| Node.js OpenAI | {nodejs_badge} |
| .NET Semantic Kernel | {dotnet_sk_badge} |
| .NET Agent Framework | {dotnet_af_badge} |

*Last updated: {update_date} | [View Run]({run_url})*

'''

# Remove leading spaces from heredoc
new_section = '\n'.join(line.lstrip() for line in new_section.split('\n'))
Comment thread
rahuldevikar761 marked this conversation as resolved.
Outdated

with open('README.md', 'r') as f:
content = f.read()

# Pattern to match the E2E Test Status section until the next section
pattern = r'## E2E Test Status\n.*?(?=\n> ####|\n## [^E]|\Z)'
Comment thread
rahuldevikar761 marked this conversation as resolved.
Outdated

if re.search(pattern, content, re.DOTALL):
content = re.sub(pattern, new_section, content, flags=re.DOTALL)
with open('README.md', 'w') as f:
f.write(content)
print('README updated successfully')
else:
print('E2E Test Status section not found')
EOF

- name: Commit and push changes
if: steps.get-status.outputs.found == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
Expand Down