diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 304188d7..ab3d5111 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,9 +15,13 @@ "charliermarsh.ruff", "ms-python.black-formatter", "ms-azuretools.vscode-docker", - "ms-vscode.makefile-tools" + "ms-vscode.makefile-tools", + "github.vscode-github-actions" ] } + }, + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 3007a4b0..00000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,63 +0,0 @@ -# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are. - -name: run-pre-commit - -on: - pull_request: - branches: [main] - push: - branches: [main] - -jobs: - pre-commit: - permissions: - pull-requests: write - 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 }} - - - uses: actions/setup-python@v4 - 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 - - # 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 - 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 diff --git a/.github/workflows/static_type_checks.yml b/.github/workflows/static_type_checks.yml deleted file mode 100644 index 72ef703a..00000000 --- a/.github/workflows/static_type_checks.yml +++ /dev/null @@ -1,97 +0,0 @@ -# We do not include static_type_checks as a pre-commit hook because pre-commit hooks -# are installed in their own virtual environment, so static_type_checks cannot -# 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 - concurrency: - group: "${{ github.workflow }} @ ${{ github.ref }}" - cancel-in-progress: true - strategy: - matrix: - os: [ubuntu-latest] - python-version: ["3.9"] - 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: Find Comment - uses: peter-evans/find-comment@v2 - id: find_comment - if: ${{github.event_name == 'pull_request'}} - continue-on-error: true - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: ✨ Looks like pyright failed ✨ - - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pyright.outputs.pyright_failed == 1 && github.event_name == 'pull_request'}} - id: add_comment - 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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index a7b26e0e..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,75 +0,0 @@ -# This workflow will install Python dependencies, run pytests and run notebooks -# 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: Tests -on: - push: - branches: [main] - 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 - concurrency: - group: "${{ github.workflow }}-${{ matrix.python-version}}-${{ matrix.os }} @ ${{ github.ref }}" - cancel-in-progress: true - - 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: 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 - with: - comment_mode: "failures" - files: | - pytest.xml - - - 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()) }} - with: - create-new-comment: false - report-only-changed-files: false - pytest-coverage-path: pytest-coverage.txt - junitxml-path: ./pytest.xml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 00000000..8064d438 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,35 @@ +# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are. + +name: validate + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + build: + concurrency: + group: "${{ github.workflow }} @ ${{ github.ref }}" + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - name: Checkout (GitHub) + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Pre-build dev container image + uses: devcontainers/ci@v0.3 + with: + imageName: ghcr.io/martinbernstorff/personal-mnemonic-medium + cacheFrom: ghcr.io/martinbernstorff/personal-mnemonic-medium + push: always + runCmd: + make validate \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev index 226c1034..ad5ce49f 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,33 +1,14 @@ # Use an official Python runtime as a parent image -FROM python:3.9-bullseye +FROM python:3.10-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 .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 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 \ - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ - && apt update \ - && apt install gh -y - # Install the entire app COPY . /app RUN pip install -e . diff --git a/makefile b/makefile index 120a0803..8f4fac02 100644 --- a/makefile +++ b/makefile @@ -7,8 +7,11 @@ test: type-check: pyright . -pr: +validate: make lint & make test & make type-check + +pr: + make validate 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 d81b628a..869ebb95 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.10", ] -requires-python = ">=3.8" +requires-python = ">=3.10" dependencies = [ "misaka>=2.1.1", "genanki>=0.13.0", @@ -29,7 +29,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", @@ -44,21 +44,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"