Refactor CI workflow

This commit is contained in:
2025-04-21 13:49:47 +02:00
parent 41c03e10f6
commit dcb9c512cc
5 changed files with 107 additions and 139 deletions

View File

@ -0,0 +1,103 @@
name: Docker
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
schedule:
- cron: "@daily"
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
TIMEZONE: Europe/Stockholm
LOG_LEVEL: Info
SQLITE_LOCATION: /data/jobs.sqlite
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
steps:
# GitHub Container Registry
- uses: https://github.com/docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: thelovinator1
password: ${{ secrets.PACKAGES_WRITE_GITHUB_TOKEN }}
# Gitea Container Registry
- uses: https://github.com/docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: git.lovinator.space
username: thelovinator
password: ${{ secrets.PACKAGES_WRITE_GITEA_TOKEN }}
# Docker Hub Registry
- uses: https://github.com/docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: docker.io
username: thelovinator
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Download the latest commit from the master branch
- uses: https://github.com/actions/checkout@v4
# Set up QEMU
- id: qemu
uses: https://github.com/docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:master
platforms: linux/amd64,linux/arm64
cache-image: false
# Set up Buildx so we can build multi-arch images
- uses: https://github.com/docker/setup-buildx-action@v3
# Set up uv for Python dependency management
- uses: astral-sh/setup-uv@v5
with:
version: "latest"
# Install dependencies
- run: uv sync --all-extras --all-groups
# Run tests
- run: uv run pytest
# Install the latest version of ruff
- uses: https://github.com/astral-sh/ruff-action@v3
with:
version: "latest"
# Lint the Python code using ruff
- run: ruff check --exit-non-zero-on-fix --verbose
# Check if the Python code needs formatting
- run: ruff format --check --verbose
# Lint Dockerfile
- run: docker build --check .
# Extract metadata (tags, labels) from Git reference and GitHub events for Docker
- id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: |
thelovinator/discord-reminder-bot
ghcr.io/thelovinator1/discord-reminder-bot
tags: |
type=raw,value=latest,enable=${{ gitea.ref == format('refs/heads/{0}', 'master') }}
# Build and push the Docker image
- uses: https://github.com/docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ gitea.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}

View File

@ -1,60 +0,0 @@
name: Docker
on:
# push:
# pull_request:
workflow_dispatch:
# schedule:
# - cron: "0 6 * * *"
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
TIMEZONE: Europe/Stockholm
LOG_LEVEL: Info
SQLITE_LOCATION: /data/jobs.sqlite
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- run: |
if [ -z "${{ env.BOT_TOKEN }}" ]; then
echo "BOT_TOKEN not set"
exit 1
fi
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: 3.13
- run: uv sync --all-extras --dev
- run: uv run pytest
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: thelovinator/discord-reminder-bot:latest
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/thelovinator1/discord-reminder-bot:latest

View File

@ -1,38 +0,0 @@
name: Poetry
on:
# push:
# pull_request:
workflow_dispatch:
# schedule:
# - cron: "0 6 * * *"
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
TIMEZONE: Europe/Stockholm
LOG_LEVEL: Info
SQLITE_LOCATION: /data/jobs.sqlite
jobs:
test-on-poetry:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
poetry-version: ["latest", "main"]
steps:
- run: |
if [ -z "${{ env.BOT_TOKEN }}" ]; then
echo "BOT_TOKEN not set"
exit 1
fi
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}
- run: poetry install
- run: poetry run pytest

View File

@ -1,41 +0,0 @@
name: uv
on:
# push:
# pull_request:
workflow_dispatch:
# schedule:
# - cron: "0 6 * * *"
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
TIMEZONE: Europe/Stockholm
LOG_LEVEL: Info
SQLITE_LOCATION: /data/jobs.sqlite
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
test-on-uv:
name: Install with uv and run tests on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "pypy"]
steps:
- run: |
if [ -z "${{ env.BOT_TOKEN }}" ]; then
echo "BOT_TOKEN not set"
exit 1
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv and set the python version to ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
version: "latest"
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run tests
run: uv run pytest

View File

@ -6,6 +6,7 @@
"asyncio",
"audioop",
"autouse",
"binfmt",
"botuser",
"Buildx",
"cookiejar",
@ -16,6 +17,7 @@
"dotenv",
"filterwarnings",
"freezegun",
"Gitea",
"hikari",
"isort",
"jobstore",
@ -28,11 +30,13 @@
"pydocstyle",
"pyproject",
"pypy",
"pytest",
"PYTHONDONTWRITEBYTECODE",
"PYTHONUNBUFFERED",
"pyupgrade",
"sqlalchemy",
"thelovinator",
"tonistiigi",
"uvloop"
],
"python.analysis.typeCheckingMode": "standard"