ANewDawn/.github/workflows/ci.yml
Joakim Hellsén 85f3234530
Some checks failed
CI / ci (push) Successful in 8s
CI / build (push) Failing after 38s
Lowercase image name in CI workflow
2026-08-09 03:25:25 +02:00

92 lines
No EOL
2.6 KiB
YAML

name: CI
on:
push:
paths-ignore:
- "*.md"
pull_request:
paths-ignore:
- "*.md"
workflow_dispatch:
jobs:
ci:
runs-on: self-hosted
env:
DISCORD_TOKEN: "0"
OPENAI_TOKEN: "0"
DEEPSEEK_API_KEY: "0"
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
- name: Install dependencies
run: uv sync --all-extras --dev -U
- name: Lint the Python code using ruff
run: ruff check --exit-non-zero-on-fix --verbose
- name: Check formatting
run: ruff format --check --verbose
- name: Run tests
run: uv run pytest
build:
needs: ci
runs-on: self-hosted
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
- id: tags
name: Compute image tags
run: |
IMAGE="git.lovinator.space/thelovinator/anewdawn"
if [ "${FORGEJO_REF}" = "refs/heads/master" ]; then
echo "tags=${IMAGE}:latest,${IMAGE}:master" >> "$FORGEJO_OUTPUT"
else
SHORT_SHA="$(echo "$FORGEJO_SHA" | cut -c1-12)"
echo "tags=${IMAGE}:sha-${SHORT_SHA}" >> "$FORGEJO_OUTPUT"
fi
- name: Login to Forgejo Container Registry
run: echo "${{ github.token }}" | docker login git.lovinator.space -u "${{ github.actor }}" --password-stdin
# Build and (optionally) push the Docker image
- name: Build and push Docker image
env:
TAGS: ${{ steps.tags.outputs.tags }}
run: |
IFS=',' read -r -a tag_array <<< "$TAGS"
tag_args=()
for tag in "${tag_array[@]}"; do
tag_args+=( -t "$tag" )
done
publish=0
if [ "${FORGEJO_REF}" = "refs/heads/master" ]; then
publish=1
fi
# PR tokens are read-only, so PR builds can't write to the Actions layer cache.
cache_to=()
if [ "${publish}" = "1" ] || [ "${FORGEJO_EVENT_NAME}" != "pull_request" ]; then
cache_to=(--cache-to type=gha,mode=max)
fi
mode=(--load)
if [ "${publish}" = "1" ]; then
mode=(--push)
fi
# amd64 is the runner's native platform, so no --platform flag is needed.
docker buildx build \
--cache-from type=gha \
--build-arg "BUILD_SOURCE=https://git.lovinator.space/TheLovinator/ANewDawn" \
--build-arg "BUILD_REVISION=${FORGEJO_SHA}" \
--build-arg "BUILD_CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
"${cache_to[@]}" \
"${mode[@]}" \
"${tag_args[@]}" \
.