Skip to content

Commit

Permalink
CI: run tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
brofi committed May 4, 2024
1 parent c73eb47 commit c7fa698
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 29 deletions.
42 changes: 14 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -51,23 +49,21 @@ 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 }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
os: ['ubuntu-latest', 'windows-latest']
python-version: ['3.12']
steps:
- uses: actions/checkout@v4
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <img src="src/coh2_live_stats/res/coh2_live_stats.ico" alt="Icon" width="64" align="center"/> CoH2 Live Stats


![CI branch master](https://github.com/brofi/coh2-live-stats/actions/workflows/ci.yml/badge.svg)

[//]: # (<mark_description>)

Expand Down
16 changes: 16 additions & 0 deletions scripts/github_actions/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

"""Scripts for GitHub Actions."""
34 changes: 34 additions & 0 deletions scripts/github_actions/activate.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

"""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()
37 changes: 37 additions & 0 deletions scripts/github_actions/mock_logfile.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

"""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()

0 comments on commit c7fa698

Please sign in to comment.