Version packages from series branches
This commit is contained in:
@@ -14,17 +14,41 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Detect package branch
|
||||
run: |
|
||||
python - <<'PY'
|
||||
import os
|
||||
import re
|
||||
|
||||
branch = (
|
||||
os.environ.get('GITHUB_REF_NAME')
|
||||
or os.environ.get('GITHUB_HEAD_REF')
|
||||
or '')
|
||||
publish = bool(re.fullmatch(r'\d+\.\d+', branch))
|
||||
with open(os.environ['GITHUB_ENV'], 'a') as env:
|
||||
env.write(f'PUBLISH_PACKAGE={"true" if publish else "false"}\n')
|
||||
if publish:
|
||||
env.write(f'PACKAGE_SERIES={branch}\n')
|
||||
if publish:
|
||||
print(f'Publishing package series: {branch}')
|
||||
else:
|
||||
print(f'Skipping package publish for branch: {branch}')
|
||||
PY
|
||||
|
||||
- name: Set up Python
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Install build tools
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install build twine
|
||||
|
||||
- name: Check publishing credentials
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.REGISTRY_USER }}
|
||||
TWINE_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
@@ -33,6 +57,7 @@ jobs:
|
||||
test -n "$TWINE_PASSWORD" || { echo "Missing REGISTRY_PASSWORD secret"; exit 1; }
|
||||
|
||||
- name: Set CI package version
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.REGISTRY_USER }}
|
||||
TWINE_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
@@ -60,12 +85,8 @@ jobs:
|
||||
cfg_match = re.search(r'(?m)^version=(.+)$', cfg_text)
|
||||
if not cfg_match:
|
||||
raise SystemExit('tryton.cfg has no version entry')
|
||||
base_version = cfg_match.group(1).strip()
|
||||
version_match = re.fullmatch(r'(\d+)\.(\d+)\.(\d+)', base_version)
|
||||
if not version_match:
|
||||
raise SystemExit(
|
||||
f'tryton.cfg version must be X.Y.Z, got {base_version!r}')
|
||||
major, minor, patch = map(int, version_match.groups())
|
||||
series = os.environ['PACKAGE_SERIES']
|
||||
major, minor = map(int, series.split('.'))
|
||||
|
||||
pyproject = tomllib.loads(Path('pyproject.toml').read_text())
|
||||
package_name = pyproject['project']['name']
|
||||
@@ -133,13 +154,14 @@ jobs:
|
||||
break
|
||||
|
||||
patch_pattern = re.compile(rf'^{major}\.{minor}\.(\d+)$')
|
||||
patches = [patch]
|
||||
patches = []
|
||||
for version in set(versions):
|
||||
match = patch_pattern.fullmatch(version)
|
||||
if match:
|
||||
patches.append(int(match.group(1)))
|
||||
|
||||
ci_version = f'{major}.{minor}.{max(patches) + 1}'
|
||||
next_patch = max(patches) + 1 if patches else 0
|
||||
ci_version = f'{major}.{minor}.{next_patch}'
|
||||
cfg_text = re.sub(
|
||||
r'(?m)^version=.+$', f'version={ci_version}', cfg_text)
|
||||
cfg_path.write_text(cfg_text)
|
||||
@@ -149,14 +171,17 @@ jobs:
|
||||
PY
|
||||
|
||||
- name: Build package
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
run: |
|
||||
python -m build
|
||||
|
||||
- name: Check package
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
run: |
|
||||
python -m twine check dist/*
|
||||
|
||||
- name: Publish to Gitea PyPI registry
|
||||
if: env.PUBLISH_PACKAGE == 'true'
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.REGISTRY_USER }}
|
||||
TWINE_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
Reference in New Issue
Block a user