2 Commits

8 changed files with 83 additions and 38 deletions

View File

@@ -1,52 +1,91 @@
name: Botty - CI
on: [pull_request]
on:
pull_request:
push:
branches: [main, mine]
release:
types: [published]
jobs:
tests:
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Miniconda Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.10'
# TODO: The below setp only chaches conda packages, need to cache pip seperatly
- name: Cache conda
uses: actions/cache@v2
env:
# Increase this value to reset cache if environment.yml has not changed
CACHE_NUMBER: 1
with:
path: ~/conda_pkgs_dir
key: conda-${{ env.CACHE_NUMBER }}-${{hashFiles('environment.yml') }}
- name: Cache pip
uses: actions/cache@v2
env:
# Increase this value to reset cache if environment.yml has not changed
CACHE_NUMBER: 1
with:
path: ~/pip
key: pip-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
- name: Install Miniconda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
python-version: '3.10'
activate-environment: botty
channel-priority: strict
environment-file: environment.yml
use-only-tar-bz2: true # Needed for caching
- name: Activate conda
use-only-tar-bz2: true
- name: Download test assets
shell: powershell
run: |
C:\Miniconda\condabin\conda.bat init powershell
set PYTHONPATH=./src
- name: Pytest & Coverage
C:\Miniconda\condabin\conda.bat activate botty
python -c "import utils.download_test_assets"
- name: Pytest
shell: powershell
run: |
C:\Miniconda\condabin\conda.bat activate botty
python -c "import sys; print(sys.version)"
coverage run --source=./src -m pytest -v -s
- name: Coverage Report Generation
python -m pytest test/smoke_test.py test/nip/ test/game_stats_test.py test/closest_non_hud_test.py test/transmute/ -v -s
- name: Coverage
shell: powershell
run: |
C:\Miniconda\condabin\conda.bat activate botty
coverage xml
build:
needs: test
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Miniconda Python 3.10
uses: conda-incubator/setup-miniconda@v3
with:
python-version: '3.10'
activate-environment: botty
channel-priority: strict
environment-file: environment.yml
use-only-tar-bz2: true
- name: Build exe
shell: powershell
env:
BOTTY_NO_RENAME: '1'
run: |
C:\Miniconda\condabin\conda.bat activate botty
python build.py --conda_path C:\Miniconda
- name: Prepare release zip
shell: powershell
run: |
$BOTTY_DIR = Get-ChildItem -Directory -Name | Where-Object { $_ -match '^botty_v' } | Select-Object -First 1
Write-Host "Botty dir: $BOTTY_DIR"
Get-ChildItem -Path $BOTTY_DIR -Recurse | Select-Object -Property FullName, Length
$ZIP = "${BOTTY_DIR}.zip"
Compress-Archive -Path "${BOTTY_DIR}\*" -DestinationPath $ZIP -Force
Write-Host "Release zip: $ZIP"
Get-Item $ZIP | Select-Object -Property FullName, Length
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: botty-build
path: botty_v*/
retention-days: 7
- name: Upload to Release
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
BOTTY_DIR=$(ls -d botty_v* | head -1)
gh release upload "${{ github.event.release.tag_name }}" "${BOTTY_DIR}.zip" --clobber

View File

@@ -97,8 +97,9 @@ if __name__ == "__main__":
new_name = ''.join(random.choices(string.ascii_letters, k=random.randint(6, 14)))
os.rename(f'{botty_dir}/main.exe', f'{botty_dir}/{new_name}.exe')
# Always rename main.exe to avoid Warden flagging the obvious name
if not args.random_name:
# Rename main.exe to avoid Warden flagging the obvious name
# In CI/production builds (env BOTTY_NO_RENAME=1) keep main.exe as-is
if not args.random_name and not os.environ.get("BOTTY_NO_RENAME"):
new_name = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
os.rename(f'{botty_dir}/main.exe', f'{botty_dir}/{new_name}.exe')
print(f"Renamed main.exe -> {new_name}.exe")

View File

@@ -23,7 +23,6 @@ dependencies:
- coverage
- pytest
- pytest-env
- pytest-pythonpath
- pytest-mock
- pyparsing
- graphviz

View File

@@ -30,10 +30,11 @@ dependencies = [
dev = [
"pytest",
"pytest-env",
"pytest-pythonpath",
# pytest-pythonpath is deprecated; use [tool.pytest.ini_options] pythonpath instead
"pytest-mock",
"coverage",
]
[tool.pytest.ini_options]
pythonpath = ["src"]
pythonpath = ["./src"]
testpaths = ["test"]

View File

@@ -2,4 +2,3 @@
env =
PYTHONPATH=./src
RUN_ENV=test
python_paths = ./src

View File

@@ -16,6 +16,9 @@ import utils.download_test_assets # downloads assets if they don't already exist
PATH='test/assets/ground_loot'
screen.set_window_position(0, 0)
if not os.path.isdir(PATH):
pytest.skip("test assets not available", allow_module_level=True)
@cache
def load_ground_loot() -> dict:
test_objs = {}

View File

@@ -17,6 +17,9 @@ import bnip.actions as bnip_actions
PATH='test/assets/hovered_items'
screen.set_window_position(0, 0)
if not os.path.isdir(PATH):
pytest.skip("test assets not available", allow_module_level=True)
@cache
def load_hovered_items() -> dict:
test_objs = {}