diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 3007a4b..fa4e9cf 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -9,55 +9,27 @@ on: branches: [main] jobs: - pre-commit: - permissions: - pull-requests: write + build: concurrency: group: "${{ github.workflow }} @ ${{ github.ref }}" cancel-in-progress: true - if: ${{ github.actor != 'dependabot[bot]' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - token: ${{ secrets.PAT }} + - name: Checkout (GitHub) + uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: - python-version: "3.9" - - - name: Install pre-commit - run: pip install pre-commit - - - name: Run pre-commit - id: pre_commit - continue-on-error: true - run: | - if pre-commit run --color always --all-files; then - echo "Pre-commit check passed" - echo "pre_commit_failed=0" >> $GITHUB_OUTPUT - else - echo "Pre-commit check failed" - echo "pre_commit_failed=1" >> $GITHUB_OUTPUT - exit 1 - fi + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - # Have this step before commit in case the PR is from a fork. In this case, we want the - # add-pr-comment to fail, because it makes it means that the contributer is directed here, - # and are given the informative error message, instead of directed to a "could not commit error message". - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pre_commit.outputs.pre_commit_failed == 1 && github.event_name == 'pull_request' }} - id: add_comment + - name: Pre-build dev container image + uses: devcontainers/ci@v0.3 with: - message: | - Looks like some formatting rules failed. You can: - - 🏎️ Fix locally by running `inv pr` - - We also recommend setting up the `ruff` and `black` extensions to auto-format on save in your chosen editor. - - - name: Fail workflow - if: ${{ steps.pre_commit.outputs.pre_commit_failed == 1 && github.event_name == 'pull_request' }} - run: exit 1 + imageName: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + cacheFrom: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + push: never + runCmd: + make lint \ No newline at end of file diff --git a/.github/workflows/static_type_checks.yml b/.github/workflows/static_type_checks.yml index 72ef703..b619acf 100644 --- a/.github/workflows/static_type_checks.yml +++ b/.github/workflows/static_type_checks.yml @@ -3,95 +3,28 @@ # use stubs from imports name: static_type_checks -on: - pull_request: - branches: [main] - push: - branches: [main] - jobs: - static_type_checks: - runs-on: ubuntu-latest - permissions: - pull-requests: write + build: concurrency: group: "${{ github.workflow }} @ ${{ github.ref }}" cancel-in-progress: true - strategy: - matrix: - os: [ubuntu-latest] - python-version: ["3.9"] + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Cache tox - uses: actions/cache@v3.2.6 - id: cache_tox - with: - path: | - .tox - key: ${{ runner.os }}-${{ matrix.python-version }}-static-type-checks - - - name: Set up Python - uses: actions/setup-python@v4 - id: setup_python - with: - python-version: ${{ matrix.python-version}} - - - name: Install dependencies - shell: bash - run: | - pip install invoke tox - - - name: Run static type checker - id: pyright - continue-on-error: true - run: | - if inv static-type-checks; then - echo "pyright check passed" - echo "pyright_failed=0" >> $GITHUB_OUTPUT - else - echo "pyright check failed" - echo "pyright_failed=1" >> $GITHUB_OUTPUT - fi + - name: Checkout (GitHub) + uses: actions/checkout@v3 - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: find_comment - if: ${{github.event_name == 'pull_request'}} - continue-on-error: true + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: ✨ Looks like pyright failed ✨ + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pyright.outputs.pyright_failed == 1 && github.event_name == 'pull_request'}} - id: add_comment + - name: Pre-build dev container image + uses: devcontainers/ci@v0.3 with: - message: | - ✨ Looks like pyright failed ✨ - - If you want to fix this, we recommend doing it locally by either: - - a) Enabling pyright in VSCode and going through the errors in the problems tab - - `VSCode settings > Python > Analysis: Type checking mode > "basic"` - - b) Debugging via the command line - - 1. Installing pyright, which is included in the dev dependencies: `pip install -e ".[dev]"` - 2. Diagnosing the errors by running `pyright .` - - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pyright.outputs.pyright_failed == 0 && steps.find_comment.outputs.comment-id != '' && github.event_name == 'pull_request'}} - with: - message-id: ${{ steps.find_comment.outputs.comment-id }} - message: | - 🌟 pyright succeeds! 🌟 - - - name: Show pyright output - id: fail_run - if: ${{steps.pyright.outputs.pyright_failed == 1}} - run: | - inv static-type-checks # Rerunning pyright isn't optimal computationally, but typically takes no more than a couple of seconds, and this ensures that the errors are in the failing step + imageName: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + cacheFrom: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + push: never + runCmd: + make type-check \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a7b26e0..8317344 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,67 +9,29 @@ on: pull_request: branches: [main] -jobs: - pytest: - runs-on: ${{ matrix.os }} - permissions: - contents: read - issues: read - checks: write - pull-requests: write - strategy: - matrix: - os: [ubuntu-latest] #, macos-latest, windows-latest] - python-version: ["3.9"] # , "3.10"] - # This allows a subsequently queued workflow run to interrupt previous runs +jobs: + build: concurrency: - group: "${{ github.workflow }}-${{ matrix.python-version}}-${{ matrix.os }} @ ${{ github.ref }}" + group: "${{ github.workflow }} @ ${{ github.ref }}" cancel-in-progress: true - + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Cache tox - uses: actions/cache@v3.2.6 - id: cache_tox - with: - path: | - .tox - key: ${{ runner.os }}-${{ matrix.python-version }}-tests - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - shell: bash - run: | - pip install invoke tox - - - name: Run and write pytest - shell: bash - run: | - # Specifying two sets of "--pytest-args" is required for invoke to parse it as a list - inv test --pytest-args="--durations=0" --pytest-args="--junitxml=pytest.xml --cov-report=term-missing --cov=src/" - + - name: Checkout (GitHub) + uses: actions/checkout@v3 - - name: Test report on failures - uses: EnricoMi/publish-unit-test-result-action@v2 - id: test_report_with_annotations - if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (success() || failure()) }} # Do not run for dependabot, run whether tests failed or succeeded + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: - comment_mode: "failures" - files: | - pytest.xml + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Pytest coverage comment - id: coverage-comment - uses: MishaKav/pytest-coverage-comment@main - if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (success() || failure()) }} + - name: Pre-build dev container image + uses: devcontainers/ci@v0.3 with: - create-new-comment: false - report-only-changed-files: false - pytest-coverage-path: pytest-coverage.txt - junitxml-path: ./pytest.xml + imageName: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + cacheFrom: ghcr.io/MartinBernstorff/personal-mnemonic-medium/ + push: never + runCmd: + make test \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev index 226c103..cf2ee13 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,26 +1,20 @@ # Use an official Python runtime as a parent image -FROM python:3.9-bullseye +FROM python:3.11-bullseye # Set the working directory to /app WORKDIR /app # Install deps -COPY pyproject.toml /app/ +COPY pyproject.toml ./ RUN pip install .[dev] RUN pip install .[tests] # Setup dev env -COPY tasks.py pyproject.toml ./ -RUN inv static-type-checks +COPY makefile pyproject.toml ./ +RUN make type-check COPY .pre-commit-config.yaml ./ -RUN git init && pre-commit run - -RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \ - && curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \ - && tar xf lazygit.tar.gz lazygit \ - && install lazygit /usr/local/bin -RUN mkdir -p ~/.config/lazygit/ && touch ~/.config/lazygit/config.yml && echo "disableStartupPopups: true" >> ~/.config/lazygit/config.yml +RUN git init && make lint RUN type -p curl >/dev/null || (apt update && apt install curl -y) && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ diff --git a/makefile b/makefile new file mode 100644 index 0000000..120a080 --- /dev/null +++ b/makefile @@ -0,0 +1,14 @@ +lint: + pre-commit run --all-files + +test: + pytest -n auto -rfE --failed-first --disable-warnings -q + +type-check: + pyright . + +pr: + make lint & make test & make type-check + git push + gh pr create + gh pr merge --auto --merge \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index c4e69ca..3323be3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,9 +13,9 @@ classifiers = [ "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", - "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.11", ] -requires-python = ">=3.8" +requires-python = ">=3.11" dependencies = [ "misaka>=2.1.1", "genanki>=0.13.0", @@ -28,7 +28,7 @@ dependencies = [ [project.optional-dependencies] dev = [ "cruft>=2.0.0", - "pyright==1.1.330.post0", + "pyright==1.1.331", "pyright-polite>=0.0.1", "pre-commit>=2.20.0", "ruff>=0.0.254", @@ -43,21 +43,6 @@ tests = [ "pytest-sugar>=0.9.4", "tox>=4.5.0", ] -docs = [ - "sphinx>=5.3.0,<7.3.0", - "furo>=2022.12.7,<2023.9.11", # theme - "sphinx-copybutton>=0.5.1,<0.5.2", - "sphinxext-opengraph>=0.7.3,<0.8.2", - "sphinx_design>=0.3.0,<0.5.1", - "myst-nb>=0.6.0,<1.17.0", - "sphinx_togglebutton>=0.2.3,<0.4.0", -] -tutorials = [ - "jupyter>=1.0.0,<1.1.0", - "sphinx_togglebutton>=0.2.3,<0.4.0", - "myst-nb>=0.6.0,<1.17.0", # for rendering notebooks - "jupyter>=1.0.0,<1.1.0", # for tutorials -] [project.urls] homepage = "https://github.com/MartinBernstorff/personal-mnemonic-medium"