Skip to content

Commit

Permalink
Merge branch 'main' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
49Indium authored May 22, 2024
2 parents 59fb4f1 + e3cc014 commit 3c35e85
Show file tree
Hide file tree
Showing 62 changed files with 4,448 additions and 2,803 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ SERVER_ID=

# Variables for various command cogs.
AOC_SESSION_ID=
HACKATHON_START_TIME=
HACKATHON_END_TIME=
MC_RCON_ADDRESS=
MC_RCON_PORT=
MC_RCON_PASSWORD=
MC_PUBLIC_IP=
MC_PUBLIC_PORT=
SB_BASE_THRESHOLD=8
SB_BIG_THRESHOLD=24
SB_RATELIMIT=30
6 changes: 3 additions & 3 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:

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

# Login against the Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -32,7 +32,7 @@ jobs:
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/black.yml → .github/workflows/run-black.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
name: Code Style Check

on: [pull_request]
on: [ pull_request ]

jobs:
black:
runs-on: ubuntu-latest

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

- name: Run black
id: runBlack
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./uqcsbot"
version: "23.3.0"
version: "23.12.1"

- name: Convert logs to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always() && (steps.runBlack.outcome == 'failure')
with:
name: "black-logs"
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Static Code Tests

on:
push:
branches: [ main ]
pull_request: []

env:
PYTHON_VERSION: '3.10'
POETRY_VERSION: '1.7.1'

jobs:
tests:
name: Run tests
runs-on: ubuntu-latest

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

# Local action that tries to cache as much of python & poetry as possible
- name: Setup environment
uses: ./.github/workflows/setup-python
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}

- name: Check with pytest
run: poetry run pytest

types:
name: Run typechecking
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

# Local action that tries to cache as much of python & poetry as possible
- name: Setup environment
uses: ./.github/workflows/setup-python
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}

- name: Check with pyright
run: poetry run pyright uqcsbot
69 changes: 69 additions & 0 deletions .github/workflows/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Setup Env
description: Setup python & poetry for running tests & typechecking

inputs:
python-version:
description: Version of python to use
required: true
poetry-version:
description: Version of poetry to use
required: true

runs:
using: "composite"
steps:
# ------
# Get python
# ------
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

# ------
# Get poetry (hopefully from cache)
# ------
- name: Check for cached poetry binary
id: cached-poetry-binary
uses: actions/cache@v4
with:
path: ~/.local
# poetry depends on OS, python version, and poetry version
key: poetry-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.poetry-version }}

- name: Install poetry on cache miss
# we don't need an `if:` here because poetry checks if it's already installed
uses: snok/install-poetry@v1
with:
version: ${{ inputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: '**/.venv'
installer-parallel: true

- name: Ensure poetry is on PATH
run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH
shell: bash

# ------
# Get library dependencies (hopefully from cache)
# ------
- name: Check for cached dependencies
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: '**/.venv'
# poetry dependencies depend on OS, python version, poetry version, and repository lockfile
key: poetry-deps-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.poetry-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies on cache miss
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
shell: bash

# ------
# Finalise install
# ------
- name: Install main project
run: poetry install --no-interaction
shell: bash
37 changes: 0 additions & 37 deletions .github/workflows/tests.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/typecheck.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ dmypy.json
.vim
*.db
**/.DS_STORE
.vscode/*

# (per-user) configs for pyright
pyrightconfig.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_NO_INTERACTION=1 \
POETRY_VERSION=1.4.2 \
POETRY_VERSION=1.7.1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_CACHE_DIR='/var/cache/pypoetry'

Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You'll need to define environment variables to be able to start the bot. The `.e

Once you have a .env file, you can run the following command to start the bot:

```sh
```bash
poetry run botdev
```

Expand Down Expand Up @@ -48,9 +48,28 @@ We use an automated code formatter called [Black](https://black.readthedocs.io/)
poetry run black uqcsbot
```


Individual files can also be styled with:

```bash
poetry run black uqcsbot/file.py
```

## Static Type Checks

We use [Pyright](https://github.com/microsoft/pyright) to perform static type checks; which all commits should pass. The exception list is within `pyproject.toml` is for legacy code only, as we hope that all new cogs can be made to pass. To run Pyright, run from the root of the repo:
We use [Pyright](https://github.com/microsoft/pyright) to perform static type checks; which all commits should pass. The exception list within `pyproject.toml` is only to be used for legacy code or libraries with no available typing stubs. We hope that all new cogs can be made to pass - if you're having trouble, ping us on discord and we'll give you a hand. To run Pyright, run from the root of the repo:

```bash
poetry run pyright uqcsbot
```

Individual files can also be typechecked with:

```bash
poetry run pyright uqcsbot/file.py
```

## Development Resources

```bash
poetry run pyright uqcsbot
Expand Down
Loading

0 comments on commit 3c35e85

Please sign in to comment.