Consolidate to pyproject.toml #33
Workflow file for this run
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: Post screenshots | |
on: | |
pull_request_target: | |
jobs: | |
post: | |
name: Python | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
SCREENSHOTS_BRANCH: "pr-screenshots" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
- name: Install deps | |
run: | | |
pip install -r requirements.txt | |
playwright install | |
- name: Create Screenshots - CLI | |
run: | | |
msp simulate --length 1000 --recombination-rate 0.01 --mutation-rate 0.01 100 out.trees | |
python -m tsbrowse preprocess out.trees | |
python -m tsbrowse screenshot out.tsbrowse mutations | |
python -m tsbrowse screenshot out.tsbrowse edges | |
python -m tsbrowse screenshot out.tsbrowse nodes | |
- name: Create Screenshots - WEB | |
run: | | |
python -m pytest --save-screenshots tests/test_ui.py | |
- name: Commit Screenshots | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email '[email protected]' | |
pr_number="${{ github.event.pull_request.number }}" | |
screenshot_dir="pr_${pr_number}" | |
if ! git ls-remote --exit-code --heads origin $SCREENSHOTS_BRANCH; then | |
git checkout --orphan $SCREENSHOTS_BRANCH | |
git rm -rf . | |
git commit --allow-empty -m "Initial commit for screenshots branch" | |
git push origin $SCREENSHOTS_BRANCH | |
else | |
git fetch origin $SCREENSHOTS_BRANCH | |
git checkout $SCREENSHOTS_BRANCH | |
fi | |
mkdir -p $screenshot_dir | |
mv *.png $screenshot_dir/ | |
git add $screenshot_dir | |
git commit -m "Update screenshots for PR #${pr_number}" | |
git push origin $SCREENSHOTS_BRANCH | |
- name: Update or Post Comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs').promises; | |
const prNumber = context.payload.pull_request.number; | |
const screenshotDir = `pr_${prNumber}`; | |
const pngFiles = (await fs.readdir(screenshotDir)).filter(file => file.endsWith('.png')); | |
let commentBody = '## Automated Screenshots\n\n'; | |
commentBody += 'These screenshots are automatically updated as the PR changes.\n\n'; | |
commentBody += '<details><summary>Click to view screenshots</summary>\n\n'; | |
for (const file of pngFiles) { | |
const imageUrl = `https://raw.githubusercontent.com/${context.repo.owner}/${context.repo.repo}/${process.env.SCREENSHOTS_BRANCH}/${screenshotDir}/${file}`; | |
commentBody += `### ${file}\n\n![${file}](${imageUrl})\n\n`; | |
} | |
commentBody += '</details>'; | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
}); | |
const botComment = comments.find(comment => | |
comment.user.type === 'Bot' && comment.body.includes('## Automated Screenshots') | |
); | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body: commentBody, | |
}); | |
console.log('Updated existing comment'); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: commentBody, | |
}); | |
console.log('Created new comment'); | |
} |