From 7617fa5b106142847f5ff381f0e60daba73b600a Mon Sep 17 00:00:00 2001 From: Alex Elmekeev <55494848+aelmekeev@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:37:03 +0000 Subject: [PATCH] Automatically add all packs to packs workflow (#6) --- .github/workflows/emulations.yaml | 2 +- .github/workflows/packs.yaml | 13 +++++++++++-- .github/workflows/players.yaml | 2 +- .github/workflows/strategies.yaml | 2 +- top_trumps.py | 6 +++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/emulations.yaml b/.github/workflows/emulations.yaml index 46ee03c..d25d626 100644 --- a/.github/workflows/emulations.yaml +++ b/.github/workflows/emulations.yaml @@ -21,4 +21,4 @@ jobs: python-version: '3.11' - name: Run emulations run: | - python top_trumps.py --pack ${{ matrix.pack }} --emulations ${{ matrix.emulations }} + python top_trumps.py --pack ${{ matrix.pack }} --emulations ${{ matrix.emulations }} >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/packs.yaml b/.github/workflows/packs.yaml index 0ed5143..b9b6446 100644 --- a/.github/workflows/packs.yaml +++ b/.github/workflows/packs.yaml @@ -6,11 +6,20 @@ on: - main jobs: + list-packs: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - id: set-matrix + run: echo "matrix=$(ls packs/*.csv | jq -R -s -c 'split("\n")[:-1]')" >> "$GITHUB_OUTPUT" run_emulations: + needs: list-packs runs-on: ubuntu-latest strategy: matrix: - pack: ["packs/cats.csv","packs/elements.csv","packs/famous-art-robberies.csv","packs/harry-potter-and-the-deathly-hallows-part-2.csv","packs/mcdonalds-baby-animals.csv","packs/mcdonalds-minions-rise-of-gru.csv","packs/star-wars-rise-of-the-bounty-hunters.csv","packs/star-wars-starships.csv","packs/the-art-game.csv","packs/the-big-bang-theory.csv"] # ls -1 packs/*.csv | jq -Rsc 'split("\n")[:-1]' + pack: ${{ fromJson(needs.list-packs.outputs.matrix) }} steps: - name: Checkout uses: actions/checkout@v4 @@ -20,4 +29,4 @@ jobs: python-version: '3.11' - name: Run emulations run: | - python top_trumps.py --pack ${{ matrix.pack }} + python top_trumps.py --pack ${{ matrix.pack }} >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/players.yaml b/.github/workflows/players.yaml index d4bd1ba..f590775 100644 --- a/.github/workflows/players.yaml +++ b/.github/workflows/players.yaml @@ -21,4 +21,4 @@ jobs: python-version: '3.11' - name: Run emulations run: | - python top_trumps.py --pack ${{ matrix.pack }} --number_of_players ${{ matrix.players }} + python top_trumps.py --pack ${{ matrix.pack }} --number_of_players ${{ matrix.players }} >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/strategies.yaml b/.github/workflows/strategies.yaml index d5e1c6c..c97c62a 100644 --- a/.github/workflows/strategies.yaml +++ b/.github/workflows/strategies.yaml @@ -21,4 +21,4 @@ jobs: python-version: '3.11' - name: Run emulations run: | - python top_trumps.py --pack ${{ matrix.pack }} --get_stat_index_method ${{ matrix.strategy }} + python top_trumps.py --pack ${{ matrix.pack }} --get_stat_index_method ${{ matrix.strategy }} >> $GITHUB_STEP_SUMMARY diff --git a/top_trumps.py b/top_trumps.py index 2e2fbaa..4f95419 100644 --- a/top_trumps.py +++ b/top_trumps.py @@ -129,9 +129,9 @@ def main(pack, number_of_players, emulations, max_exchanges, get_stat_index_meth endless_games += 1 total_exchanges += exchanges - print(f"Average number of exchanges: {total_exchanges // emulations}") - print(f"Average number of minutes per game: {round(total_exchanges * AVERAGE_NUMBER_OF_SECONDS_PER_EXCHANGE / 60 / emulations)}") - print(f"Number of endless games: {endless_games} ({endless_games * 100 // emulations}%)\n\n") + print(f"* Average number of exchanges: {total_exchanges // emulations}") + print(f"* Average number of minutes per game: {round(total_exchanges * AVERAGE_NUMBER_OF_SECONDS_PER_EXCHANGE / 60 / emulations)}") + print(f"* Number of endless games: {endless_games} ({endless_games * 100 // emulations}%)\n\n") if __name__ == '__main__': # read parameters from the command line