Skip to content

Commit dde532e

Browse files
authored
Initial release version?
* Adding new workflows for versioning (#14) * Add dummy test (#17) * Fix PR images cleanup workflow (#18) (#19) * Integrate release drafter (#21)
1 parent 11dac48 commit dde532e

File tree

13 files changed

+994
-23
lines changed

13 files changed

+994
-23
lines changed

.github/release-drafter.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name-template: 'Release {{version}}'
2+
tag-template: '{{version}}'
3+
categories:
4+
- title: "Features"
5+
labels:
6+
- feature
7+
- title: "Bug Fixes"
8+
labels:
9+
- bug
10+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
11+
template: |
12+
# Yet another release!
13+
## Changes
14+
$CHANGES

.github/scripts/bump_patch.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
import subprocess
3+
import re
4+
5+
def get_latest_tag():
6+
try:
7+
output = subprocess.check_output(["git", "tag"], stderr=subprocess.STDOUT)
8+
tags = output.decode().strip().splitlines()
9+
semver_tags = [tag for tag in tags if re.match(r"v\d+\.\d+\.\d+", tag)]
10+
if not semver_tags:
11+
return "v0.0.0"
12+
semver_tags.sort(key=lambda s: list(map(int, s.lstrip("v").split("."))))
13+
return semver_tags[-1]
14+
except subprocess.CalledProcessError:
15+
return "v0.0.0"
16+
17+
def bump_patch(version):
18+
major, minor, patch = map(int, version.lstrip("v").split("."))
19+
patch += 1
20+
return f"v{major}.{minor}.{patch}"
21+
22+
if __name__ == "__main__":
23+
latest = get_latest_tag()
24+
new_version = bump_patch(latest)
25+
print(new_version)

.github/scripts/bump_version.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
import subprocess
3+
import re
4+
5+
def get_latest_tag():
6+
try:
7+
output = subprocess.check_output(["git", "tag"], stderr=subprocess.STDOUT)
8+
tags = output.decode().strip().splitlines()
9+
semver_tags = [tag for tag in tags if re.match(r"v\d+\.\d+\.\d+", tag)]
10+
if not semver_tags:
11+
return "v0.0.0"
12+
semver_tags.sort(key=lambda s: list(map(int, s.lstrip("v").split("."))))
13+
return semver_tags[-1]
14+
except subprocess.CalledProcessError:
15+
return "v0.0.0"
16+
17+
def bump_minor(version):
18+
major, minor, patch = map(int, version.lstrip("v").split("."))
19+
minor += 1
20+
patch = 0
21+
return f"v{major}.{minor}.{patch}"
22+
23+
if __name__ == "__main__":
24+
latest = get_latest_tag()
25+
new_version = bump_minor(latest)
26+
print(new_version)
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
name: Build and Push Docker image
1+
name: Docker Build for DEV
2+
3+
env:
4+
REGISTRY: docker.io
5+
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/python-template
26

37
on:
48
push:
59
branches:
6-
- main
710
- dev
811
pull_request:
912
branches:
10-
- main
1113
- dev
1214

1315
concurrency:
1416
group: ${{ github.workflow }}-${{ github.ref_name }}
15-
cancel-in-progress: ${{ !contains(github.ref, 'main')}}
16-
17-
env:
18-
REGISTRY: docker.io
19-
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/package-name
17+
cancel-in-progress: true
2018

2119
jobs:
22-
build-and-push:
20+
build-dev:
2321
runs-on: ubuntu-latest
2422
steps:
2523
- name: Checkout repository
@@ -33,17 +31,17 @@ jobs:
3331

3432
- name: Log in to Docker Hub
3533
uses: docker/login-action@v3
36-
if: github.event_name == 'push' # Only log in on pushes to main
34+
if: github.event_name == 'push' # Only log in on pushes
3735
with:
3836
username: ${{ secrets.DOCKER_USERNAME }}
3937
password: ${{ secrets.DOCKER_PASSWORD }}
4038

41-
- name: Build and push
39+
- name: Build and push DEV image
4240
uses: docker/build-push-action@v2
4341
with:
4442
context: .
4543
file: ./Dockerfile
46-
push: ${{ github.event_name == 'push' }} # Only push on pushes to main
47-
tags: ${{ env.IMAGE_NAME }}:latest
48-
labels: ${{ env.IMAGE_NAME }}:latest
49-
platforms: linux/amd64,linux/arm64
44+
push: ${{ github.event_name == 'push' }} # Only push on pushes
45+
tags: |
46+
${{ env.IMAGE_NAME }}:latest
47+
platforms: linux/amd64,linux/arm64

.github/workflows/hotfix.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Hotfix Workflow
2+
3+
env:
4+
REGISTRY: docker.io
5+
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/python-template
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
paths-ignore:
11+
- 'dev/**'
12+
13+
jobs:
14+
hotfix:
15+
if: github.ref != 'refs/heads/dev'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.x'
25+
26+
- name: Bump patch version and get new tag
27+
id: bump_patch
28+
run: |
29+
NEW_VERSION=$(python3 .github/scripts/bump_patch.py)
30+
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
31+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
32+
33+
- name: Create Git Tag and push (Hotfix)
34+
run: |
35+
git tag ${{ env.VERSION }}
36+
git push origin ${{ env.VERSION }}
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Log in to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKER_USERNAME }}
48+
password: ${{ secrets.DOCKER_PASSWORD }}
49+
50+
- name: Build and push Hotfix Docker image
51+
uses: docker/build-push-action@v2
52+
with:
53+
context: .
54+
file: ./Dockerfile
55+
push: true
56+
tags: |
57+
${{ env.IMAGE_NAME }}:${{ env.VERSION }}
58+
${{ env.IMAGE_NAME }}:stable
59+
platforms: linux/amd64,linux/arm64
60+
61+
- name: Cherry-pick hotfix into dev branch
62+
run: |
63+
HOTFIX_COMMIT=$(git rev-parse HEAD)
64+
git checkout dev
65+
git cherry-pick $HOTFIX_COMMIT
66+
git push origin dev
67+
68+
- name: Rebuild DEV "latest" Docker image
69+
uses: docker/build-push-action@v2
70+
with:
71+
context: .
72+
file: ./Dockerfile
73+
push: true
74+
tags: |
75+
${{ env.IMAGE_NAME }}:latest
76+
platforms: linux/amd64,linux/arm64
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
name: CI
1+
name: CI
2+
3+
env:
4+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
25

