diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..41b2833 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# Ignore everything +** + +# Except what we need +!bot +!pyproject.toml +!uv.lock diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb20c94..b0fd663 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,30 +1,18 @@ name: Build and deploy a Docker image on: - workflow_run: - workflows: ["Linting"] - branches: - - master - types: - - completed - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - + workflow_call: + inputs: + sha-tag: + description: "A short-form SHA tag for the commit that triggered this workflow" + required: true + type: string jobs: build: - if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' name: Build & Push to GHCR runs-on: ubuntu-latest steps: - - name: Create a short SHA tag - id: sha_tag - run: | - tag=$(cut -c 1-7 <<< $GITHUB_SHA) - echo "::set-output name=tag::$tag" - - name: Checkout code uses: actions/checkout@v6 @@ -43,11 +31,11 @@ jobs: with: context: . file: Dockerfile - push: true + push: ${{ github.ref == 'refs/heads/master' }} cache-from: type=registry,ref=ghcr.io/fisher60/friendo-bot:latest cache-to: type=inline tags: | ghcr.io/fisher60/friendo-bot:latest - ghcr.io/fisher60/friendo-bot:${{ steps.sha_tag.outputs.tag }} + ghcr.io/fisher60/friendo-bot:${{ inputs.sha-tag }} build-args: | git_sha=${{ github.sha }} diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index af8d089..2b94d4c 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -1,15 +1,7 @@ name: Linting on: - push: - branches: - - master - - develop - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + workflow_call: jobs: lint: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..799897e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + generate-sha-tag: + runs-on: ubuntu-latest + outputs: + sha-tag: ${{ steps.sha-tag.outputs.sha-tag }} + steps: + - name: Create short SHA to be used as a container tag + id: sha-tag + run: | + tag=$(cut -c 1-7 <<< $GITHUB_SHA) + echo "sha-tag=$tag" >> $GITHUB_OUTPUT + + lint: + uses: ./.github/workflows/linting.yml + + build-deploy: + uses: ./.github/workflows/build.yml + needs: + - lint + - generate-sha-tag + with: + sha-tag: ${{ needs.generate-sha-tag.outputs.sha-tag }} + secrets: inherit diff --git a/Dockerfile b/Dockerfile index 62c2b6e..9bc28cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ ENV PATH="/build/.venv/bin:$PATH" # Copy the source code in last to optimize rebuilding the image WORKDIR /app -COPY bot . +COPY . . ENTRYPOINT ["python", "-m"] CMD ["bot"] diff --git a/bot/settings.py b/bot/settings.py index 063f2e5..f773178 100644 --- a/bot/settings.py +++ b/bot/settings.py @@ -1,5 +1,7 @@ import logging +import tomllib from os import environ +from pathlib import Path log = logging.getLogger(__name__) @@ -34,7 +36,10 @@ log.info("Using %s for backend...", FRIENDO_API_URL) -VERSION = "1.2" +with Path("pyproject.toml").open("rb") as f: + pyproject = tomllib.load(f) + +VERSION = pyproject["project"]["version"] GITHUB_REPO = "https://github.com/fisher60/friendo-bot" diff --git a/pyproject.toml b/pyproject.toml index f7524c8..69809f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = [ license = {text = "MIT"} requires-python = "~=3.14.0" name = "friendo-bot" -version = "0.0.1" +version = "1.2" dependencies = [ "aiodns~=4.0.0", "aiofiles~=25.1.0", diff --git a/uv.lock b/uv.lock index 398bde4..60d342a 100644 --- a/uv.lock +++ b/uv.lock @@ -293,7 +293,7 @@ wheels = [ [[package]] name = "friendo-bot" -version = "0.0.1" +version = "1.2" source = { virtual = "." } dependencies = [ { name = "aiodns" },