Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite releasing scripts for packit compatibility #462

Merged
merged 2 commits into from
Sep 8, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
python3-pygithub
python3-requests
python3-semantic_version
python3-specfile
task: lint
- dependencies: >
black
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
python3-pygithub
python3-requests
python3-semantic_version
python3-specfile
task: lint
- dependencies: >
black
Expand Down
17 changes: 4 additions & 13 deletions mockbuild_test/generate_sourcerpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ if ! groups | grep mock; then
exit 1
fi

DATECODE=$(date +%Y%m%d)
DIST_RELEASE=$1

STRATISD_SPEC_VERSION=$(rpmspec -q --srpm --qf "%{version}\n" stratisd.spec)
Expand Down Expand Up @@ -67,22 +66,14 @@ cd upstream
git clone https://github.com/stratis-storage/stratisd
git clone https://github.com/stratis-storage/stratis-cli
cd stratisd
STRATISD_HEADREV=$(git rev-parse --short HEAD)
STRATISD_SUFFIX="~${DATECODE}git${STRATISD_HEADREV}"
../../../release_management/create_artifacts.py ../../SOURCES/ --pre-release-suffix="${STRATISD_SUFFIX}" stratisd "$STRATISD_SPEC_VERSION"
../../../release_management/create_artifacts.py ../../SOURCES/ --pre-release --specfile-path=../../SPECS/stratisd.spec stratisd "$STRATISD_SPEC_VERSION"
cd ..
cd stratis-cli
STRATISCLI_HEADREV=$(git rev-parse --short HEAD)
STRATISCLI_SUFFIX="~${DATECODE}git${STRATISCLI_HEADREV}"
../../../release_management/create_artifacts.py ../../SOURCES/ --pre-release-suffix="${STRATISCLI_SUFFIX}" stratis-cli "$STRATISCLI_SPEC_VERSION"
../../../release_management/create_artifacts.py ../../SOURCES/ --pre-release --specfile-path=../../SPECS/stratis-cli.spec stratis-cli "$STRATISCLI_SPEC_VERSION"
cd ../..

# Fix the "Requires: stratisd" line in stratis-cli.spec.
sed --in-place -E "s/(^Requires.*stratisd.*)${STRATISD_SPEC_VERSION}/\1${STRATISD_SPEC_VERSION}${STRATISD_SUFFIX}/g" SPECS/stratis-cli.spec

# Before running mock, the spec versions need to be changed.
sed --in-place -E "s/(^Version.*)${STRATISD_SPEC_VERSION}/\1${STRATISD_SPEC_VERSION}${STRATISD_SUFFIX}/g" SPECS/stratisd.spec
sed --in-place -E "s/(^Version.*)${STRATISCLI_SPEC_VERSION}/\1${STRATISCLI_SPEC_VERSION}${STRATISCLI_SUFFIX}/g" SPECS/stratis-cli.spec
# Remove the "Requires: stratisd" line in stratis-cli.spec.
sed -i "/Requires.*stratisd/d" SPECS/stratis-cli.spec

mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratisd.spec --sources SOURCES/ --resultdir=SRPMS/stratisd/
mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratis-cli.spec --sources SOURCES/ --resultdir=SRPMS/stratis-cli/
Expand Down
4 changes: 2 additions & 2 deletions mockbuild_test/mockbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ cd ../..

mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratisd.spec --sources SOURCES/ --resultdir=SRPMS/stratisd/
mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratis-cli.spec --sources SOURCES/ --resultdir=SRPMS/stratis-cli/
mock --rebuild -r $MOCKCONFIG SRPMS/stratisd/stratisd-"$STRATISD_SPEC_VERSION"-77.$DIST.src.rpm --resultdir=RPMS/stratisd/
mock --rebuild -r $MOCKCONFIG SRPMS/stratis-cli/stratis-cli-"$STRATISCLI_SPEC_VERSION"-77.$DIST.src.rpm --resultdir=RPMS/stratis-cli/
mock --rebuild -r $MOCKCONFIG SRPMS/stratisd/stratisd-"$STRATISD_SPEC_VERSION"-D.$DIST.src.rpm --resultdir=RPMS/stratisd/
mock --rebuild -r $MOCKCONFIG SRPMS/stratis-cli/stratis-cli-"$STRATISCLI_SPEC_VERSION"-D.$DIST.src.rpm --resultdir=RPMS/stratis-cli/

for package in stratisd stratis-cli; do
find RPMS -name "$package*.rpm" -exec cp -v -t output/$package {} +
Expand Down
2 changes: 1 addition & 1 deletion mockbuild_test/stratis-cli.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: stratis-cli
Version: 3.6.0
Release: 77%{?dist}
Release: D%{?dist}
Summary: Command-line tool for interacting with the Stratis daemon

License: Apache-2.0
Expand Down
2 changes: 1 addition & 1 deletion mockbuild_test/stratisd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Name: stratisd
Version: 3.6.0
Release: 77%{?dist}
Release: D%{?dist}
Summary: Daemon that manages block devices to create filesystems

License: MPL-2.0
Expand Down
38 changes: 35 additions & 3 deletions release_management/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import os
import subprocess
import tarfile
from datetime import datetime
from getpass import getpass
from urllib.parse import urlparse

# isort: THIRDPARTY
import requests
from github import Github
from specfile import specfile

MANIFEST_PATH = "./Cargo.toml"

Expand All @@ -45,16 +47,16 @@ def __init__(self, base, *, suffix=None):
:type suffix: str or Nonetype
"""
self.base = base
self.suffix = "" if suffix is None else suffix
self.suffix = suffix

def __str__(self):
return self.base + self.suffix
return f"{self.base}{'' if self.suffix is None else '~' + self.suffix}"

def to_crate_str(self):
"""
Return the release version in a crates.io-friendly string.
"""
return (self.base + self.suffix).replace("~", "-")
return f"{self.base}{'' if self.suffix is None else '-' + self.suffix}"

def base_only(self):
"""
Expand All @@ -63,6 +65,36 @@ def base_only(self):
return self.base


