Skip to content

Commit f7cfa8a

Browse files
authored
Merge pull request #281 from ChrisLovering/CI-logic
Update CI logic so build happens in CI too
2 parents a66a98c + 75a0c2e commit f7cfa8a

8 files changed

Lines changed: 60 additions & 33 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore everything
2+
**
3+
4+
# Except what we need
5+
!bot
6+
!pyproject.toml
7+
!uv.lock

.github/workflows/build.yml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
11
name: Build and deploy a Docker image
22

33
on:
4-
workflow_run:
5-
workflows: ["Linting"]
6-
branches:
7-
- master
8-
types:
9-
- completed
10-
11-
concurrency:
12-
group: ${{ github.workflow }}-${{ github.ref }}
13-
cancel-in-progress: true
14-
4+
workflow_call:
5+
inputs:
6+
sha-tag:
7+
description: "A short-form SHA tag for the commit that triggered this workflow"
8+
required: true
9+
type: string
1510

1611
jobs:
1712
build:
18-
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
1913
name: Build & Push to GHCR
2014
runs-on: ubuntu-latest
2115
steps:
22-
- name: Create a short SHA tag
23-
id: sha_tag
24-
run: |
25-
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
26-
echo "::set-output name=tag::$tag"
27-
2816
- name: Checkout code
2917
uses: actions/checkout@v6
3018

@@ -43,11 +31,11 @@ jobs:
4331
with:
4432
context: .
4533
file: Dockerfile
46-
push: true
34+
push: ${{ github.ref == 'refs/heads/master' }}
4735
cache-from: type=registry,ref=ghcr.io/fisher60/friendo-bot:latest
4836
cache-to: type=inline
4937
tags: |
5038
ghcr.io/fisher60/friendo-bot:latest
51-
ghcr.io/fisher60/friendo-bot:${{ steps.sha_tag.outputs.tag }}
39+
ghcr.io/fisher60/friendo-bot:${{ inputs.sha-tag }}
5240
build-args: |
5341
git_sha=${{ github.sha }}

.github/workflows/linting.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
name: Linting
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
- develop
8-
pull_request:
9-
10-
concurrency:
11-
group: ${{ github.workflow }}-${{ github.ref }}
12-
cancel-in-progress: true
4+
workflow_call:
135

146
jobs:
157
lint:

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
generate-sha-tag:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
sha-tag: ${{ steps.sha-tag.outputs.sha-tag }}
18+
steps:
19+
- name: Create short SHA to be used as a container tag
20+
id: sha-tag
21+
run: |
22+
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
23+
echo "sha-tag=$tag" >> $GITHUB_OUTPUT
24+
25+
lint:
26+
uses: ./.github/workflows/linting.yml
27+
28+
build-deploy:
29+
uses: ./.github/workflows/build.yml
30+
needs:
31+
- lint
32+
- generate-sha-tag
33+
with:
34+
sha-tag: ${{ needs.generate-sha-tag.outputs.sha-tag }}
35+
secrets: inherit

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ENV PATH="/build/.venv/bin:$PATH"
3333

3434
# Copy the source code in last to optimize rebuilding the image
3535
WORKDIR /app
36-
COPY bot .
36+
COPY . .
3737

3838
ENTRYPOINT ["python", "-m"]
3939
CMD ["bot"]

bot/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
2+
import tomllib
23
from os import environ
4+
from pathlib import Path
35

46
log = logging.getLogger(__name__)
57

@@ -34,7 +36,10 @@
3436

3537
log.info("Using %s for backend...", FRIENDO_API_URL)
3638

37-
VERSION = "1.2"
39+
with Path("pyproject.toml").open("rb") as f:
40+
pyproject = tomllib.load(f)
41+
42+
VERSION = pyproject["project"]["version"]
3843

3944
GITHUB_REPO = "https://github.com/fisher60/friendo-bot"
4045

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [
66
license = {text = "MIT"}
77
requires-python = "~=3.14.0"
88
name = "friendo-bot"
9-
version = "0.0.1"
9+
version = "1.2"
1010
dependencies = [
1111
"aiodns~=4.0.0",
1212
"aiofiles~=25.1.0",

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)