Skip to content

Commit

Permalink
Merge pull request #59 from UniversityRadioYork/dev
Browse files Browse the repository at this point in the history
Merge dev into release
  • Loading branch information
ashhhleyyy authored Apr 4, 2024
2 parents 9e2eefa + 505a632 commit 37b9efc
Show file tree
Hide file tree
Showing 89 changed files with 7,534 additions and 807 deletions.
94 changes: 64 additions & 30 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@ name: Package
on: [push]

jobs:
build-macos:
# build-macos:

runs-on: macos-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python-version: [3.9]
# runs-on: macos-latest
# timeout-minutes: 15
# strategy:
# fail-fast: false
# matrix:
# python-version: ['3.9', '3.11']
# node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Build .app
run: |
npm run presenter-make
build/build-macos.sh
zip -r build/output/BAPSicle.zip build/output/BAPSicle.app
- name: Archive Build
uses: actions/upload-artifact@v2
with:
name: Package - MacOS
path: |
build/output/BAPSicle.zip
# steps:
# - uses: actions/checkout@v2
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# - uses: actions/checkout@v2
# - name: Set up Node ${{ matrix.node-version }}
# uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# - name: Build .app
# run: |
# npm run presenter-make
# build/build-macos.sh
# zip -r build/output/BAPSicle.zip build/output/BAPSicle.app
# - name: Extract branch name
# shell: bash
# run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
# id: extract_branch
# - name: Archive Build
# uses: actions/upload-artifact@v2
# with:
# name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-MacOS
# path: |
# build/output/BAPSicle.zip

build-ubuntu:

Expand All @@ -36,22 +46,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.8','3.9', '3.11']
node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Build executable
run: |
npm run presenter-make
build/build-linux.sh
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract_branch
- name: Archive Build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Package - Ubuntu
name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-Ubuntu-python${{matrix.python-version}}-node${{matrix.node-version}}
path: |
build/output/BAPSicle
Expand All @@ -62,22 +84,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.9', '3.11']
node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Build .exe
run: |
npm run presenter-make
build/build-windows.bat no-venv
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract_branch
- name: Archive Build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Package - Windows
name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-Windows-python${{matrix.python-version}}-node${{matrix.node-version}}
path: |
build/output/BAPSicle.exe
install/
23 changes: 9 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,33 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, 3.11]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r build/requirements.txt
pip install -r build/requirements-macos.txt
- name: Install bapsicle as module
run: |
pip install -e .
run: poetry install --with=dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --ignore=E402,E226,E24,W50,W690 --max-complexity=20 --max-line-length=127 --statistics
poetry run flake8 . --count --ignore=E402,E226,E24,W50,W690 --max-complexity=25 --max-line-length=127 --statistics
- name: Test with unittest
if: ${{ always() }}
timeout-minutes: 10
run: |
python -m sounddevice
python -m unittest
poetry run python -m sounddevice
poetry run python -m unittest
- name: Archive test logs
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Logs - Python ${{ matrix.python-version }}
path: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ music-tmp/


presenter-build

node_modules/
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "presenter"]
path = presenter
url = https://github.com/michael-grace/WebStudio.git
url = https://github.com/UniversityRadioYork/WebStudio.git
branch = master
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Starting and stopping the server, as well as UI links, are available in the Syst

On all platforms:

- Python 3.8 - 3.9 Tested
- Python 3.8 - 3.11 Tested
- Git (Obviously)

On MacOS:
Expand Down
20 changes: 20 additions & 0 deletions alerts/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from helpers.alert_manager import AlertProvider
from package import BETA
from baps_types.alert import WARNING, Alert
# Dummy alert provider for testing basics like UI without needing to actually cause errors.


class DummyAlertProvider(AlertProvider):

def get_alerts(self):
if BETA:
return [Alert(
{
"start_time": -1,
"id": "test",
"title": "BAPSicle is in Debug Mode",
"description": "This is a test alert. It will not appear on production builds.",
"module": "Test",
"severity": WARNING
}
)]
99 changes: 99 additions & 0 deletions alerts/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Any alerts produced by the player.py instances.
import json
from typing import Any, Dict, List, Optional
from datetime import datetime, timedelta
from helpers.os_environment import resolve_external_file_path
from helpers.alert_manager import AlertProvider
from baps_types.alert import CRITICAL, WARNING, Alert
from baps_types.happytime import happytime

MODULE = "Player" # This should match the log file, so the UI will link to the logs page.


class PlayerAlertProvider(AlertProvider):

_server_state: Dict[str, Any]
_states: List[Optional[Dict[str, Any]]] = []
_player_count: int

def __init__(self):
# Player count only changes after server restart, may as well just load this once.
with open(resolve_external_file_path("state/BAPSicleServer.json")) as file:
self._server_state = json.loads(file.read())

self._player_count = int(self._server_state["num_channels"])
self._states = [None] * self._player_count

# To simplify monitoring (and allow detection of things going super
# weird), we are going to read from the state file to work out the alerts.
def get_alerts(self):
for channel in range(self._player_count):
with open(resolve_external_file_path("state/Player{}.json".format(channel))) as file:
self._states[channel] = json.loads(file.read())

funcs = [self._channel_count, self._initialised, self._start_time]

alerts: List[Alert] = []

for func in funcs:
func_alerts = func()
if func_alerts:
alerts.extend(func_alerts)

return alerts

def _channel_count(self):
if self._player_count <= 0:
return [Alert({
"start_time": -1, # Now
"id": "no_channels",
"title": "There are no players configured.",
"description": "The number of channels configured is {}. \
Please set to at least 1 on the 'Server Config' page."
.format(self._player_count),
"module": MODULE+"Handler",
"severity": CRITICAL
})]

def _initialised(self):
alerts: List[Alert] = []
for channel in range(self._player_count):
if self._states[channel] and not self._states[channel]["initialised"]:
alerts.append(Alert({
"start_time": -1, # Now
"id": "player_{}_not_initialised".format(channel),
"title": "Player {} is not initialised.".format(channel),
"description": "This typically means the player channel was not able find the configured sound output \
on the system. Please check the 'Player Config' and Player logs to determine the cause.",
"module": MODULE+str(channel),
"severity": CRITICAL
}))
return alerts

def _start_time(self):
server_start_time = self._server_state["start_time"]
server_start_time = datetime.fromtimestamp(server_start_time)
delta = timedelta(
seconds=30,
)

alerts: List[Alert] = []
for channel in range(self._player_count):
start_time = self._states[channel]["start_time"]
start_time = datetime.fromtimestamp(start_time)
if (start_time > server_start_time + delta):
alerts.append(Alert({
"start_time": -1,
"id": "player_{}_restarted".format(channel),
"title": "Player {} restarted after the server started.".format(channel),
"description":
"""Player {} last restarted at {}, after the server first started at {}, suggesting a failure.
This likely means there was an unhandled exception in the player code, causing the server to restart the player.
Please check player logs to investigate the cause. Please restart the server to clear this warning."""
.format(channel, happytime(start_time), happytime(server_start_time)),
"module": MODULE+str(channel),
"severity": WARNING
}))
return alerts
Loading

0 comments on commit 37b9efc

Please sign in to comment.