commit 77a0575acb125d5c0e8c796d56b53d8275533321 Author: Max P. Date: Fri Sep 12 17:25:32 2025 +0200 chore(ci): add nightly build and cleanup scripts diff --git a/.gitea/scripts/cleanup_versions.sh b/.gitea/scripts/cleanup_versions.sh new file mode 100755 index 0000000..c8c23bc --- /dev/null +++ b/.gitea/scripts/cleanup_versions.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +# cleanup_dev_versions.sh - Delete old PyPI dev versions from Gitea package registry + +# Required environment variables +USERNAME="${TWINE_USERNAME}" +TOKEN="${TWINE_PASSWORD}" +REPO="${GITHUB_REPOSITORY}" # e.g., maxp/repocat +API_BASE="${GITHUB_API_URL%/}" # Strip trailing slash if present + +OWNER="${REPO%%/*}" +PACKAGE_NAME="${REPO##*/}" +API_URL="${API_BASE}/packages/${OWNER}/pypi/${PACKAGE_NAME}" + +# Fetch the list of versions +response=$(curl -s -u "$USERNAME:$TOKEN" "$API_URL") + +# Extract all .dev versions, sort by creation time +mapfile -t versions_to_delete < <(echo "$response" | jq -r ' + map(select(.version | test("\\.dev"))) | + sort_by(.created_at) | + .[0:-1][] | + .version') + +# Determine latest version to keep +latest_version=$(echo "$response" | jq -r ' + map(select(.version | test("\\.dev"))) | + sort_by(.created_at) | + last.version') + +if [[ -z "$latest_version" || ${#versions_to_delete[@]} -eq 0 ]]; then + echo "No old .dev versions to delete." + exit 0 +fi + +echo "Keeping latest .dev version: $latest_version" + +# Delete old .dev versions +for version in "${versions_to_delete[@]}"; do + echo "Deleting old .dev version: $version" + curl -s -X DELETE -u "$USERNAME:$TOKEN" "$API_URL/$version" +done + +echo "Cleanup complete." \ No newline at end of file diff --git a/.gitea/scripts/set_poetry_version.sh b/.gitea/scripts/set_poetry_version.sh new file mode 100755 index 0000000..272e938 --- /dev/null +++ b/.gitea/scripts/set_poetry_version.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +BASE_VERSION=$(cat VERSION) +NIGHTLY_SUFFIX="" + +if [[ "$1" == "nightly" ]]; then + # Beispiel: 20240511.1358 → 11. Mai, 13:58 Uhr + NIGHTLY_SUFFIX=".dev$(date +%Y%m%d%H%M)" +fi + +FULL_VERSION="${BASE_VERSION}${NIGHTLY_SUFFIX}" + +echo "Using version: $FULL_VERSION" +poetry version "$FULL_VERSION" diff --git a/.gitea/workflows/build-and-deploy-nightly.yml b/.gitea/workflows/build-and-deploy-nightly.yml new file mode 100644 index 0000000..ff6cb93 --- /dev/null +++ b/.gitea/workflows/build-and-deploy-nightly.yml @@ -0,0 +1,62 @@ +name: Build and Publish nightly package + +on: + workflow_dispatch: + push: + branches: + - main + paths-ignore: + - "CHANGELOG.md" + +jobs: + build-and-publish: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: 🐍 Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: 🔄 Restore cache + uses: https://git.0xmax42.io/actions/cache@v1 + with: + key: poetry-v1-${{ runner.os }}-${{ hashFiles('poetry.lock') }} + paths: | + ~/.cache/pypoetry + ~/.cache/pip + + - name: Install Poetry + run: | + pip install poetry + + - name: Install Project Dependencies + working-directory: . + run: | + poetry install + + - name: Set version from VERSION file (with nightly suffix) + run: ./.gitea/scripts/set_poetry_version.sh nightly + + - name: Build Package + working-directory: . + run: | + poetry build + + - name: Publish to Gitea Package Registry + working-directory: . + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + run: | + poetry run twine upload --repository-url ${{ secrets.TWINE_URL }} dist/* + + - name: Cleanup old dev versions + run: | + .gitea/scripts/cleanup_versions.sh '\.dev' + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}