Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-

- name: Get Version for Docker Build
id: get_version
run: |
# Ensure we have tags
git fetch --tags --force

# For tagged builds, use the exact tag without v prefix for PACKAGE_VERSION
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
VERSION="${TAG#v}"
echo "Using tag version: $VERSION"
else
# Use git version without v prefix
VERSION=$(git describe --tags --always 2>/dev/null | sed 's/^v//' || echo "0.1.0")
echo "Using git version: $VERSION"
fi

# Output for GitHub Actions
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Build Docker Image - Python ${{ matrix.python-version }}
uses: docker/build-push-action@v5
with:
Expand All @@ -108,6 +128,7 @@ jobs:
tags: gpt-po-translator:py${{ matrix.python-version }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
VERSION=${{ steps.get_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down Expand Up @@ -164,6 +185,17 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Set Package Version for PyPI
if: matrix.python-version == '3.11'
run: |
# Get tag name without 'refs/tags/' prefix
TAG=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
VERSION="${TAG#v}"
# Set as environment variable
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using version $VERSION for PyPI package"

- name: Install dependencies
if: matrix.python-version == '3.11'
Expand Down Expand Up @@ -227,12 +259,12 @@ jobs:
# For tagged builds, use the exact tag
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
# Keep the v prefix for git tags
VERSION="$TAG"
# Remove v prefix if present for Docker build arg
VERSION="${TAG#v}"
echo "Using tag version: $VERSION"
else
# Use git version with v prefix
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.1.0")
# Use git version without v prefix
VERSION=$(git describe --tags --always 2>/dev/null | sed 's/^v//' || echo "0.1.0")
echo "Using git version: $VERSION"
fi

Expand All @@ -250,4 +282,4 @@ jobs:
PYTHON_VERSION=${{ matrix.python-version }}
VERSION=${{ steps.get_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist/
__pycache__
build/
db.sqlite3
.venv
.venv
python_gpt_po/version.py
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM python:${PYTHON_VERSION}-slim

# Accept version as build arg
ARG VERSION="0.1.0"
# Set as environment variable for setup.py to use
ENV PACKAGE_VERSION=${VERSION}
ENV PYTHONPATH=/app

WORKDIR /app

Expand All @@ -13,11 +16,12 @@ RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code for installation
# Copy source code
COPY . .

# Install the package
RUN pip install --no-cache-dir .
# Create a simple wrapper script
RUN echo '#!/bin/bash\npython -m python_gpt_po.main "$@"' > /usr/local/bin/gpt-po-translator && \
chmod +x /usr/local/bin/gpt-po-translator

# Create a wrapper script to allow more flexibility
COPY docker-entrypoint.sh /usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ git clone https://github.com/pescheckit/python-gpt-po.git
cd python-gpt-po
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements
pip install -r requirements.txt
python -m python_gpt_po.main --folder test --lang nl --bulk --provider="deepseek" --list-models
```

Expand Down
9 changes: 0 additions & 9 deletions build.sh

This file was deleted.

44 changes: 30 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This script is used to install the package, dependencies, and the man page.
"""

import json
import os
import subprocess

from setuptools import find_packages, setup

Expand All @@ -16,17 +16,34 @@


def get_version():
"""
Get version from git or version.json (for Docker builds).

Returns:
dict or bool: Version configuration
"""
if os.path.exists('version.json'):
# In Docker build environment, use the version file
with open('version.json', encoding='utf-8') as version_file:
return json.load(version_file)['version']
return True # Use SCM version
"""Get version from git or environment variable."""
# Check for Docker environment
if 'PACKAGE_VERSION' in os.environ:
return os.environ.get('PACKAGE_VERSION')

# Check for CI/CD environment variable
if 'GITHUB_REF' in os.environ and os.environ['GITHUB_REF'].startswith('refs/tags/'):
# Extract version from tag (strip 'v' prefix if present)
return os.environ['GITHUB_REF'].split('/')[-1].lstrip('v')

# Try getting from git
try:
# Get version from git describe, but normalize it to be PEP 440 compliant
version = subprocess.check_output(['git', 'describe', '--tags', '--always']).decode('utf-8').strip()

# Handle version format from git describe
if '-' in version:
# Format like v0.3.5-5-gd9775d7, convert to 0.3.5.dev5+gd9775d7
tag, commits, commit_hash = version.lstrip('v').split('-')
version = f"{tag}.dev{commits}+{commit_hash}"
elif version.startswith('v'):
# Just a tagged version like v0.3.5
version = version[1:]

return version
except (subprocess.SubprocessError, FileNotFoundError):
# Fallback version
return "0.1.0"


def install_man_pages():
Expand All @@ -44,8 +61,7 @@ def install_man_pages():

setup(
name='gpt-po-translator',
use_scm_version=get_version(),
setup_requires=['setuptools-scm==8.1.0'],
version=get_version(),
author='Bram Mittendorff',
author_email='[email protected]',
description='A CLI tool for translating .po files using GPT models.',
Expand Down
19 changes: 16 additions & 3 deletions version.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/bash
# Get version from git
GIT_VERSION=$(git describe --tags --always 2>/dev/null || echo "0.1.0")
# Strip any leading 'v' if present
VERSION="${GIT_VERSION#v}"
echo $VERSION

# Clean up version for PEP 440 compliance
if [[ "$GIT_VERSION" == *-*-* ]]; then
# Format: v0.3.5-5-gd9775d7 -> 0.3.5.dev5+gd9775d7
VERSION=$(echo "$GIT_VERSION" | sed -E 's/^v?([0-9]+\.[0-9]+\.[0-9]+)-([0-9]+)-g([a-f0-9]+)/\1.dev\2+\3/')
else
# Simple version, just remove v prefix if present
VERSION="${GIT_VERSION#v}"
fi

# If first argument is "docker", return Docker-friendly version (replace + with -)
if [ "$1" = "docker" ]; then
echo "${VERSION//+/-}"
else
echo "$VERSION"
fi