Skip to content

Commit

Permalink
ci: Improve workflows
Browse files Browse the repository at this point in the history
* fix: Align priority moves with generalsio

* fix: Make online observations include priority

* ci: Add Code Embedder by @kvankova to keep READMEs up-to-date

* refactor(exceptions): make exceptions extensible

Next step should be to utilize exceptions instead of `assert`. The main
advantage of it is that you can catch specific exception instead of
`AssertionError`.

* ci: fix code-embedder action

The manual setting of referrence breaks the checkout action. I am not
entirely sure why it was needed, or what was the intended behaviour, but
checkout action by default switches to feature branch (branch which is
used as source for PR).

* ci: rework GitHub actions

It is more of an update and simplification of triggeres and update of
some action versions.

* chore: Fix pytests

---------

Co-authored-by: Juraj Paluba <[email protected]>
  • Loading branch information
strakam and revolko committed Oct 30, 2024
1 parent 727e174 commit 2a42de0
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 38 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/code-embedder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Run code embedder
uses: kvankova/code-embedder@v0.3.0
uses: kvankova/code-embedder@v0.4.0
env:
GITHUB_TOKEN: ${{ secrets.CODE_EMBEDDER }}
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/commit-message.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Check commits for Conventional Commits practices

on:
pull_request:
branches: [master]
push:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Check Commit Messages
uses: webiny/[email protected]
with:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ name: CI
on:
workflow_dispatch:
push:
pull_request:
branches: [master]

jobs:
ci:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
5 changes: 5 additions & 0 deletions generals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from gymnasium.envs.registration import register

from generals.agents import AgentFactory
from generals.core.exceptions import GeneralsBotError
from generals.core.grid import Grid, GridFactory
from generals.core.replay import Replay
from generals.envs.pettingzoo_generals import PettingZooGenerals
from generals.remote.exceptions import GeneralsIOClientError, RegisterAgentError

__all__ = [
"AgentFactory",
"GridFactory",
"PettingZooGenerals",
"Grid",
"Replay",
"GeneralsBotError",
"GeneralsIOClientError",
"RegisterAgentError",
]


Expand Down
4 changes: 4 additions & 0 deletions generals/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class GeneralsBotError(Exception):
"""Base generals-bot exception"""

pass
3 changes: 1 addition & 2 deletions generals/remote/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .generalsio_client import GeneralsBotError, GeneralsIOClient, GeneralsIOClientError, autopilot
from .generalsio_client import GeneralsIOClient, GeneralsIOClientError, autopilot

__all__ = [
"autopilot",
"GeneralsBotError",
"GeneralsIOClientError",
"GeneralsIOClient",
]
18 changes: 18 additions & 0 deletions generals/remote/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from generals import GeneralsBotError


class GeneralsIOClientError(GeneralsBotError):
"""Base GeneralsIOClient exception"""

pass


class RegisterAgentError(GeneralsIOClientError):
"""Registering bot error"""

def __init__(self, msg: str) -> None:
super().__init__()
self.msg = msg

def __str__(self) -> str:
return f"Failed to register the agent. Error: {self.msg}"
27 changes: 2 additions & 25 deletions generals/remote/generalsio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from generals.core.observation import Observation
from generals.remote.generalsio_state import GeneralsIOstate

from .exceptions import GeneralsIOClientError, RegisterAgentError

DIRECTIONS = [Direction.UP, Direction.DOWN, Direction.LEFT, Direction.RIGHT]


Expand All @@ -24,31 +26,6 @@ def autopilot(agent_id: str, user_id: str, lobby_id: str) -> None:
client.join_game()


class GeneralsBotError(Exception):
"""Base generals-bot exception
TODO: find a place for exceptions
"""

pass


class GeneralsIOClientError(GeneralsBotError):
"""Base GeneralsIOClient exception"""

pass


class RegisterAgentError(GeneralsIOClientError):
"""Registering bot error"""

def __init__(self, msg: str) -> None:
super().__init__()
self.msg = msg

def __str__(self) -> str:
return f"Failed to register the agent. Error: {self.msg}"


class GeneralsIOClient(SimpleClient):
"""
Wrapper around socket.io client to enable Agent to join
Expand Down

0 comments on commit 2a42de0

Please sign in to comment.