diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0d5cc4..eaa0189 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -88,5 +88,7 @@ jobs: arch: 'x86_64' desc: 'test package' post: 'echo post1' + # build_requires: 'perl-Git = 2.43.0' + # requires: 'git-core = 2.43.0' - run: | docker run --rm -v $PWD:/work -t centos:7 bash -c 'rpm -Uvh /work/*.rpm && testbin' diff --git a/action.yml b/action.yml index 3ef7d71..d9904b3 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,14 @@ inputs: post: description: 'Package post.' default: '' + build_requires: + description: 'Package build requires.' + # NOTE: for nim parseops package bugs + default: '-' + requires: + description: 'Package requires.' + # NOTE: for nim parseops package bugs + default: '-' outputs: file_name: description: 'File name of resulting .rpm file. This does not contain a debuginfo file.' @@ -39,7 +47,7 @@ outputs: description: 'File name of resulting .rpm debuginfo file.' runs: using: 'docker' - image: 'docker://jiro4989/build-rpm-action:2.4.0' + image: 'docker://jiro4989/build-rpm-action:2.5.0' # Ref: https://haya14busa.github.io/github-action-brandings/ # TODO: update branding if you want. diff --git a/entrypoint.sh b/entrypoint.sh index bae2c81..ab48e1c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,8 @@ fi /replacetool \ --specfile:/template.spec \ + --build-requires:"$INPUT_BUILD_REQUIRES" \ + --requires:"$INPUT_REQUIRES" \ --summary:"$INPUT_SUMMARY" \ --package-root:"$INPUT_PACKAGE_ROOT" \ --package:"$INPUT_PACKAGE" \ diff --git a/template.spec b/template.spec index ece9e9a..cd06c40 100644 --- a/template.spec +++ b/template.spec @@ -10,6 +10,8 @@ Vendor: {{VENDOR}} Source: tmp.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildArch: {{ARCH}} +{{BUILD_REQUIRES}} +{{REQUIRES}} %description {{DESC}} diff --git a/tools/src/replacetool.nim b/tools/src/replacetool.nim index 6dee392..2d914c1 100644 --- a/tools/src/replacetool.nim +++ b/tools/src/replacetool.nim @@ -3,7 +3,7 @@ import os, strutils, parseopt type Options = object specFile, summary, package, packageRoot, maintainer, version, arch, desc, - license, vendor, post: string + license, vendor, post, buildRequires, requires: string proc getCmdOpts(params: seq[string]): Options = var optParser = initOptParser(params) @@ -35,6 +35,10 @@ proc getCmdOpts(params: seq[string]): Options = result.license = val of "post": result.post = val + of "build-requires": + result.buildRequires = val + of "requires": + result.requires = val of cmdEnd: assert false # cannot happen else: @@ -46,7 +50,7 @@ proc generateInstallScript(path: string): seq[string] = result.add("cp -p " & path[1..^1] & " %{buildroot}" & head & "/") proc replaceTemplate(body, summary, package, maintainer, version, arch, desc, - install, files, license, vendor, post: string): string = + install, files, license, vendor, post, buildRequires, requires: string): string = result = body .replace("{{SUMMARY}}", summary) @@ -60,19 +64,22 @@ proc replaceTemplate(body, summary, package, maintainer, version, arch, desc, .replace("{{FILES}}", files) .replace("{{LICENSE}}", license) .replace("{{POST}}", post) + .replace("{{BUILD_REQUIRES}}", buildRequires) + .replace("{{REQUIRES}}", requires) proc formatDescription(desc: string): string = "Description: " & desc proc fixFile(file, summary, package, maintainer, version, arch, desc, install, - files, license, vendor, post: string) = + files, license, vendor, post, buildRequires, requires: string) = let body = readFile(file) fixedBody = replaceTemplate(body, summary = summary, package = package, maintainer = maintainer, version = version, arch = arch, desc = desc, install = install, files = files, license = license, - vendor = vendor, post = post) + vendor = vendor, post = post, + buildRequires = buildRequires, requires = requires) writeFile(file, fixedBody) proc getInstallFiles(packageRoot: string): (seq[string], seq[string]) = @@ -103,6 +110,14 @@ when isMainModule and not defined modeTest: license = params.license post = params.post + # NOTE: for bugs std/parseopt + buildRequires = + if params.buildRequires == "-": "" + else: "BuildRequires: " & params.buildRequires + requires = + if params.requires == "-": "" + else: "Requires: " & params.requires + let (installScript, files) = getInstallFiles(packageRoot) fixFile(params.specfile, summary = summary, @@ -116,4 +131,6 @@ when isMainModule and not defined modeTest: license = license, vendor = vendor, post = post, + buildRequires = buildRequires, + requires = requires, ) diff --git a/tools/tests/test1.nim b/tools/tests/test1.nim index a9aeb89..a1a690c 100644 --- a/tools/tests/test1.nim +++ b/tools/tests/test1.nim @@ -15,6 +15,8 @@ Vendor: {{VENDOR}} Source: tmp.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildArch: {{ARCH}} +{{BUILD_REQUIRES}} +{{REQUIRES}} %description {{DESC}} @@ -73,7 +75,9 @@ suite "replaceTemplate": files = "/usr/bin/test1\n/usr/bin/test2", license = "MIT", vendor = "author.org", - post = "echo 1;\necho 2" + post = "echo 1;\necho 2", + buildRequires = "BuildRequires: perl-Git = 2.43.0", + requires = "Requires: git-core = 2.43.0", ) const want = """Summary: package summary Name: test @@ -87,6 +91,74 @@ Vendor: author.org Source: tmp.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildArch: noarch +BuildRequires: perl-Git = 2.43.0 +Requires: git-core = 2.43.0 + +%description +description + +%prep +rm -rf $RPM_BUILD_ROOT + +%setup -n %{name} + +%build + +%install +mkdir -p /usr/bin +cp -p test1 /usr/bin/ +mkdir -p /usr/bin +cp -p test2 /usr/bin/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +echo 1; +echo 2 + +%postun + +%files +%defattr(-, root, root) +/usr/bin/test1 +/usr/bin/test2 + +%changelog +""" + check want == got + + test "empty requires": + let got = replaceTemplate( + templateSpec, + summary = "package summary", + package = "test", + maintainer = "author", + version = "1.0.0", + arch = "noarch", + desc = "description", + install = "mkdir -p /usr/bin\ncp -p test1 /usr/bin/\nmkdir -p /usr/bin\ncp -p test2 /usr/bin/", + files = "/usr/bin/test1\n/usr/bin/test2", + license = "MIT", + vendor = "author.org", + post = "echo 1;\necho 2", + buildRequires = "", + requires = "", + ) + const want = """Summary: package summary +Name: test +Version: 1.0.0 +Release: 1%{?dist} +Group: Applications +License: MIT +Packager: author +Vendor: author.org + +Source: tmp.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot +BuildArch: noarch + + %description description