Skip to content

Commit b0e2b5c

Browse files
authored
Merge pull request #277 from ChrisLovering/modernise-friendo
Modernise friendo
2 parents aeb8f6e + aa094ad commit b0e2b5c

53 files changed

Lines changed: 1793 additions & 2199 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Build and deploy a Docker image
33
on:
44
workflow_run:
55
workflows: ["Linting"]
6-
push:
76
branches:
87
- master
98
types:
@@ -27,22 +26,22 @@ jobs:
2726
echo "::set-output name=tag::$tag"
2827
2928
- name: Checkout code
30-
uses: actions/checkout@v2
29+
uses: actions/checkout@v6
3130
with:
3231
path: friendo-bot
3332

3433
- name: Set up Docker Buildx
35-
uses: docker/setup-buildx-action@v1
34+
uses: docker/setup-buildx-action@v3
3635

3736
- name: Login to ghcr
38-
uses: docker/login-action@v1
37+
uses: docker/login-action@v3
3938
with:
4039
registry: ghcr.io
4140
username: ${{ github.repository_owner }}
4241
password: ${{ secrets.GITHUB_TOKEN }}
4342

4443
- name: Build and Push to ghcr
45-
uses: docker/build-push-action@v2
44+
uses: docker/build-push-action@v6
4645
with:
4746
context: friendo-bot/
4847
file: friendo-bot/Dockerfile

.github/workflows/linting.yml

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,29 @@ jobs:
1515
lint:
1616
name: Linting
1717
runs-on: ubuntu-latest
18-
env:
19-
# Configure pip to cache dependencies and do a user install
20-
PIP_NO_CACHE_DIR: false
21-
PIP_USER: 1
22-
23-
# Hide the graphical elements from pipenv's output
24-
PIPENV_HIDE_EMOJIS: 1
25-
PIPENV_NOSPIN: 1
26-
27-
# Make sure pipenv does not try reuse an environment it's running in
28-
PIPENV_IGNORE_VIRTUALENVS: 1
29-
30-
# Specify explicit paths for python dependencies and the pre-commit
31-
# environment so we know which directories to cache
32-
PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
33-
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
3418
steps:
35-
- name: Add custom PYTHONUSERBASE to PATH
36-
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
3719
- name: Checkout repo
38-
uses: actions/checkout@v2
20+
uses: actions/checkout@v6
3921

40-
- name: Set up Python
41-
uses: actions/setup-python@v2
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v7
4224
with:
43-
python-version: '3.9'
25+
enable-cache: true
26+
resolution-strategy: "lowest"
27+
cache-dependency-glob: "uv.lock"
28+
activate-environment: true
4429

45-
- name: Python Dependency Caching
46-
uses: actions/cache@v2
47-
id: python_cache
30+
- name: "Set up Python"
31+
uses: actions/setup-python@v6
4832
with:
49-
path: ${{ env.PYTHONUSERBASE }}
50-
key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
51-
${{ steps.python.outputs.python-version }}-\
52-
${{ hashFiles('./Pipfile', './Pipfile.lock') }}"
33+
python-version-file: "pyproject.toml"
5334

54-
# Install deps, skipping if we hit a cache
55-
- name: Install dependencies
56-
if: steps.python_cache.outputs.cache-hit != 'true'
57-
run: |
58-
pip install pipenv
59-
pipenv install --dev --deploy --system
60-
61-
- name: Pre-commit Environment Caching
62-
uses: actions/cache@v2
63-
with:
64-
path: ${{ env.PRE_COMMIT_HOME }}
65-
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
66-
${{ steps.python.outputs.python-version }}-\
67-
${{ hashFiles('./.pre-commit-config.yaml') }}"
35+
- name: Install the project
36+
run: uv sync --all-groups
6837

6938
- name: Run pre-commit hooks
70-
run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files
39+
run: SKIP=ruff prek run --all-files
7140

72-
- name: Lint Flake8
73-
run: |
74-
flake8 .
41+
# Run `ruff` using github formatting to enable automatic inline annotations.
42+
- name: Run ruff
43+
run: "ruff check --output-format=github ."

