#156 Implement flags in %autorelease macro
Merged 2 years ago by nphilipp. Opened 2 years ago by dkirwan.
fedora-infra/ dkirwan/rpmautospec 152_snapshots_prereleases_nohotfixes  into  main

@@ -1,4 +1,4 @@ 

- %autorelease(e:s:hp) %{?-p:0.}1%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{?dist}%{?-h:.1}

+ %autorelease(e:s:p) %{?-p:0.}1%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{?dist}

  %autochangelog %{lua:

      locale = os.setlocale(nil)

      os.setlocale("C.utf8")

@@ -1,41 +0,0 @@ 

- ## START: Automatic release macro

- %define autorelease(e:s:hp) %{lua:

-   has_extraver = rpm.expand("%{-e}") ~= ""

-   has_snapinfo = rpm.expand("%{-s}") ~= ""

-   is_prerelease = rpm.expand("%{-p}") ~= ""

-   is_hotfix = rpm.expand("%{-h}") ~= ""

- 

-   if has_extraver

-   then

-     rpm.define("_autorelease_extraver .%{-e*}")

-   else

-     rpm.define("_autorelease_extraver %{nil}")

-   end

- 

-   if has_snapinfo

-   then

-     rpm.define("_autorelease_snapinfo .%{-s*}")

-   else

-     rpm.define("_autorelease_snapinfo %{nil}")

-   end

- 

-   if is_prerelease

-   then

-     if is_hotfix

-     then

-       option = "prerel_hotfix_cadence"

-     else

-       option = "prerel_cadence"

-     end

-   else

-     if is_hotfix

-     then

-       option = "hotfix_cadence"

-     else

-       option = "normal_cadence"

-     end

-   end

- 

-   print(rpm.expand("%_autorelease_" .. option))

- }

- ## END: Automatic release macro

file modified
+15 -13
@@ -15,12 +15,8 @@ 

  _log = logging.getLogger(__name__)

  __here__ = os.path.dirname(__file__)

  

- autorelease_macro_path = os.path.join(__here__, "etc", "autorelease-macro.txt")

  autorelease_template = """## START: Set by rpmautospec

- %define _autorelease_normal_cadence {autorelease_normal}%{{?_autorelease_extraver}}%{{?_autorelease_snapinfo}}%{{?dist}}

- %define _autorelease_hotfix_cadence Sorry, the hotfix cadence isn't implemented yet.

- %define _autorelease_prerel_cadence Sorry, the pre-release cadence isn't implemented yet.

- %define _autorelease_prerel_hotfix_cadence Sorry, the hotfix, pre-release cadences aren't implemented yet.

+ %define autorelease(e:s:p) %{{?-p:0.}}{autorelease_number}%{{?-e:.%{{-e*}}}}%{{?-s:.%{{-s*}}}}%{{?dist}}

  ## END: Set by rpmautospec

  """  # noqa: E501

  
@@ -80,7 +76,7 @@ 

  def get_autorelease(srcdir, dist, session):

      # Not setting latest_evr, next_epoch_version just goes with what's in the package and latest

      # builds.

-     release = calculate_release(srcdir=srcdir, strip_dist=True)

+     release = calculate_release(srcdir=srcdir)

      return release

  

  
@@ -141,15 +137,15 @@ 

      if dist.startswith("."):

          dist = dist[1:]

  

-     new_rel = get_autorelease(srcdir, dist, session)

+     autorelease_number = get_autorelease(srcdir, dist, session)

      with open(specfile_name, "r") as specfile, tempfile.NamedTemporaryFile("w") as tmp_specfile:

          # Process the spec file into a temporary file...

          if has_autorelease:

              # Write %autorelease macro header

-             with open(autorelease_macro_path, "r") as autorelease_macro_file:

-                 print(autorelease_template.format(autorelease_normal=new_rel), file=tmp_specfile)

-                 for line in autorelease_macro_file:

-                     print(line, file=tmp_specfile, end="")

+             print(

+                 autorelease_template.format(autorelease_number=autorelease_number),

+                 file=tmp_specfile,

+             )

  

          for lineno, line in enumerate(specfile, start=1):

              if changelog_lineno:
@@ -163,11 +159,17 @@ 

              print(line, file=tmp_specfile, end="")

  

          if has_autochangelog:

-             print("\n".join(produce_changelog(srcdir, latest_rel=new_rel)), file=tmp_specfile)

+             print(

+                 "\n".join(produce_changelog(srcdir, latest_rel=autorelease_number)),

+                 file=tmp_specfile,

+             )

          elif changelog_lineno is None:

              print("No changelog found, auto creating")

              print("\n%changelog\n", file=tmp_specfile, end="")

-             print("\n".join(produce_changelog(srcdir, latest_rel=new_rel)), file=tmp_specfile)

+             print(

+                 "\n".join(produce_changelog(srcdir, latest_rel=autorelease_number)),

+                 file=tmp_specfile,

+             )

  

          tmp_specfile.flush()

  

Metadata Update from @dkirwan:
- Request assigned

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Verify:

To verify try the following:

  • Take a copy of a repo and replace the Release value with %autorelease in the specfile.
  • Commit the change
cp ../guake /tmp/tmpguake
  • Run the process-distgit command against the repo
./rpmautospec.py process-distgit /tmp/tmpguake/
calculate_release head: ebda32a1c8db6a83409b686257ee93dfa889006d
Checking commit 63324e6e10633522b84a095a8e98018c61395db8 ...
... -> 3.7.0
Checking commit 8c140461a910c533bf0b4e525ca2c1b825b7b68e ...
... -> 3.7.0
Checking commit f12287c31b6fcd8a7fbaac5ce6fd930fcf680f05 ...
... -> 3.6.3
calculate_release release: 3
  • Check the specfile, it should have the autorelease macro populated at the top of the file
head  /tmp/tmpguake/guake.spec 
## START: Set by rpmautospec
%define autorelease(e:s:p) %{?-p:0.}3%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{?dist}
## END: Set by rpmautospec

Name:           guake
Version:        3.7.0

Finally can check what the macro evaluates to using rpm

rpm --specfile /tmp/tmpguake/guake.spec
guake-3.7.0-3.fc32.noarch

I tested this on my end with the same results, also played around with flags on the processed spec file and results look good to me.

Ah there are a couple of too long lines, I'll try to fix and push to your repo…

rebased onto 64d1b7f

2 years ago

Build succeeded.

Pull-Request has been merged by nphilipp

2 years ago