From c3443b53857ec63adadeb0d154c584ac85664e77 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 17:49:13 +0200 Subject: [PATCH 1/7] chore(gh-actions): add linting fix: typo style: rename job --- .github/workflows/lint.yml | 25 ++++++++++++++ pyproject.toml | 69 +++++++++++++++++++------------------- requirements_dev.txt | 1 + src/game/screens/tetris.py | 8 ++--- tetris/__main__.py | 8 ++--- 5 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3d5d6d2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint +on: [push, pull_request] +jobs: + lint: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ["3.10", "3.11"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements_dev.txt + - name: Analysing the code with mypy + run: | + mypy $(git ls-files '*.py') + - name: Analysing the code with ruff + run: | + ruff check $(git ls-files '*.py') diff --git a/pyproject.toml b/pyproject.toml index 905b468..f7ae139 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,19 +11,19 @@ readme = "README.md" requires-python = ">=3.11" license = { file = "LICENSE" } dependencies = [ - "attrs==23.1.0", - "loguru==0.7.2", - "numpy==1.26.3", - "pygame-ce==2.4.0", - "toml==0.10.2", + "attrs==23.1.0", + "loguru==0.7.2", + "numpy==1.26.3", + "pygame-ce==2.4.0", + "toml==0.10.2", ] keywords = ["tetris", "game", "pygame"] classifiers = [ - "Development Status :: 3 - Alpha", - "License :: OSI Approved :: GPLv3 License", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: GPLv3 License", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] [project.urls] @@ -45,40 +45,41 @@ warn_unused_configs = true [tool.ruff] extend-select = [ - "B", - "BLE", - "C4", - "ERA", - "I", - "ICN", - "INP", - "ISC", - "N", - "NPY", - "PGH", - "PIE", - # "PTH", - "Q", - "RET", - "RSE", - "RUF", - "S", - "SIM", - "T20", - "TCH", - "TID", - "YTT", + "B", + "BLE", + "C4", + "ERA", + "I", + "ICN", + "INP", + "ISC", + "N", + "NPY", + "PGH", + "PIE", + # "PTH", + "Q", + "RET", + "RSE", + "RUF", + "S", + "SIM", + "T20", + "TCH", + "TID", + "YTT", ] ignore = ["E741"] show-fixes = true line-length = 120 indent-width = 4 -target-version = "py38" +target-version = "py310" [tool.ruff.lint] extend-select = ["I"] preview = true +fixable = ["ALL"] [tool.ruff.format] quote-style = "double" diff --git a/requirements_dev.txt b/requirements_dev.txt index f3bc67b..fa4853f 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,4 @@ mypy==1.8.0 pytest==7.4.3 ruff==0.1.9 +types-toml==0.10.8.7 diff --git a/src/game/screens/tetris.py b/src/game/screens/tetris.py index 40b5d63..5764d21 100644 --- a/src/game/screens/tetris.py +++ b/src/game/screens/tetris.py @@ -355,10 +355,10 @@ class Tetris(BaseScreen): def _initialize_timers(self) -> None: """Initialize game timers.""" self.timers = Timers( - Timer(self.initial_block_speed, True, self.move_down), - Timer(CONFIG.game.movment_delay), - Timer(CONFIG.game.rotation_delay), - Timer(CONFIG.game.drop_delay), + Timer(self.initial_block_speed, True, self.move_down), # type: ignore + Timer(CONFIG.game.movment_delay), # type: ignore + Timer(CONFIG.game.rotation_delay), # type: ignore + Timer(CONFIG.game.drop_delay), # type: ignore ) self.timers.vertical.activate() diff --git a/tetris/__main__.py b/tetris/__main__.py index a47c87b..6152b49 100755 --- a/tetris/__main__.py +++ b/tetris/__main__.py @@ -57,10 +57,10 @@ def run() -> None: game.Main(GameMode.PLAYER).run() -def main(args: argparse.ArgumentParser) -> None: - if args.debug: +def main(args) -> None: + if args.debug: # type: ignore level = "debug" - elif args.verbose: + elif args.verbose: # type: ignore level = "info" else: level = "warning" @@ -72,4 +72,4 @@ def main(args: argparse.ArgumentParser) -> None: if __name__ == "__main__": args = parser.parse_args() - main(args) + main(args) # type: ignore From 24e4421b7e42d5fda6d78ccb946f59f878bc734e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 18:07:00 +0200 Subject: [PATCH 2/7] chore(gh-actions): add tests --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ pyproject.toml | 2 +- tests/test_blank.py | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml create mode 100644 tests/test_blank.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3af19e7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Test +on: [push, pull_request] +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ["3.10", "3.11"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + - name: Test with pytest + run: | + pytest diff --git a/pyproject.toml b/pyproject.toml index f7ae139..6736271 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ version = "0.1.0" description = "Tetris game" authors = [{ name = "Kristofers Solo", email = "dev@kristofers.xyz" }] readme = "README.md" -requires-python = ">=3.11" +requires-python = ">=3.10" license = { file = "LICENSE" } dependencies = [ "attrs==23.1.0", diff --git a/tests/test_blank.py b/tests/test_blank.py new file mode 100644 index 0000000..a59017a --- /dev/null +++ b/tests/test_blank.py @@ -0,0 +1,6 @@ +import unittest + + +class TestBlank(unittest.TestCase): + def test(self) -> None: + pass From 1b3f3500ff024bed13f03b2e250f1c116a947cb1 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 18:19:53 +0200 Subject: [PATCH 3/7] chore(gh-actions): add typst build fix: add on pull_request --- .github/workflows/typst.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/typst.yml diff --git a/.github/workflows/typst.yml b/.github/workflows/typst.yml new file mode 100644 index 0000000..5c4a6b2 --- /dev/null +++ b/.github/workflows/typst.yml @@ -0,0 +1,33 @@ +name: Build Typst document +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] +permissions: + contents: write +jobs: + typst-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Typst + uses: lvignoli/typst-action@main + with: + source_file: | + typst/main.typ + - name: Uplaoding PDF file + uses: actions/upload-artifact@v3 + with: + name: PDF + path: | + typst/main.pdf + - name: Get current date + id: date + run: echo "DATE=$(date +%Y-%m-%d-%H:%M)" >> $GITHUB_ENV + - name: Release + uses: softprops/action-gh-release@v1 + if: github.ref_type == 'tag' + with: + name: "${{ github.ref_name }} — ${{ env.DATE }}" + files: typst/main.pdf From c79bdef3b336d3d3a9d915fff1788c21889cac61 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 19:16:31 +0200 Subject: [PATCH 4/7] refactor(gh-actions): compile and push pdf --- .github/workflows/typst.yml | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/workflows/typst.yml b/.github/workflows/typst.yml index 5c4a6b2..022a611 100644 --- a/.github/workflows/typst.yml +++ b/.github/workflows/typst.yml @@ -1,33 +1,24 @@ name: Build Typst document on: push: - branches: ["main"] + - main pull_request: - branches: ["main"] -permissions: - contents: write + - main jobs: typst-build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Typst + - name: Build Typst uses: lvignoli/typst-action@main with: source_file: | typst/main.typ - - name: Uplaoding PDF file - uses: actions/upload-artifact@v3 + - name: Push changes + uses: stefanzweifel/git-auto-commit-action@v5 with: - name: PDF - path: | - typst/main.pdf - - name: Get current date - id: date - run: echo "DATE=$(date +%Y-%m-%d-%H:%M)" >> $GITHUB_ENV - - name: Release - uses: softprops/action-gh-release@v1 - if: github.ref_type == 'tag' - with: - name: "${{ github.ref_name }} — ${{ env.DATE }}" - files: typst/main.pdf + file_pattern: "typst/*.pdf" + commit_message: "chore(build): auto-build pdf" + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: "github-actions[bot] " From f1e8994eb8ec1373068f2111bd0a0665c985f069 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 19:16:52 +0200 Subject: [PATCH 5/7] chore(gh-actions): add automated release fix: indentations --- .github/workflows/release.yml | 25 +++++++++++++++++++++++++ .github/workflows/typst.yml | 6 ++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..edd4b77 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release +on: + push: + tags: + - "v*.*.*" +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: dist/*.tar.gz diff --git a/.github/workflows/typst.yml b/.github/workflows/typst.yml index 022a611..1827f69 100644 --- a/.github/workflows/typst.yml +++ b/.github/workflows/typst.yml @@ -1,9 +1,7 @@ name: Build Typst document on: - push: - - main - pull_request: - - main + push: main + pull_request: main jobs: typst-build: runs-on: ubuntu-latest From cbe2b7f6deb6fa99aa9123eb41f76946d67859f0 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 19:23:35 +0200 Subject: [PATCH 6/7] fix: indentation --- .github/workflows/typst.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/typst.yml b/.github/workflows/typst.yml index 1827f69..4bb5d3a 100644 --- a/.github/workflows/typst.yml +++ b/.github/workflows/typst.yml @@ -1,10 +1,9 @@ name: Build Typst document -on: - push: main - pull_request: main +on: [push, pull_request] jobs: typst-build: runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/main' }} steps: - uses: actions/checkout@v3 - name: Build Typst From e660844af2e09da3731e3b125b2c1f4ffcd990b2 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 19:27:04 +0200 Subject: [PATCH 7/7] chore: add badges to readme --- .github/workflows/{test.yml => tests.yml} | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename .github/workflows/{test.yml => tests.yml} (98%) diff --git a/.github/workflows/test.yml b/.github/workflows/tests.yml similarity index 98% rename from .github/workflows/test.yml rename to .github/workflows/tests.yml index 3af19e7..cbcdcbd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Test +name: Tests on: [push, pull_request] jobs: test: diff --git a/README.md b/README.md index 6627b36..1902ac2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Tetris +![Tests](https://github.com/kristoferssolo/Tetris/actions/workflows/tests.yml/badge.svg) ![Lint](https://github.com/kristoferssolo/Tetris/actions/workflows/lint.yml/badge.svg)