From c7fa698fee4402d0b5da15948bab074f8285cdfb Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 4 May 2024 16:01:46 +0200 Subject: [PATCH] CI: run tests on windows --- .github/workflows/ci.yml | 42 +++++++++----------------- README.md | 2 +- scripts/github_actions/__init__.py | 16 ++++++++++ scripts/github_actions/activate.py | 34 +++++++++++++++++++++ scripts/github_actions/mock_logfile.py | 37 +++++++++++++++++++++++ 5 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 scripts/github_actions/__init__.py create mode 100644 scripts/github_actions/activate.py create mode 100644 scripts/github_actions/mock_logfile.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f457bd1..9b82f65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,14 +25,12 @@ jobs: run: | python -m venv --without-pip .venv python -m venv --upgrade-deps --upgrade .venv + - name: activate virtual environment + run: python -c "from scripts.github_actions.activate import run; run()" - name: install dependencies - run: | - . .venv/bin/activate - python -m pip install ruff + run: python -m pip install ruff - name: run lint - run: | - . .venv/bin/activate - python -m ruff check + run: python -m ruff check type-check: name: type-check ${{ matrix.python-version }} @@ -51,15 +49,13 @@ jobs: run: | python -m venv --without-pip .venv python -m venv --upgrade-deps --upgrade .venv + - name: activate virtual environment + run: python -c "from scripts.github_actions.activate import run; run()" - name: install dependencies # See: https://github.com/python/mypy/issues/10600 - run: | - . .venv/bin/activate - python -m pip install .[build] types-colorama types-pyinstaller + run: python -m pip install .[build] types-colorama types-pyinstaller - name: run mypy - run: | - . .venv/bin/activate - python -m mypy src tests scripts tasks.py + run: python -m mypy src tests scripts tasks.py test: name: test ${{ matrix.os }} / ${{ matrix.python-version }} @@ -67,7 +63,7 @@ jobs: strategy: fail-fast: false matrix: - os: ['ubuntu-latest'] + os: ['ubuntu-latest', 'windows-latest'] python-version: ['3.12'] steps: - uses: actions/checkout@v4 @@ -79,21 +75,11 @@ jobs: run: | python -m venv --without-pip .venv python -m venv --upgrade-deps --upgrade .venv + - name: activate virtual environment + run: python -c "from scripts.github_actions.activate import run; run()" - name: install dependencies - run: | - . .venv/bin/activate - python -m pip install .[build] + run: python -m pip install .[build] - name: mock log file - run: > - . .venv/bin/activate && python -c - "import os; from pathlib import Path; - logfile = Path().home(); - logfile = logfile.joinpath('Documents', 'My Games', 'Company of Heroes 2') if os.name == 'nt' - else logfile.joinpath('.local', 'share', 'feral-interactive', 'CompanyOfHeroes2', 'AppData'); - logfile.mkdir(parents=True, exist_ok=True); - logfile /= 'warnings.log'; - logfile.touch()" + run: python -c "from scripts.github_actions.mock_logfile import run; run()" - name: run pytest - run: | - . .venv/bin/activate - python -m pytest --verbose -s + run: python -m pytest --verbose -s diff --git a/README.md b/README.md index 5e4c9a0..f20069c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Icon CoH2 Live Stats - +![CI branch master](https://github.com/brofi/coh2-live-stats/actions/workflows/ci.yml/badge.svg) [//]: # () diff --git a/scripts/github_actions/__init__.py b/scripts/github_actions/__init__.py new file mode 100644 index 0000000..0254bf6 --- /dev/null +++ b/scripts/github_actions/__init__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2024 Andreas Becker. +# +# This file is part of CoH2LiveStats. +# +# CoH2LiveStats is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later version. +# +# CoH2LiveStats is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# CoH2LiveStats. If not, see . + +"""Scripts for GitHub Actions.""" diff --git a/scripts/github_actions/activate.py b/scripts/github_actions/activate.py new file mode 100644 index 0000000..2013173 --- /dev/null +++ b/scripts/github_actions/activate.py @@ -0,0 +1,34 @@ +# Copyright (C) 2024 Andreas Becker. +# +# This file is part of CoH2LiveStats. +# +# CoH2LiveStats is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later version. +# +# CoH2LiveStats is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# CoH2LiveStats. If not, see . + +"""Virtual environment activation used in GitHub Actions.""" + +import os +from pathlib import Path + + +def run() -> None: + """Set up env variables for a python venv in the GitHub environment files.""" + virtual_env = Path('.venv').resolve() + path = virtual_env.joinpath('Scripts' if os.name == 'nt' else 'bin').resolve() + with Path(os.environ['GITHUB_PATH']).open('a+') as f: + f.write(f'\n{path}' if f.read() else str(path)) + with Path(os.environ['GITHUB_ENV']).open('a+') as f: + v = f'VIRTUAL_ENV={virtual_env}' + f.write(f'\n{v}' if f.read() else str(v)) + + +if __name__ == '__main__': + run() diff --git a/scripts/github_actions/mock_logfile.py b/scripts/github_actions/mock_logfile.py new file mode 100644 index 0000000..36b6513 --- /dev/null +++ b/scripts/github_actions/mock_logfile.py @@ -0,0 +1,37 @@ +# Copyright (C) 2024 Andreas Becker. +# +# This file is part of CoH2LiveStats. +# +# CoH2LiveStats is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later version. +# +# CoH2LiveStats is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# CoH2LiveStats. If not, see . + +"""Logfile mocking used in GitHub Actions.""" + +import os +from pathlib import Path + + +def run() -> None: + """Create an empty CoH2 logfile at the correct location depending on OS.""" + logfile = Path().home() + if os.name == 'nt': + logfile = logfile.joinpath('Documents', 'My Games', 'Company of Heroes 2') + else: + logfile = logfile.joinpath( + '.local', 'share', 'feral-interactive', 'CompanyOfHeroes2', 'AppData' + ) + logfile.mkdir(parents=True, exist_ok=True) + logfile /= 'warnings.log' + logfile.touch() + + +if __name__ == '__main__': + run()