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

Build and publish RPM packages (for EL8/EPEL) #34

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions .github/actions/rpmbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM docker.io/centos:8.3.2011

COPY provision.sh /provision.sh
RUN /provision.sh && rm /provision.sh

VOLUME /artifacts

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
12 changes: 12 additions & 0 deletions .github/actions/rpmbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: "rpmbuild"
description: "Build (S)RPM packages"
inputs:
version:
description: "Version of the package"
required: true
runs:
using: "docker"
image: "Dockerfile"
args:
- "${{ inputs.version }}"
27 changes: 27 additions & 0 deletions .github/actions/rpmbuild/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -xue -o pipefail

install -g build -o build -m 0444 \
$GITHUB_WORKSPACE/python-gptsum.spec \
/home/build/rpmbuild/SPECS/
install -g build -o build -m 0444 \
$GITHUB_WORKSPACE/dist/gptsum-$1.tar.gz \
/home/build/rpmbuild/SOURCES/

su - build -s /bin/bash << EOF
set -xue -o pipefail

cd /home/build/rpmbuild/SPECS
test -f python-gptsum.spec
rpmbuild -ba --define "_version $1" python-gptsum.spec

test -f /home/build/rpmbuild/SRPMS/python-gptsum-$1-1.el8.src.rpm
test -f /home/build/rpmbuild/RPMS/noarch/python3-gptsum-$1-1.el8.noarch.rpm
EOF

mkdir $GITHUB_WORKSPACE/artifacts/
install -m 0444 \
/home/build/rpmbuild/SRPMS/python-gptsum-$1-1.el8.src.rpm \
/home/build/rpmbuild/RPMS/noarch/python3-gptsum-$1-1.el8.noarch.rpm \
$GITHUB_WORKSPACE/artifacts/
31 changes: 31 additions & 0 deletions .github/actions/rpmbuild/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -xue -o pipefail

dnf install --assumeyes epel-release
dnf install --assumeyes --enablerepo="powertools" \
dnf-plugins-core \
epel-rpm-macros \
python3-devel \
python3-setuptools \
"python3dist(dataclasses)" \
"python3dist(importlib-metadata)" \
"python3dist(packaging)" \
"python3dist(py)" \
"python3dist(pytest)" \
"python3dist(pytest-benchmark)" \
"python3dist(pytest-mock)" \
rpm-build \
rpmdevtools
dnf clean all

useradd -m -U build
su - build -s /bin/bash << EOF
set -xue -o pipefail

rpmdev-setuptree

cat > /home/build/.rpmmacros << EOF2
%_topdir %(echo \\\$HOME)/rpmbuild
EOF2
EOF
15 changes: 14 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- { python-version: 3.8, session: "tests" }
- { python-version: 3.7, session: "tests" }
- { python-version: 3.6, session: "tests" }
- { python-version: 3.6, session: "tests_centos8" }
- { python-version: 3.9, session: "typeguard" }
- { python-version: 3.9, session: "xdoctest" }
- { python-version: 3.9, session: "docs" }
Expand Down Expand Up @@ -59,7 +60,7 @@ jobs:
nox --force-color --python="${{ matrix.python-version }}"

- name: Upload coverage data
if: always() && matrix.session == 'tests'
if: always() && (matrix.session == 'tests' || matrix.session == 'tests_centos8')
uses: "actions/[email protected]"
with:
name: coverage-data
Expand Down Expand Up @@ -110,3 +111,15 @@ jobs:
nox --force-color --session=coverage -- xml
- name: Upload coverage report
uses: codecov/[email protected]

rpmbuild:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repository
uses: actions/[email protected]

- name: rpmbuild
uses: ./.github/actions/rpmbuild/
with:
version: "0.0.0"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
Expand Down
62 changes: 61 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import shutil
import sys
import tempfile
from pathlib import Path

from nox_poetry import Session, session
import nox
from nox_poetry import SDIST, Session, session

PACKAGE = "gptsum"

Expand All @@ -27,6 +29,28 @@
"docs/conf.py",
]

# Versions of various packages as found in CentOS 8 + EPEL
# Retrieved by running the Nox session, running `pip freeze` in its virtualenv,
# then looking up package versions using `dnf info ...`.
CENTOS8_CONSTRAINTS = b"""
attrs==17.4.0
coverage==4.5.1
dataclasses==0.8
importlib-metadata==0.23
packaging==16.8
pip==9.0.3
pluggy==0.6.0
py==1.5.3
py-cpuinfo==5.0.0
pytest==3.4.2
pytest-benchmark==3.1.1
pytest-mock==1.10.4
setuptools==39.2.0
six==1.11.0
typing-extensions==3.7.4.2
zipp==0.5.1
"""


