Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding github action to monitor for dungeon gen changes #637

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test-seed-catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Compare Seed Catalogs"
on:
pull_request:
branches:
- 'release'

jobs:

linux-test:
runs-on: ubuntu-20.04
steps:
- name: "Install dependencies"
run: |
sudo apt update -y
sudo apt install -y libsdl2-dev libsdl2-image-dev

- name: "Checkout sources"
uses: actions/checkout@v3

- name: "Compile"
run: |
make bin/brogue

- name: "Run seed catalog regression tests"
run: |
python3 test/compare_seed_catalog.py test/seed_catalogs/seed_catalog_brogue.txt 40
python3 test/compare_seed_catalog.py --extra_args "--variant rapid_brogue" test/seed_catalogs/seed_catalog_rapid_brogue.txt 10
54 changes: 54 additions & 0 deletions test/compare_seed_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import argparse
import sys
import os

def run_brogue_tests(seed_catalog_file, extra_args, max_level):

output_seed_catalog_file = f'output_seed_catalog_{max_level}.txt'
seed_catalog_cmd_args = f'--print-seed-catalog 1 25 {max_level}'

# Generate the first 25 seeds
if extra_args:
brogue_command = f'./brogue {extra_args} {seed_catalog_cmd_args} > {output_seed_catalog_file}'
else:
brogue_command = f'./brogue {seed_catalog_cmd_args} > {output_seed_catalog_file}'
print(f"Running {brogue_command}...")
brogue_result = subprocess.run(brogue_command, shell=True, capture_output=True, text=True)

# Run diff to compare the seed catalog files
print (f"Comparing {seed_catalog_file} and {output_seed_catalog_file}...")

diff_command = f"bash -c 'diff <(sed \"1,4d\" {seed_catalog_file}) <(sed \"1,4d\" {output_seed_catalog_file})'"
flend marked this conversation as resolved.
Show resolved Hide resolved
diff_result = subprocess.run(diff_command, shell=True, capture_output=True, text=True)

# Delete the output seed catalog file
os.remove(output_seed_catalog_file)

if brogue_result.returncode:
print("Test run failure, seed catalog generation failed. Output:")
print(brogue_result.stdout)
sys.exit(1)

if diff_result.returncode:
print("Test run failure, seed catalog has changed.\nIf this was intentional, update the seed catalogs by running update_seed_catalogs.py.\nOutput:")
print(diff_result.stdout)
sys.exit(1)

print("Seed catalog identical - test run successful")

def main():
# Create the argument parser
parser = argparse.ArgumentParser(description='Brogue Seed Compare Test Runner')
parser.add_argument('seed_catalog', help='Seed catalog file to compare')
parser.add_argument('max_level', help='Maximum level to generate seeds for')
parser.add_argument('--extra_args', help='Extra command-line arguments to be passed to brogue (e.g. to select variant)')

# Parse the command line arguments
args = parser.parse_args()

# Call the function to run the brogue tests
run_brogue_tests(args.seed_catalog, args.extra_args, args.max_level)

if __name__ == '__main__':
main()
Loading