.pre-commit-config.yaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.1.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-merge-conflict
66
- id: check-toml
@@ -9,18 +9,32 @@ repos:
99
- id: mixed-line-ending
1010
args: [ --fix=lf ]
1111
- id: trailing-whitespace
12-
13-
- repo: https://github.com/pre-commit/pygrep-hooks
14-
rev: v1.5.1
15-
hooks:
16-
- id: python-check-blanket-noqa
12+
args: [--markdown-linebreak-ext=md]
1713

1814
- repo: local
1915
hooks:
20-
- id: flake8
21-
args:
22-
- bot
23-
name: Flake8
24-
entry: pipenv run flake8
16+
- id: uv-check
17+
name: uv lock check
18+
description: Checks the validity of the uv.lock file.
19+
entry: uv lock --check
20+
language: system
21+
files: pyproject.toml
22+
pass_filenames: false
23+
require_serial: true
24+
25+
- id: ruff-lint
26+
name: ruff linting
27+
description: Run ruff linting
28+
entry: uv run ruff check --force-exclude
29+
language: system
30+
'types_or': [python, pyi]
31+
require_serial: true
32+
args: [--fix, --exit-non-zero-on-fix]
33+
34+
- id: ruff-format
35+
name: ruff formatting
36+
description: Run ruff formatting
37+
entry: uv run ruff format --force-exclude
2538
language: system
26-
types: [ python ]
39+
'types_or': [python, pyi]
40+
require_serial: true

Dockerfile

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
FROM python:3.9-slim
1+
ARG python_version=3.14-slim
22

3-
# Set pip to have cleaner logs and no saved cache
4-
ENV PIP_NO_CACHE_DIR=false \
5-
PIPENV_IGNORE_VIRTUALENVS=1 \
6-
PIPENV_NOSPIN=1
3+
FROM python:$python_version AS builder
4+
COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /bin/
75

8-
WORKDIR /app
6+
ENV UV_COMPILE_BYTECODE=1 \
7+
UV_LINK_MODE=copy
8+
9+
# Install project dependencies with build tools available
10+
WORKDIR /build
911

10-
# Install pipenv
11-
RUN pip install pipenv
12+
RUN --mount=type=cache,target=/root/.cache/uv \
13+
--mount=type=bind,source=uv.lock,target=uv.lock \
14+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15+
uv sync --frozen --no-install-project
1216

13-
# Copy deps and lockfile
14-
COPY Pipfile Pipfile.lock /app/
17+
# -------------------------------------------------------------------------------
1518

16-
# Install project deps
17-
RUN pipenv install --system --deploy
19+
FROM python:$python_version
1820

19-
# Set SHA build argument
2021
ARG git_sha="development"
2122
ENV GIT_SHA=$git_sha
2223

23-
# Copy in rest of code last, for caching
24-
COPY . /app/
24+
# Define version build argument
25+
ARG version="development"
26+
ENV VERSION=$version
27+
28+
# Install dependencies from build cache
29+
# .venv not put in /app so that it doesn't conflict with the dev
30+
# volume we use to avoid rebuilding image every code change locally
31+
COPY --from=builder /build /build
32+
ENV PATH="/build/.venv/bin:$PATH"
33+
34+
# Copy the source code in last to optimize rebuilding the image
35+
WORKDIR /app
36+
COPY bot .
2537

26-
CMD ["python3", "-m", "bot"]
38+
ENTRYPOINT ["python", "-m"]
39+
CMD ["bot"]

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: all install just-lock lock outdated lint precommit format
2+
3+
all: install prek
4+
5+
install:
6+
uv sync --frozen --all-groups
7+
8+
just-lock:
9+
uv lock --upgrade
10+
11+
lock: just-lock install
12+
13+
outdated:
14+
uv tree --outdated --all-groups
15+
16+
lint:
17+
uv run prek run --all-files
18+
19+
prek:
20+
uv run prek install
21+
22+
format:
23+
uv run ruff format bot

Pipfile

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)