Also patch salt/version.py when making a release.

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-02-16 10:37:29 +00:00 committed by Pedro Algarvio
parent b3f02cc86b
commit 725b4103e0
6 changed files with 63 additions and 33 deletions

View file

@ -16,6 +16,10 @@ inputs:
type: boolean
default: false
description: Validate the passed version.
release:
type: boolean
default: false
description: This is a release of salt.
outputs:
salt-version:
value: ${{ steps.setup-salt-version.outputs.salt-version }}
@ -36,4 +40,4 @@ runs:
if [ "${{ inputs.cwd }}" != "" ]; then
cd "${{ inputs.cwd }}"
fi
tools pkg set-salt-version ${{ inputs.validate-version == 'true' && '--validate-version' || '' }} ${{ inputs.salt-version }}
tools pkg set-salt-version ${{ inputs.validate-version == 'true' && '--validate-version' || '' }} ${{ inputs.release == 'true' && '--release' || '' }} ${{ inputs.salt-version }}

View file

@ -278,6 +278,7 @@ jobs:
uses: ./.github/actions/setup-salt-version
with:
salt-version: "${{ needs.prepare-workflow.outputs.salt-version }}"
release: true
- name: Update Debian changelog
shell: bash

View file

@ -94,6 +94,9 @@ on:
uses: ./.github/actions/setup-salt-version
with:
salt-version: "${{ needs.prepare-workflow.outputs.salt-version }}"
<%- if prepare_actual_release %>
release: true
<%- endif %>
- name: Update Debian changelog
shell: bash

View file

@ -101,6 +101,9 @@ class Recompress:
"validate_version": {
"help": "Validate, and normalize, the passed Salt Version",
},
"release": {
"help": "When true, also update salt/versions.py to set the version as released",
},
},
)
def set_salt_version(
@ -108,6 +111,7 @@ def set_salt_version(
salt_version: str,
overwrite: bool = False,
validate_version: bool = False,
release: bool = False,
):
"""
Write the Salt version to 'salt/_version.txt'
@ -167,6 +171,22 @@ def set_salt_version(
ctx.info(f"Successfuly wrote {salt_version!r} to 'salt/_version.txt'")
if release:
version_instance = tools.utils.Version(salt_version)
with open(tools.utils.REPO_ROOT / "salt" / "version.py", "r+") as rwfh:
contents = rwfh.read()
contents = contents.replace(
f"info=({version_instance.major}, {version_instance.minor}))",
f"info=({version_instance.major}, {version_instance.minor}), released=True)",
)
rwfh.seek(0)
rwfh.write(contents)
rwfh.truncate()
ctx.info(
f"Successfuly marked {salt_version!r} as released in 'salt/version.py'"
)
gh_env_file = os.environ.get("GITHUB_ENV", None)
if gh_env_file is not None:
variable_text = f"SALT_VERSION={salt_version}"

View file

@ -22,6 +22,7 @@ from ptscripts import Context, command_group
import tools.pkg
import tools.utils
from tools.utils import Version
try:
import boto3
@ -1731,35 +1732,3 @@ def _parse_versions(*versions: str) -> list[Version]:
if _versions:
_versions.sort(reverse=True)
return _versions
class Version(packaging.version.Version):
def __lt__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__lt__(other)
def __le__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__le__(other)
def __eq__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__eq__(other)
def __ge__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__ge__(other)
def __gt__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__gt__(other)
def __ne__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__ne__(other)

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import pathlib
import packaging.version
from ptscripts import Context
from rich.progress import (
BarColumn,
@ -81,3 +82,35 @@ def gpg_sign(ctx: Context, key_id: str, path: pathlib.Path):
"--sign",
str(path),
)
class Version(packaging.version.Version):
def __lt__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__lt__(other)
def __le__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__le__(other)
def __eq__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__eq__(other)
def __ge__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__ge__(other)
def __gt__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__gt__(other)
def __ne__(self, other):
if not isinstance(other, self.__class__):
other = self.__class__(other)
return super().__ne__(other)