forked from tskit-dev/tsbrowse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/savitakartik/tsinfer-qc
- Loading branch information
Showing
26 changed files
with
1,751 additions
and
1,365 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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 | ||
|
||
- name: Create Screenshots | ||
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: 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\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'); | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import os | ||
|
||
import tszip | ||
from click.testing import CliRunner | ||
from PIL import Image | ||
|
||
from . import test_preprocess | ||
from tsbrowse import __main__ as main | ||
|
||
|
||
def test_preprocess_cli(tmpdir): | ||
tszip_path = os.path.join(tmpdir, "test_input.tszip") | ||
default_output_path = os.path.join(tmpdir, "test_input.tsbrowse") | ||
custom_output_path = os.path.join(tmpdir, "custom_input.tsbrowse") | ||
|
||
ts = test_preprocess.single_tree_example_ts() | ||
tszip.compress(ts, tszip_path) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(main.cli, ["preprocess", tszip_path]) | ||
assert result.exit_code == 0 | ||
assert os.path.exists(default_output_path) | ||
tszip.load(default_output_path).tables.assert_equals(ts.tables) | ||
|
||
result = runner.invoke( | ||
main.cli, ["preprocess", tszip_path, "--output", custom_output_path] | ||
) | ||
assert result.exit_code == 0 | ||
assert os.path.exists(custom_output_path) | ||
tszip.load(custom_output_path).tables.assert_equals(ts.tables) | ||
|
||
|
||
def test_screenshot_cli(tmpdir): | ||
tszip_path = os.path.join(tmpdir, "test_input.tszip") | ||
tsbrowse_path = os.path.join(tmpdir, "test_input.tsbrowse") | ||
ts = test_preprocess.single_tree_example_ts() | ||
tszip.compress(ts, tszip_path) | ||
runner = CliRunner() | ||
result = runner.invoke(main.cli, ["preprocess", tszip_path]) | ||
assert result.exit_code == 0 | ||
|
||
# Test with default output | ||
result = runner.invoke(main.cli, ["screenshot", tsbrowse_path, "overview"]) | ||
assert result.exit_code == 0 | ||
default_output = os.path.join(tmpdir, "test_input_overview.png") | ||
assert os.path.exists(default_output) | ||
with Image.open(default_output) as img: | ||
width, height = img.size | ||
assert width == 1560 | ||
assert height == 296 | ||
|
||
# Test with path | ||
custom_output = os.path.join(tmpdir, "custom_screenshot.png") | ||
result = runner.invoke( | ||
main.cli, | ||
[ | ||
"screenshot", | ||
tsbrowse_path, | ||
"overview", | ||
"--output", | ||
custom_output, | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
assert os.path.exists(custom_output) | ||
|
||
# Test with invalid page | ||
result = runner.invoke(main.cli, ["screenshot", tsbrowse_path, "InvalidPage"]) | ||
assert result.exit_code != 0 | ||
assert "Invalid value" in result.output |
Oops, something went wrong.