@session(python=PYTHON_VERSIONS[-1])
def flake8(session: Session) -> None:
Expand Down Expand Up @@ -66,6 +90,8 @@ def mypy(session: Session) -> None:
session.install(".")
session.install(
"mypy",
"packaging",
"py",
"pytest",
"pytest-benchmark",
"pytest-mock",
Expand All @@ -81,6 +107,8 @@ def tests(session: Session) -> None:
session.install(".")
session.install(
"coverage[toml]",
"packaging",
"py",
"pygments",
"pytest",
"pytest-benchmark",
Expand All @@ -93,6 +121,36 @@ def tests(session: Session) -> None:
session.notify("coverage")


@nox.session(python=["3.6"])
def tests_centos8(session: nox.Session) -> None:
"""Run the tests using (pinned) dependency versions as shipped with CentOS 8."""
with tempfile.NamedTemporaryFile() as fd:
fd.write(CENTOS8_CONSTRAINTS)
fd.flush()

poetry_session = Session(session)
package = poetry_session.poetry.build_package(distribution_format=SDIST)
# Version of 'coverage' must be consistent with other sessions
poetry_session.install(
"coverage[toml]",
)
session.install(f"--constraint={fd.name}", package)
session.install(
f"--constraint={fd.name}",
"packaging",
"py",
"pytest",
"pytest-benchmark",
"pytest-mock",
)

try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
session.notify("coverage")


@session
def coverage(session: Session) -> None:
"""Produce the coverage report."""
Expand All @@ -116,6 +174,8 @@ def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
session.install(".")
session.install(
"packaging",
"py",
"pygments",
"pytest",
"pytest-benchmark",
Expand Down
24 changes: 12 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ gptsum = "gptsum.cli:main"

[tool.poetry.dependencies]
python = "^3.6.1"
importlib-metadata = {version = "^3.7.3", python = "< 3.8"}
importlib-metadata = {version = ">=0.23", python = "< 3.8"}
dataclasses = {version = ">=0.6,<0.9", python = "< 3.7"}

[tool.poetry.dev-dependencies]
Expand Down Expand Up @@ -82,6 +82,8 @@ flake8-return = "^1.1.2"
flake8-expression-complexity = "^0.0.9"
pytest-mock = "^3.5.1"
pytest-benchmark = "^3.2.3"
packaging = "^20.9"
py = "^1.10.0"

[tool.coverage.paths]
source = ["src", "*/site-packages"]
Expand Down
63 changes: 63 additions & 0 deletions python-gptsum.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
%global srcname gptsum

Name: python-%{srcname}
Version: %{_version}
Release: 1%{?dist}
Summary: A tool to make disk images using GPT partitions self-verifiable

License: APL 2.0
URL: https://github.com/NicolasT/gptsum
Source0: %{pypi_source}

BuildArch: noarch

%global _description %{expand:
A tool to make disk images using GPT partitions self-verifiable, like isomd5sum.}

%description %_description

%package -n python%{python3_pkgversion}-%{srcname}
Summary: %{summary}
BuildRequires: python%{python3_pkgversion}-devel
BuildRequires: python%{python3_pkgversion}-setuptools

# Dependencies
%if 0%{python3_version_nodots} < 37
BuildRequires: %{py3_dist dataclasses}
%endif
%if 0%{python3_version_nodots} < 38
BuildRequires: %{py3_dist importlib-metadata}
%endif

# Test dependencies
BuildRequires: util-linux
BuildRequires: %{py3_dist packaging}
BuildRequires: %{py3_dist py}
BuildRequires: %{py3_dist pytest}
BuildRequires: %{py3_dist pytest-benchmark}
BuildRequires: %{py3_dist pytest-mock}

%description -n python%{python3_pkgversion}-%{srcname} %_description

%prep
%autosetup -n %{srcname}-%{version}

%build
%py3_build

%install
%py3_install

%check
%pytest

%files -n python%{python3_pkgversion}-%{srcname}
%license LICENSE
%doc README.rst
%{_bindir}/gptsum
%{python3_sitelib}/%{srcname}/
%{python3_sitelib}/%{srcname}-%{version}-py%{python3_version}.egg-info/

%changelog
* Wed Mar 31 2021 Nicolas Trangez <[email protected]> 0.0.9
- New package.
Loading