36
on:
47
push:
58
branches:
69
- main
10+
- dev
711
pull_request:
812
branches:
913
- main
14+
- dev
1015

1116
concurrency:
1217
group: ${{ github.workflow }}-${{ github.ref_name }}
@@ -47,5 +52,40 @@ jobs:
4752
- name: Lint source code
4853
run: make lint
4954

55+
Test:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
with:
61+
lfs: 'true'
62+
63+
- name: Set up Python 3.13
64+
uses: actions/setup-python@v5
65+
with:
66+
python-version: "3.13"
67+
68+
- name: Install and configure Poetry
69+
uses: snok/install-poetry@v1
70+
with:
71+
version: 2.0.1
72+
virtualenvs-create: true
73+
virtualenvs-in-project: true
74+
75+
- name: Set up cache
76+
uses: actions/cache@v3
77+
id: cached-poetry-dependencies
78+
with:
79+
path: .venv
80+
key: venv-${{ runner.os }}-python-3.13-${{ hashFiles('**/poetry.lock') }}
81+
82+
- name: Install dependencies
83+
run: poetry install
84+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
85+
5086
- name: Run tests
5187
run: make ci-test
88+
89+
- name: Upload coverage reports to Codecov
90+
uses: codecov/[email protected]
91+

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release Workflow
2+
3+
env:
4+
REGISTRY: docker.io
5+
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/python-template
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Bump minor version and get new tag
24+
id: bump
25+
run: |
26+
NEW_VERSION=$(python3 .github/scripts/bump_version.py)
27+
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
28+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
29+
30+
- name: Create Git Tag and push
31+
run: |
32+
git tag ${{ env.VERSION }}
33+
git push origin ${{ env.VERSION }}
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Log in to Docker Hub
42+
uses: docker/login-action@v3
43+
with:
44+
username: ${{ secrets.DOCKER_USERNAME }}
45+
password: ${{ secrets.DOCKER_PASSWORD }}
46+
47+
- name: Build and push Release image
48+
uses: docker/build-push-action@v2
49+
with:
50+
context: .
51+
file: ./Dockerfile
52+
push: true
53+
tags: |
54+
${{ env.IMAGE_NAME }}:${{ env.VERSION }}
55+
${{ env.IMAGE_NAME }}:stable
56+
${{ env.IMAGE_NAME }}:latest
57+
platforms: linux/amd64,linux/arm64
58+
59+
- name: Publish draft release using GitHub CLI and Release Drafter
60+
run: |
61+
gh release publish "${{ env.VERSION }}"
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# =====================
44

55
FROM python:3.13-slim
6-
WORKDIR /src
6+
WORKDIR /app
77

88
ENV LANG=C.UTF-8
99
ENV LC_ALL=C.UTF-8
@@ -45,10 +45,10 @@ RUN poetry install --no-interaction --no-ansi --no-root
4545
# Runtime
4646
# ----------------------
4747

48-
COPY . /src
48+
COPY . /app
4949

50-
COPY entrypoint.sh /src/entrypoint.sh
51-
RUN chmod +x /src/entrypoint.sh
50+
COPY entrypoint.sh /app/entrypoint.sh
51+
RUN chmod +x /app/entrypoint.sh
5252

5353
# Command to run the application
54-
ENTRYPOINT ["/src/entrypoint.sh"]
54+
ENTRYPOINT ["/app/entrypoint.sh"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DIRS_PYTHON := src
1+
DIRS_PYTHON := src tests
22

33
.PHONY: help
44
help:

0 commit comments

Comments
 (0)