Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .flake8

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Build and deploy a Docker image
on:
workflow_run:
workflows: ["Linting"]
push:
branches:
- master
types:
Expand All @@ -27,22 +26,22 @@ jobs:
echo "::set-output name=tag::$tag"

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v6
with:
path: friendo-bot

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to ghcr
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push to ghcr
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
context: friendo-bot/
file: friendo-bot/Dockerfile
Expand Down
63 changes: 16 additions & 47 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,29 @@ jobs:
lint:
name: Linting
runs-on: ubuntu-latest
env:
# Configure pip to cache dependencies and do a user install
PIP_NO_CACHE_DIR: false
PIP_USER: 1

# Hide the graphical elements from pipenv's output
PIPENV_HIDE_EMOJIS: 1
PIPENV_NOSPIN: 1

# Make sure pipenv does not try reuse an environment it's running in
PIPENV_IGNORE_VIRTUALENVS: 1

# Specify explicit paths for python dependencies and the pre-commit
# environment so we know which directories to cache
PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
steps:
- name: Add custom PYTHONUSERBASE to PATH
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: '3.9'
enable-cache: true
resolution-strategy: "lowest"
cache-dependency-glob: "uv.lock"
activate-environment: true

- name: Python Dependency Caching
uses: actions/cache@v2
id: python_cache
- name: "Set up Python"
uses: actions/setup-python@v6
with:
path: ${{ env.PYTHONUSERBASE }}
key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
${{ steps.python.outputs.python-version }}-\
${{ hashFiles('./Pipfile', './Pipfile.lock') }}"
python-version-file: "pyproject.toml"

# Install deps, skipping if we hit a cache
- name: Install dependencies
if: steps.python_cache.outputs.cache-hit != 'true'
run: |
pip install pipenv
pipenv install --dev --deploy --system

- name: Pre-commit Environment Caching
uses: actions/cache@v2
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
${{ steps.python.outputs.python-version }}-\
${{ hashFiles('./.pre-commit-config.yaml') }}"
- name: Install the project
run: uv sync --all-groups

- name: Run pre-commit hooks
run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files
run: SKIP=ruff prek run --all-files

- name: Lint Flake8
run: |
flake8 .
# Run `ruff` using github formatting to enable automatic inline annotations.
- name: Run ruff
run: "ruff check --output-format=github ."
38 changes: 26 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: check-toml
Expand All @@ -9,18 +9,32 @@ repos:
- id: mixed-line-ending
args: [ --fix=lf ]
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.5.1
hooks:
- id: python-check-blanket-noqa
args: [--markdown-linebreak-ext=md]

- repo: local
hooks:
- id: flake8
args:
- bot
name: Flake8
entry: pipenv run flake8
- id: uv-check
name: uv lock check
description: Checks the validity of the uv.lock file.
entry: uv lock --check
language: system
files: pyproject.toml
pass_filenames: false
require_serial: true

- id: ruff-lint
name: ruff linting
description: Run ruff linting
entry: uv run ruff check --force-exclude
language: system
'types_or': [python, pyi]
require_serial: true
args: [--fix, --exit-non-zero-on-fix]

- id: ruff-format
name: ruff formatting
description: Run ruff formatting
entry: uv run ruff format --force-exclude
language: system
types: [ python ]
'types_or': [python, pyi]
require_serial: true
46 changes: 30 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
FROM python:3.9-slim
ARG python_version=3.14-slim

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

WORKDIR /app
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy

# Install project dependencies with build tools available
WORKDIR /build

# Install pipenv
RUN pip install pipenv
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project

# Copy deps and lockfile
COPY Pipfile Pipfile.lock /app/
# -------------------------------------------------------------------------------

# Install project deps
RUN pipenv install --system --deploy
FROM python:$python_version

# Set SHA build argument
# Define Git SHA build argument for sentry
ARG git_sha="development"
ENV GIT_SHA=$git_sha

# Copy in rest of code last, for caching
COPY . /app/
# Define version build argument
ARG version="development"
ENV VERSION=$version

# Install dependencies from build cache
# .venv not put in /app so that it doesn't conflict with the dev
# volume we use to avoid rebuilding image every code change locally
COPY --from=builder /build /build
ENV PATH="/build/.venv/bin:$PATH"

# Copy the source code in last to optimize rebuilding the image
WORKDIR /app
COPY bot .

CMD ["python3", "-m", "bot"]
ENTRYPOINT ["python", "-m"]
CMD ["bot"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: all install just-lock lock outdated lint precommit format

all: install prek

install:
uv sync --frozen --all-groups

just-lock:
uv lock --upgrade

lock: just-lock install

outdated:
uv tree --outdated --all-groups

lint:
uv run prek run --all-files

prek:
uv run prek install

format:
uv run ruff format bot
41 changes: 0 additions & 41 deletions Pipfile

This file was deleted.

Loading