Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: extract smoketest command from readme #468

Merged
merged 12 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
// readme at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
"build": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
# then it will in python 3.9 (ubuntu-latest) create a badge with the coverage
# and add it to the PR. This badge will be updated if the PR is updated.

name: docker-smoketest
name: smoketests
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
smoketest:
smoketests:
permissions: write-all
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}}
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}}-${{ matrix.invoke_command }}
cancel-in-progress: true
runs-on: ubuntu-latest
strategy:
matrix:
invoke_command: ["smoketest-docker", "smoketest-cli"]

steps:
- name: Checkout (GitHub)
uses: actions/checkout@v4
Expand All @@ -26,10 +30,19 @@ jobs:
registry: ghcr.io
username: MartinBernstorff
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install invoke
run: |
python -m pip install --upgrade pip
pip install invoke

- name: Run integration test
shell: bash
run: |
TEST_PATH=./docker_smoketest.sh
chmod +x $TEST_PATH
$TEST_PATH
pip install .
inv ${{ matrix.invoke_command }}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
{
"label": "Update from ancestor",
"type": "shell",
"command": "gt restack --upstack",
"command": "gt sync --delete --force",
"presentation": {
"reveal": "always",
"clear": true,
Expand Down
21 changes: 0 additions & 21 deletions docker_smoketest.sh

This file was deleted.

1 change: 0 additions & 1 deletion memium/subtasks/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@inv.task(aliases=("submit",)) # type: ignore
def submit_pr(c: inv.Context):
c.run("gt sync --delete --force --no-restack")
c.run("gt submit -m --no-edit --publish")
c.run("gt log short")

Expand Down
60 changes: 60 additions & 0 deletions memium/subtasks/smoketest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from collections.abc import Sequence
from pathlib import Path

import invoke as inv

from memium.subtasks.graphite import submit_pr # noqa: F401 # type: ignore


def get_code_blocks_from_md(md_path: Path) -> Sequence[str]:
md = md_path.read_text()
code_blocks = md.split("```")[1::2]
return code_blocks


def create_smoketest_dir() -> Path:
print("💨 Running smoketest")
input_dir = Path.home() / "smoketest_dir"
input_dir.mkdir(exist_ok=True)

test_file = input_dir / "test.md"
test_file.write_text("Q. Question here\nA. Answer!")
return input_dir


@inv.task # type: ignore
def smoketest_docker(c: inv.Context):
input_dir = create_smoketest_dir()

code_blocks = get_code_blocks_from_md(Path("readme.md"))
docker_block = next(block for block in code_blocks if "docker run" in block)

# Only keep content after docker line
docker_block = docker_block[docker_block.index("docker run") :]
replaced_input_dir = docker_block.replace("$INPUT_DIR", str(input_dir))

smoketest_docker_command = (
replaced_input_dir + " --dry-run \\\n" + " --skip-sync"
)

print(smoketest_docker_command)

c.run("docker build . -t memium:latest -f Dockerfile")
c.run("docker volume create ankidecks")
c.run(smoketest_docker_command)
print("💨🎉 Smoketest complete")


@inv.task # type: ignore
def smoketest_cli(c: inv.Context):
smoketest_dir = create_smoketest_dir()
code_blocks = get_code_blocks_from_md(Path("readme.md"))
cli_block = next(block for block in code_blocks if "cli-block" in block)
sanitised_cli_block = cli_block.splitlines()[1].replace("> ", "")

cli_smoketest_cmd = sanitised_cli_block.replace(
"[YOUR_INPUT_DIR]", str(smoketest_dir)
)
print(cli_smoketest_cmd)
c.run(cli_smoketest_cmd + " --dry-run \\\n" + " --skip-sync")
print("💨🎉 Smoketest complete")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
file = "LICENSE"

[project.readme]
file = "README.md"
file = "readme.md"
content-type = "text/markdown"

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ If you want to sync markdown notes to Anki, here's how to get started!

3. Import your notes!

```bash
```cli-block
> memium --input-dir [YOUR_INPUT_DIR]
```

Expand Down
4 changes: 4 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
create_branch_from_issue,
submit_pr, # noqa: F401 # type: ignore
)
from memium.subtasks.smoketest import (
smoketest_cli, # noqa: F401 # type: ignore
smoketest_docker, # noqa: F401 # type: ignore
)

PYTEST_CMD = "pytest --durations=5 --cov=memium memium --cov-report xml:.coverage.xml --cov-report lcov:.coverage.lcov"

Expand Down
Loading