Update the argument type of outputs (#198) #23
This file contains 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: Update Test Report Issue | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
update-report: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
- name: Install dependencies | |
run: | | |
pip install pytest pytest-html pytest-json-report | |
- name: Generate timestamp | |
id: timestamp | |
run: | | |
echo "timestamp=$(date +%Y%m%d_%H%M%S)" >> $GITHUB_ENV | |
echo "formatted_date=$(date -u '+%A, %B %d, %Y %H:%M:%S')" >> $GITHUB_ENV | |
- name: Run tests | |
run: | | |
pytest --tb=no --html=report.html --self-contained-html --json-report --json-report-file=report.json tests | |
continue-on-error: true | |
- name: Checkout pages repo | |
uses: actions/checkout@v4 | |
with: | |
repository: childmindresearch/niwrap-test-report | |
token: ${{ secrets.PAGES_DEPLOY_TOKEN }} | |
path: pages-repo | |
- name: Copy report to pages repo | |
run: | | |
mkdir -p pages-repo/test-reports | |
cp report.html pages-repo/test-reports/latest.html | |
cp report.html "pages-repo/test-reports/report-${{ env.timestamp }}-${GITHUB_SHA}.html" | |
- name: Clean old reports | |
run: | | |
cd pages-repo/test-reports | |
# Keep latest 30 reports plus latest.html | |
ls -t report-* | tail -n +31 | xargs -r rm | |
- name: Update index | |
run: | | |
cd pages-repo | |
cat > test-reports/index.html << EOF | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test Report History</title> | |
<style> | |
body { | |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; | |
max-width: 1200px; | |
margin: 0 auto; | |
padding: 20px; | |
} | |
table { | |
width: 100%; | |
border-collapse: collapse; | |
margin-top: 20px; | |
} | |
th, td { | |
padding: 12px; | |
text-align: left; | |
border-bottom: 1px solid #ddd; | |
} | |
th { | |
background-color: #f6f8fa; | |
} | |
tr:hover { | |
background-color: #f6f8fa; | |
} | |
a { | |
color: #0366d6; | |
text-decoration: none; | |
} | |
a:hover { | |
text-decoration: underline; | |
} | |
.latest { | |
margin: 20px 0; | |
padding: 15px; | |
background-color: #f6f8fa; | |
border-radius: 6px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Test Report History</h1> | |
<div class="latest"> | |
<h2>Latest Report</h2> | |
<p><a href="latest.html?sort=result&visible=failed,error,xfailed,xpassed,rerun">View Latest Test Results</a></p> | |
</div> | |
<h2>Historical Reports</h2> | |
<table> | |
<thead> | |
<tr> | |
<th>Date</th> | |
<th>Commit</th> | |
<th>Report</th> | |
</tr> | |
</thead> | |
<tbody> | |
EOF | |
ls -t test-reports/report-* | while read file; do | |
filename=$(basename "$file") | |
# Extract date and time parts (assuming format: report-YYYYMMDD_HHMMSS-COMMIT.html) | |
datetime_part=$(echo $filename | cut -d'-' -f2) | |
commit=$(echo $filename | cut -d'-' -f3 | cut -d'.' -f1) | |
# Parse date and time | |
year=${datetime_part:0:4} | |
month=${datetime_part:4:2} | |
day=${datetime_part:6:2} | |
hour=${datetime_part:9:2} | |
minute=${datetime_part:11:2} | |
second=${datetime_part:13:2} | |
# Format date | |
formatted_date="$year-$month-$day $hour:$minute:$second" | |
echo "<tr><td>$formatted_date</td><td><a href='https://github.com/${GITHUB_REPOSITORY}/commit/$commit'>${commit:0:7}</a></td><td><a href=\"$filename?sort=result&visible=failed,error,xfailed,xpassed,rerun\">View Report</a></td></tr>" >> test-reports/index.html | |
done | |
cat >> test-reports/index.html << EOF | |
</tbody> | |
</table> | |
<footer style="margin-top: 40px; text-align: center; color: #586069;"> | |
<p>Generated by GitHub Actions</p> | |
</footer> | |
</body> | |
</html> | |
EOF | |
- name: Commit and push to pages repo | |
run: | | |
cd pages-repo | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add test-reports/ | |
git commit -m "Update test report from ${{ github.repository }} @ ${{ github.sha }}" | |
git push | |
- name: Update Report Issue | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const report = JSON.parse(fs.readFileSync('report.json', 'utf8')); | |
const ISSUE_NUMBER = 186; | |
const REPORT_PARAMS = '?sort=result&visible=failed,error,xfailed,xpassed,rerun'; | |
function formatPercentage(part, total) { | |
return ((part / total) * 100).toFixed(1) + '%'; | |
} | |
const summary = ` | |
# Test Status Report | |
Last updated: ${{ env.formatted_date }} UTC | |
## Test Coverage | |
| Category | Count | Percentage | | |
|----------|--------|------------| | |
| ✓ Passing | ${report.summary.passed} | ${formatPercentage(report.summary.passed, report.summary.total)} | | |
| × Failing | ${report.summary.failed} | ${formatPercentage(report.summary.failed, report.summary.total)} | | |
| ⚠ Skipped | ${report.summary.skipped || 0} | ${formatPercentage(report.summary.skipped || 0, report.summary.total)} | | |
| **Total** | **${report.summary.total}** | **100%** | | |
Test duration: ${Math.floor(report.duration * 100) / 100}s | |
## Quick Links | |
📊 [Latest Results](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/latest.html${REPORT_PARAMS}) | |
📈 [Historical Reports](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/index.html) | |
🔍 [This Run](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/report-${{ env.timestamp }}-${context.sha}.html${REPORT_PARAMS}) | |
## Build Details | |
| Category | Detail | | |
|----------|---------| | |
| Branch | \`main\` | | |
| Commit | [\`${context.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}) | | |
| Action | [View Run](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) | | |
<sub>🤖 Auto-generated on main branch updates | [View Test Configuration](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/main/tests)</sub> | |
`; | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: ISSUE_NUMBER, | |
body: summary | |
}); |