Skip to content

Commit a5cd084

Browse files
authored
Merge pull request #17 from sunbeam-labs/16-containerize-and-version
Version and containerize
2 parents 35270d4 + b0c8056 commit a5cd084

File tree

15 files changed

+305
-114
lines changed

15 files changed

+305
-114
lines changed

.github/workflows/linter.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
run-tests:
13+
uses: ./.github/workflows/tests.yml
14+
secrets: inherit
15+

.github/workflows/release.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
run-tests:
11+
uses: ./.github/workflows/tests.yml
12+
secrets: inherit
13+
14+
check-version:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Get sbx version
21+
shell: bash
22+
run: |
23+
SBX_VER=$(cat VERSION)
24+
echo "SBX_VER=$SBX_VER" >> $GITHUB_ENV
25+
26+
- id: get_version
27+
uses: battila7/get-version-action@v2
28+
29+
- name: Check version
30+
shell: bash
31+
run: |
32+
RELEASE_VERSION=${{ steps.get_version.outputs.version-without-v }}
33+
echo "Release version: ${RELEASE_VERSION}"
34+
echo "Sbx version: ${{ env.SBX_VER }}"
35+
36+
if [[ $RELEASE_VERSION == ${{ env.SBX_VER }} ]]; then
37+
echo "Versions match, continuing..."
38+
else
39+
echo "Versions don't match, exiting..."
40+
exit 1
41+
fi
42+
43+
build-and-push-to-dockerhub:
44+
name: Push Docker image to Docker Hub
45+
runs-on: ubuntu-latest
46+
needs:
47+
- run-tests
48+
- check-version
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- name: Log in to Docker Hub
55+
uses: docker/login-action@v3
56+
with:
57+
username: ${{ secrets.DOCKER_USERNAME }}
58+
password: ${{ secrets.DOCKER_PASSWORD }}
59+
60+
- name: Extract metadata (tags, labels) for Docker
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
images: ctbushman/sbx_mapping
65+
66+
- name: Build and push Docker image
67+
uses: docker/build-push-action@v5
68+
with:
69+
context: .
70+
file: envs/sbx_mapping_env.Dockerfile
71+
push: true
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
75+
test-apptainer:
76+
name: Apptainer Test
77+
runs-on: ubuntu-latest
78+
79+
steps:
80+
- name: Checkout Code
81+
uses: actions/checkout@v4
82+
83+
- name: Set test env
84+
run: echo "SUNBEAM_TEST_PROFILE=apptainer" >> $GITHUB_ENV
85+
86+
- uses: eWaterCycle/setup-apptainer@v2
87+
with:
88+
apptainer-version: 1.1.2
89+
90+
- name: Test with Sunbeam
91+
uses: sunbeam-labs/sbx_test_action@v1
92+
with:
93+
test-directory: ".tests/e2e/"
94+
95+
- name: Dump Logs
96+
shell: bash
97+
if: always()
98+
run: tail -n +1 logs/*
99+
100+
- name: Dump Stats
101+
shell: bash
102+
if: always()
103+
run: cat stats/*

.github/workflows/tests.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,61 @@ on:
55
branches: [ master, main ]
66
push:
77
branches: [ master, main ]
8+
workflow_call:
9+
workflow_dispatch:
810
schedule:
911
- cron: "0 13 * * 1"
1012

11-
jobs:
13+
jobs:
14+
lint:
15+
name: Lint Code
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v4
21+
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.12
25+
26+
- name: Install Dependencies
27+
run: pip install black snakefmt
28+
29+
- name: Run Linter
30+
run: |
31+
black --check .
32+
snakefmt --check *.smk
33+
34+
test-unit:
35+
name: Run Extension Unit Tests
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout Code
40+
uses: actions/checkout@v4
41+
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: 3.12
45+
46+
- name: Install Dependencies
47+
run: pip install pytest pysam
48+
49+
- name: Run Unit Tests
50+
run: true #pytest .tests/unit/
51+
# This'll require having a lib within scripts with internal tests
52+
1253
test-e2e:
1354
name: Test Extension with Sunbeam
1455
runs-on: ubuntu-latest
56+
needs:
57+
- test-unit
58+
- lint
1559

1660
steps:
1761
- name: Checkout Code
18-
uses: actions/checkout@v3
62+
uses: actions/checkout@v4
1963

2064
- name: Test with Sunbeam
2165
uses: sunbeam-labs/sbx_test_action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.tests/data/hosts/*.fasta.*
22
.tests/data/ref/*.fasta.*
33
__pycache__
4+
.snakemake/

.tests/__init__.py

Whitespace-only changes.

.tests/conftest.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
import pytest
3+
import shutil
4+
import subprocess as sp
5+
import sys
6+
7+
8+
@pytest.fixture
9+
def setup(tmpdir):
10+
reads_fp = os.path.abspath(".tests/data/reads/")
11+
genomes_fp = os.path.abspath(".tests/data/ref/")
12+
13+
project_dir = os.path.join(tmpdir, "project/")
14+
15+
profile = os.environ.get("TEST_PROFILE", "")
16+
if profile:
17+
profile_list = ["--profile", profile]
18+
else:
19+
profile_list = []
20+
21+
sp.check_output(
22+
["sunbeam", "init", "--data_fp", reads_fp, project_dir] + profile_list
23+
)
24+
25+
config_fp = os.path.join(project_dir, "sunbeam_config.yml")
26+
27+
config_str = f"sbx_mapping: {{genomes_fp: {genomes_fp}}}"
28+
sp.check_output(
29+
[
30+
"sunbeam",
31+
"config",
32+
"modify",
33+
"-i",
34+
"-s",
35+
f"{config_str}",
36+
f"{config_fp}",
37+
]
38+
)
39+
40+
yield tmpdir, project_dir
41+
42+
shutil.rmtree(tmpdir)
43+
44+
45+
@pytest.fixture
46+
def run_sunbeam(setup):
47+
tmpdir, project_dir = setup
48+
49+
output_fp = os.path.join(project_dir, "sunbeam_output")
50+
51+
try:
52+
# Run the test job
53+
sp.check_output(
54+
[
55+
"sunbeam",
56+
"run",
57+
"--conda-frontend",
58+
"conda",
59+
"--profile",
60+
project_dir,
61+
"all_mapping",
62+
"--directory",
63+
tmpdir,
64+
]
65+
)
66+
except sp.CalledProcessError as e:
67+
shutil.copytree(os.path.join(output_fp, "logs/"), "logs/")
68+
shutil.copytree(os.path.join(project_dir, "stats/"), "stats/")
69+
sys.exit(e)
70+
71+
shutil.copytree(os.path.join(output_fp, "logs/"), "logs/")
72+
shutil.copytree(os.path.join(project_dir, "stats/"), "stats/")
73+
74+
bfragilis_sliding_cov_fp = os.path.join(
75+
output_fp, "mapping/filtered/Bfragilis/sliding_coverage.csv"
76+
)
77+
ecoli_sliding_cov_fp = os.path.join(
78+
output_fp, "mapping/filtered/Ecoli/sliding_coverage.csv"
79+
)
80+
bfragilis_filtered_cov_fp = os.path.join(
81+
output_fp, "mapping/filtered/Bfragilis/coverage_filtered.csv"
82+
)
83+
ecoli_filtered_cov_fp = os.path.join(
84+
output_fp, "mapping/filtered/Ecoli/coverage_filtered.csv"
85+
)
86+
bfragilis_num_reads_fp = os.path.join(
87+
output_fp, "mapping/filtered/Bfragilis/numReads.tsv"
88+
)
89+
ecoli_num_reads_fp = os.path.join(output_fp, "mapping/filtered/Ecoli/numReads.tsv")
90+
91+
benchmarks_fp = os.path.join(project_dir, "stats/")
92+
93+
yield bfragilis_sliding_cov_fp, ecoli_sliding_cov_fp, bfragilis_filtered_cov_fp, ecoli_filtered_cov_fp, bfragilis_num_reads_fp, ecoli_num_reads_fp, benchmarks_fp

.tests/e2e/test_full_run.py

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,4 @@
11
import os
2-
import pytest
3-
import shutil
4-
import subprocess as sp
5-
import sys
6-
import tempfile
7-
8-
9-
@pytest.fixture
10-
def setup():
11-
temp_dir = tempfile.mkdtemp()
12-
13-
reads_fp = os.path.abspath(".tests/data/reads/")
14-
genomes_fp = os.path.abspath(".tests/data/ref/")
15-
16-
project_dir = os.path.join(temp_dir, "project/")
17-
18-
sp.check_output(["sunbeam", "init", "--data_fp", reads_fp, project_dir])
19-
20-
config_fp = os.path.join(project_dir, "sunbeam_config.yml")
21-
22-
config_str = f"sbx_mapping: {{genomes_fp: {genomes_fp}}}"
23-
sp.check_output(
24-
["sunbeam", "config", "modify", "-i", "-s", f"{config_str}", f"{config_fp}",]
25-
)
26-
27-
yield temp_dir, project_dir
28-
29-
shutil.rmtree(temp_dir)
30-
31-
32-
@pytest.fixture
33-
def run_sunbeam(setup):
34-
temp_dir, project_dir = setup
35-
36-
output_fp = os.path.join(project_dir, "sunbeam_output")
37-
38-
try:
39-
# Run the test job
40-
sp.check_output(
41-
[
42-
"sunbeam",
43-
"run",
44-
"--conda-frontend",
45-
"conda",
46-
"--profile",
47-
project_dir,
48-
"all_mapping",
49-
"--directory",
50-
temp_dir,
51-
]
52-
)
53-
except sp.CalledProcessError as e:
54-
shutil.copytree(os.path.join(output_fp, "logs/"), "logs/")
55-
shutil.copytree(os.path.join(project_dir, "stats/"), "stats/")
56-
sys.exit(e)
57-
58-
shutil.copytree(os.path.join(output_fp, "logs/"), "logs/")
59-
shutil.copytree(os.path.join(project_dir, "stats/"), "stats/")
60-
61-
bfragilis_sliding_cov_fp = os.path.join(
62-
output_fp, "mapping/filtered/Bfragilis/sliding_coverage.csv"
63-
)
64-
ecoli_sliding_cov_fp = os.path.join(
65-
output_fp, "mapping/filtered/Ecoli/sliding_coverage.csv"
66-
)
67-
bfragilis_filtered_cov_fp = os.path.join(
68-
output_fp, "mapping/filtered/Bfragilis/coverage_filtered.csv"
69-
)
70-
ecoli_filtered_cov_fp = os.path.join(
71-
output_fp, "mapping/filtered/Ecoli/coverage_filtered.csv"
72-
)
73-
bfragilis_num_reads_fp = os.path.join(
74-
output_fp, "mapping/filtered/Bfragilis/numReads.tsv"
75-
)
76-
ecoli_num_reads_fp = os.path.join(output_fp, "mapping/filtered/Ecoli/numReads.tsv")
77-
78-
benchmarks_fp = os.path.join(project_dir, "stats/")
79-
80-
yield bfragilis_sliding_cov_fp, ecoli_sliding_cov_fp, bfragilis_filtered_cov_fp, ecoli_filtered_cov_fp, bfragilis_num_reads_fp, ecoli_num_reads_fp, benchmarks_fp
812

823

834
def test_full_run(run_sunbeam):

0 commit comments

Comments
 (0)