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