Skip to content

feat: Add CLI arguments support for LaunchAndKill action #3

feat: Add CLI arguments support for LaunchAndKill action

feat: Add CLI arguments support for LaunchAndKill action #3

name: PR Screenshots
# Triggered when a maintainer adds the 'run-tests' label to a PR.
on:
pull_request:
types: [labeled]
jobs:
screenshots:
if: github.event.label.name == 'run-tests'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
actions: read
steps:
- name: Checkout PR
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Run screenshot tests
run: dotnet test tests/TimeToKill.App.Tests/ --verbosity normal
- name: Validate screenshot sizes
run: |
MAX_SIZE=$((5 * 1024 * 1024)) # 5MB per file
SCREENSHOTS_DIR="tests/TimeToKill.App.Tests/bin/Debug/net10.0/Screenshots"
if [ -d "$SCREENSHOTS_DIR" ]; then
for f in "$SCREENSHOTS_DIR"/*.png; do
size=$(stat -c%s "$f")
if [ "$size" -gt "$MAX_SIZE" ]; then
echo "::error::Screenshot $(basename $f) is ${size} bytes (max ${MAX_SIZE}). Aborting upload."
exit 1
fi
echo "$(basename $f): ${size} bytes - OK"
done
else
echo "::warning::No screenshots directory found"
fi
- name: Upload screenshots
uses: actions/upload-artifact@v4
if: always()
with:
name: screenshots
path: tests/TimeToKill.App.Tests/bin/Debug/net10.0/Screenshots/
if-no-files-found: warn
- name: Comment on PR with screenshots
if: success()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const screenshotsDir = 'tests/TimeToKill.App.Tests/bin/Debug/net10.0/Screenshots';
let files = [];
if (fs.existsSync(screenshotsDir)) {
files = fs.readdirSync(screenshotsDir)
.filter(f => f.endsWith('.png'))
.sort();
}
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
let body = `## Screenshot Results\n\n`;
body += `**${files.length}** screenshots captured from headless UI tests.\n\n`;
if (files.length > 0) {
body += `| # | Screenshot |\n|---|---|\n`;
for (const f of files) {
body += `| ${f} | :white_check_mark: |\n`;
}
body += `\n`;
}
body += `[Download screenshots](${runUrl}#artifacts) from the workflow run artifacts.\n\n`;
body += `---\n_Generated by [PR Screenshots workflow](${runUrl})_`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
- name: Remove run-tests label
if: always()
uses: actions/github-script@v7
with:
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'run-tests'
});
} catch (e) {
// Label may have already been removed
console.log('Could not remove label:', e.message);
}