def calc_pre_release_suffix():
"""
Return a standard value for the pre-release suffix for the version
:rtype: str
:returns: standard pre-release suffix
"""
command = ["git", "rev-parse", "--short", "HEAD"]
with subprocess.Popen(command, stdout=subprocess.PIPE) as proc:
commit_hash = proc.stdout.readline().strip().decode("utf-8")
return f"{datetime.today():%Y%m%d%H%M}git{commit_hash}"


def edit_specfile(specfile_path, *, release_version=None, sources=None):
"""
Edit the specfile in place
:param specfile_path: abspath of specfile
:type specfile_path: str or NoneType
:param ReleaseVersion release_version: release version to set in spec file
:param sources: local source files
:type sources: list of str or NoneType
"""
if specfile_path is not None:
with specfile.Specfile(specfile_path) as spec:
spec.version = str(release_version)
if sources is not None:
with spec.sources() as entries: # pylint: disable=not-context-manager
for index, value in enumerate(sources):
entries[index].location = value


def get_python_package_info(name):
"""
Get info about the python package.
Expand Down
86 changes: 66 additions & 20 deletions release_management/create_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
# isort: STDLIB
import argparse
import os
import subprocess
import sys

# isort: LOCAL
from _utils import (
MANIFEST_PATH,
ReleaseVersion,
calc_pre_release_suffix,
edit_specfile,
get_package_info,
get_python_package_info,
make_source_tarball,
Expand Down Expand Up @@ -54,9 +55,17 @@ def main():
type=os.path.abspath,
)
parser.add_argument(
"--pre-release-suffix",
"--specfile-path",
action="store",
help="pre-release suffix to add to the version",
default=None,
help="path to specfile to edit",
type=lambda p: p if p is None else os.path.abspath(p),
)
parser.add_argument(
"--pre-release",
action="store_true",
default=False,
help="do automatic actions for a pre-release version",
)

subparsers = parser.add_subparsers(title="subcommands")
Expand Down Expand Up @@ -97,26 +106,45 @@ def _stratisd_artifacts(namespace):
output_path = namespace.output_dir
os.makedirs(output_path, exist_ok=True)

(release_version, _) = get_package_info(manifest_abs_path, "stratisd")
(source_version, _) = get_package_info(manifest_abs_path, "stratisd")

if release_version != namespace.version:
if source_version != namespace.version:
raise RuntimeError("Version mismatch.")

r_v = ReleaseVersion(release_version, suffix=namespace.pre_release_suffix)
pre_release_suffix = calc_pre_release_suffix() if namespace.pre_release else None

specfile_path = namespace.specfile_path
if specfile_path is None and pre_release_suffix is not None:
raise RuntimeError("must specify specfile using --specfile-path option")

release_version = ReleaseVersion(source_version, suffix=pre_release_suffix)

source_tarfile_path = make_source_tarball("stratisd", release_version, output_path)
print(os.path.relpath(source_tarfile_path))

(vendor_tarfile_name, cargo_crate_path) = vendor(
manifest_abs_path,
release_version,
)

crate_path = os.path.join(
output_path, f"stratisd-{release_version.to_crate_str()}.crate"
)

source_tarfile = make_source_tarball("stratisd", r_v, output_path)
(vendor_tarfile_name, crate_path) = vendor(manifest_abs_path, r_v)
os.rename(vendor_tarfile_name, os.path.join(output_path, vendor_tarfile_name))
os.rename(cargo_crate_path, crate_path)

source_vendor_tarfile = os.path.join(output_path, vendor_tarfile_name)
vendor_tarfile_path = os.path.join(output_path, vendor_tarfile_name)

crate_suffix_name = f"stratisd-{r_v.to_crate_str()}.crate"
source_crate = os.path.join(output_path, crate_suffix_name)
os.rename(crate_path, source_crate)
subprocess.run(["sha512sum", source_crate], check=True)
os.rename(vendor_tarfile_name, vendor_tarfile_path)

subprocess.run(["sha512sum", source_tarfile], check=True)
subprocess.run(["sha512sum", source_vendor_tarfile], check=True)
edit_specfile(
specfile_path,
release_version=release_version,
sources=[
os.path.basename(path)
for path in [source_tarfile_path, vendor_tarfile_path, crate_path]
],
)


def _stratis_cli_artifacts(namespace):
Expand All @@ -126,14 +154,32 @@ def _stratis_cli_artifacts(namespace):
output_path = namespace.output_dir
os.makedirs(output_path, exist_ok=True)

(release_version, _) = get_python_package_info("stratis-cli")
(source_version, _) = get_python_package_info("stratis-cli")

if release_version != namespace.version:
if source_version != namespace.version:
raise RuntimeError("Version mismatch.")

r_v = ReleaseVersion(release_version, suffix=namespace.pre_release_suffix)
pre_release_suffix = calc_pre_release_suffix() if namespace.pre_release else None
specfile_path = namespace.specfile_path

if specfile_path is None and pre_release_suffix is not None:
raise RuntimeError("must specify specfile using --specfile-path option")

release_version = ReleaseVersion(source_version, suffix=pre_release_suffix)

source_tarfile = make_source_tarball(
"stratis-cli",
release_version,
output_path,
)

edit_specfile(
specfile_path,
release_version=release_version,
sources=[os.path.basename(source_tarfile)],
)

make_source_tarball("stratis-cli", r_v, output_path)
print(os.path.relpath(source_tarfile))


if __name__ == "__main__":
Expand Down