Skip to content

Commit 878e6e6

Browse files
committed
Add patch-git support
Follow the instructions in konflux-ci/rpmbuild-pipeline#112
1 parent c102e35 commit 878e6e6

File tree

7 files changed

+114
-2
lines changed

7 files changed

+114
-2
lines changed

.github/workflows/gh-action-testsuite.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515

1616
steps:
1717
- name: Checkout code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v6
1919

2020
- name: install needed RPMs
21-
run: dnf install -y python3-norpm python3-pip python3-specfile koji patch
21+
run: dnf install -y python3-norpm python3-pip python3-specfile koji patch git
2222

2323
- name: patch rpmdiff
2424
run: patch /usr/lib/python3.14/site-packages/koji/rpmdiff.py < rpmdiff.patch

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.coverage
22
__pycache__
33
tests/results.json
4+
test-git-repos/
45
test-source-rpms/
56
trace
67
tests/sbom_merged.json

Containerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ADD python_scripts/select_architectures.py /usr/local/bin/select_architectures.p
3232
# TODO: We need to find a better place for this datafile (and autogenerate it)
3333
ADD arch-specific-macro-overrides.json /etc/arch-specific-macro-overrides.json
3434

35+
ADD patch-git-prepare.sh /usr/bin
36+
3537
# TODO: Find a better way to ensure that we never execute RPMSpecParser in Konflux.
3638
RUN sed -i 's/# Note: These calls will alter the results of any subsequent macro expansion/sys.exit(1)/' \
3739
/usr/lib/python3.*/site-packages/rpmautospec/specparser.py

patch-git-prepare.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/sh -x
2+
3+
# See these discussions:
4+
# https://github.com/konflux-ci/rpmbuild-pipeline/issues/112
5+
# https://github.com/konflux-ci/rpmbuild-pipeline-environment-container/pull/105
6+
7+
set -e
8+
export TZ=UTC LC_ALL=C.utf8
9+
git log --first-parent --no-decorate --no-renames --raw --pretty=fuller --date=default > patch-git-generated-log.txt
10+
git rev-parse HEAD > patch-git-generated-commit.txt
11+
echo v1 >> patch-git-generated-commit.txt

run_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ download_files test-source-rpms \
4040
broken-noarch-subpackage/x86_64/test-noarch-check-1-1.fc42.x86_64.rpm \
4141
broken-noarch-subpackage/x86_64/test-noarch-check-noarch-1-1.fc42.noarch.rpm
4242

43+
download_files test-git-repos git-repos/rpmbuild-pipeline-git.tar.gz
44+
4345
coverage=( --cov-report term-missing --cov python_scripts )
4446
for arg; do
4547
case $arg in

tests/patch-git-example-output.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
commit c8d343a3ff7f6be17ff1d0dd7f89d06845c0a18b
2+
Author: Pavel Raiskup <praiskup@redhat.com>
3+
AuthorDate: Thu Mar 6 18:43:42 2025 +0100
4+
Commit: Pavel Raiskup <praiskup@redhat.com>
5+
CommitDate: Thu Mar 6 19:23:04 2025 +0100
6+
7+
Correct Tekton path
8+
9+
:000000 100644 0000000 2bca131 A .tekton/environment-pull-request.yaml
10+
:000000 100644 0000000 0397e8d A .tekton/environment-push.yaml
11+
:100644 000000 2bca131 0000000 D environment-pull-request.yaml
12+
:100644 000000 0397e8d 0000000 D environment-push.yaml
13+
14+
commit 8c78e9e9c32492c00a75b31a281c57cc69e42f66
15+
Author: Pavel Raiskup <praiskup@redhat.com>
16+
AuthorDate: Thu Mar 6 14:15:36 2025 +0100
17+
Commit: Pavel Raiskup <praiskup@redhat.com>
18+
CommitDate: Thu Mar 6 14:24:17 2025 +0100
19+
20+
Tektonize
21+
22+
:000000 100644 0000000 2bca131 A environment-pull-request.yaml
23+
:000000 100644 0000000 0397e8d A environment-push.yaml
24+
25+
commit e0ea9d05f330a91bb1a5f60005bfae30a4b18df0
26+
Author: Pavel Raiskup <praiskup@redhat.com>
27+
AuthorDate: Tue Mar 4 12:47:00 2025 +0100
28+
Commit: Pavel Raiskup <praiskup@redhat.com>
29+
CommitDate: Tue Mar 4 12:47:00 2025 +0100
30+
31+
Fully-qualified image reference
32+
33+
:100644 100644 e4c5edd dfea447 M Containerfile
34+
35+
commit 1fca25484f458311cb64536cec315e62f275cdc1
36+
Author: Pavel Raiskup <praiskup@redhat.com>
37+
AuthorDate: Tue Mar 4 12:40:07 2025 +0100
38+
Commit: Pavel Raiskup <praiskup@redhat.com>
39+
CommitDate: Tue Mar 4 12:44:25 2025 +0100
40+
41+
Initial commit
42+
43+
:000000 100644 0000000 e4c5edd A Containerfile
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Test patch-git-prepare.sh script
3+
"""
4+
5+
import os
6+
import subprocess
7+
import tempfile
8+
from pathlib import Path
9+
10+
11+
def test_patch_git_prep():
12+
"""
13+
Just run the script against our repo, and compare with the expected output.
14+
"""
15+
16+
root_dir = Path(__file__).parent.parent.absolute()
17+
script_path = root_dir / "patch-git-prepare.sh"
18+
expected_file = root_dir / "tests" / "patch-git-example-output.txt"
19+
repos_dir = root_dir / "test-git-repos" / "git-repos"
20+
repo_tarball = repos_dir / "rpmbuild-pipeline-git.tar.gz"
21+
22+
# Extract the test repository into the temporary directory
23+
with tempfile.TemporaryDirectory() as tmp_dir:
24+
workdir = Path(tmp_dir)
25+
26+
subprocess.run(
27+
["tar", "-xzf", str(repo_tarball), "-C", str(workdir)],
28+
check=True
29+
)
30+
31+
git_dir = workdir / "rpmbuild-pipeline-git"
32+
env = os.environ.copy()
33+
env["GIT_CONFIG_COUNT"] = "1"
34+
env["GIT_CONFIG_KEY_0"] = "safe.directory"
35+
env["GIT_CONFIG_VALUE_0"] = str(git_dir)
36+
37+
r = subprocess.run(
38+
[str(script_path)],
39+
capture_output=True,
40+
text=True,
41+
check=False,
42+
cwd=git_dir,
43+
env=env,
44+
)
45+
46+
if r.returncode:
47+
raise RuntimeError(f"Command errored: {r.stderr}")
48+
49+
generated_file = git_dir / "patch-git-generated-log.txt"
50+
actual_content = generated_file.read_text()
51+
expected_content = expected_file.read_text()
52+
53+
assert actual_content == expected_content

0 commit comments

Comments
 (0)