#18 Handle more github quirks
Merged 7 years ago by tibbs. Opened 7 years ago by nim.
Unknown source more-github-quirks  into  master

file modified
+128 -107
@@ -77,131 +77,152 @@

  -- Set spec variable values for each known software publishing service

  if (forgeurl ~= "") then

    local forge          = string.match(forgeurl, "^[^:]+://([^/]+)/")

-   if (string.match(forge, "^gitlab[%.-]") or string.match(forge, "[%.-]gitlab[%.]")) then

-     forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

-     if (forgeurl == nil) then

-       if not silent then

-         rpm.expand("%{error:Gitlab URLs must match https://(…[-.])gitlab[-.]…/owner/repo !\\n}")

-       end

-     else

-       explicitset("forgeurl",   forgeurl)

-       if (commit == "") then

-         rpm.expand("%{error:All Gitlab URLs require commit value knowledge: you need to define %{commit}!\\nPlease vote on https://gitlab.com/gitlab-org/gitlab-ce/issues/38830\\n}")

-       end

-       safeset("archiveext",     "tar.bz2")

-       safeset("forgesetupargs", "-n %{archivename}")

-       if (commit ~= "") or (tag ~= "") then

-         safeset("scm", "git")

-       end

-       local owner   = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

-       local repo    = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

-       local version = rpm.expand("%{?version}")

-       if (version ~= "") and (version ~= "0") and (tag == "") then

-         -- GitLab does not have strong versionning semantics

-         -- Some projects use "version" as release tag, others "v" + "version"

-         -- Tag value needs to be explicitly declared before calling the macro

-         -- in the second case

-         tag = version

-         safeset("tag", tag)

-       end

-       if (tag ~= "") then

-         safeset("archivename", repo .. "-%{tag}-%{commit}")

-         safeset("archiveurl",  "%{forgeurl}/repository/%{tag}/archive.%{archiveext}")

+   if (forge == nil) then

+     if not silent then

+       rpm.expand("%{error:URLs must include a protocol such as https:// and a path starting with / !\\n}")

+     end

+   else

+     if (string.match(forge, "^gitlab[%.-]") or string.match(forge, "[%.-]gitlab[%.]")) then

+       forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

+       if (forgeurl == nil) then

+         if not silent then

+           rpm.expand("%{error:Gitlab URLs must match https://(…[-.])gitlab[-.]…/owner/repo !\\n}")

+         end

        else

-         safeset("archivename", repo .. "-%{commit}")

-         safeset("archiveurl",  "%{forgeurl}/repository/%{commit}/archive.%{archiveext}")

+         explicitset("forgeurl",   forgeurl)

+         if (commit == "") then

+           rpm.expand("%{error:All Gitlab URLs require commit value knowledge: you need to define %{commit}!\\nPlease vote on https://gitlab.com/gitlab-org/gitlab-ce/issues/38830\\n}")

+         end

+         safeset("archiveext",     "tar.bz2")

+         safeset("forgesetupargs", "-n %{archivename}")

+         if (commit ~= "") or (tag ~= "") then

+           safeset("scm", "git")

+         end

+         local owner   = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

+         local repo    = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

+         local version = rpm.expand("%{?version}")

+         if (version ~= "") and (version ~= "0") and (tag == "") then

+           -- GitLab does not have strong versionning semantics

+           -- Some projects use "version" as release tag, others "v" + "version"

+           -- Tag value needs to be explicitly declared before calling the macro

+           -- in the second case

+           tag = version

+           safeset("tag", tag)

+         end

+         if (tag ~= "") then

+           safeset("archivename", repo .. "-%{tag}-%{commit}")

+           safeset("archiveurl",  "%{forgeurl}/repository/%{tag}/archive.%{archiveext}")

+         else

+           safeset("archivename", repo .. "-%{commit}")

+           safeset("archiveurl",  "%{forgeurl}/repository/%{commit}/archive.%{archiveext}")

+         end

        end

      end

-   end

-   if (string.match(forge, "^github[%.-]") or string.match(forge, "[%.-]github[%.]")) then

-     forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

-     if (forgeurl == nil) then

-       if not silent then

-         rpm.expand("%{error:GitHub URLs must match https://(…[-.])github[-.]…/owner/repo !\\n}")

-       end

-     else

-       explicitset("forgeurl",   forgeurl)

-       safeset("archiveext",     "tar.gz")

-       safeset("forgesetupargs", "-n %{archivename}")

-       if (commit ~= "") or (tag ~= "") then

-         safeset("scm", "git")

-       end

-       local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

-       local repo  = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

-       if (tag ~= "") then

-         safeset("archivename",   repo .. "-%{tag}")

-         safeset("archiveurl",    "%{forgeurl}/archive/%{tag}.%{archiveext}")

+     if (string.match(forge, "^github[%.-]") or string.match(forge, "[%.-]github[%.]")) then

+       forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

+       if (forgeurl == nil) then

+         if not silent then

+           rpm.expand("%{error:GitHub URLs must match https://(…[-.])github[-.]…/owner/repo !\\n}")

+         end

        else

-         if (commit ~= "") then

-           safeset("archivename", repo .. "-%{commit}")

-           safeset("archiveurl",  "%{forgeurl}/archive/%{commit}/" .. repo .. "-%{commit}.%{archiveext}")

+         explicitset("forgeurl",   forgeurl)

+         safeset("archiveext",     "tar.gz")

+         local forgesetupargs = "-n %{archivename}"

+         if (commit ~= "") or (tag ~= "") then

+           safeset("scm", "git")

+         end

+         local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

+         local repo  = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

+         if (tag ~= "") then

+           -- if upstream used a version suffix such as -rc1 or -beta it will not

+           -- be a valid version string for rpm but github will accept it fine and

+           -- use the same naming as for other versions: v prefix in the tag and

+           -- archivename, no v prefix in the topdir naming inside the archive

+           local version = rpm.expand("%{?version}")

+           if version ~= "" and

+              (string.match(tag, "^v" .. version .. "[^%d]") or

+               string.match(tag, "^v" .. version .. "$"))    then

+             forgesetupargs = "-n " .. repo .. "-" .. string.gsub(tag, "^v", "")

+           end

+           safeset("archivename",   repo .. "-%{tag}")

+           safeset("archiveurl",    "%{forgeurl}/archive/%{tag}.%{archiveext}")

          else

-           safeset("archivename", repo .. "-%{version}")

-           safeset("archiveurl",   "%{forgeurl}/archive/v%{version}.%{archiveext}")

+           if (commit ~= "") then

+             safeset("archivename", repo .. "-%{commit}")

+             safeset("archiveurl",  "%{forgeurl}/archive/%{commit}/" .. repo .. "-%{commit}.%{archiveext}")

+           else

+             safeset("archivename", repo .. "-%{version}")

+             safeset("archiveurl",   "%{forgeurl}/archive/v%{version}.%{archiveext}")

+           end

          end

+         safeset("forgesetupargs", forgesetupargs)

        end

      end

-   end

-   if (forge == "code.googlesource.com") then

-     forgeurl = string.match(forgeurl, "https://code.googlesource.com/[^#?]*[^/#?]+")

-     if (forgeurl == nil) then

-       if not silent then

-         rpm.expand("%{error:Googlesource URLs must match https://code.googlesource.com/…/repo !\\n}")

-       end

-     else

-       explicitset("forgeurl",   forgeurl)

-       safeset("archiveext",     "tar.gz")

-       safeset("forgesetupargs", "-c")

-       if (commit ~= "") or (tag ~= "") then

-         safeset("scm", "git")

-       end

-       local repo = string.match(forgeurl, "^[^:]+://.+/([^/?#]+)")

-       if (tag ~= "") then

-         safeset("archivename",   repo .. "-%{tag}")

-         safeset("archiveurl",    "%{forgeurl}/+archive/%{tag}.%{archiveext}")

+     if (forge == "code.googlesource.com") then

+       forgeurl = string.match(forgeurl, "https://code.googlesource.com/[^#?]*[^/#?]+")

+       if (forgeurl == nil) then

+         if not silent then

+           rpm.expand("%{error:Googlesource URLs must match https://code.googlesource.com/…/repo !\\n}")

+         end

        else

-         if (commit ~= "") then

-           safeset("archivename", repo .. "-%{commit}")

-           safeset("archiveurl",  "%{forgeurl}/+archive/%{commit}.%{archiveext}")

+         explicitset("forgeurl",   forgeurl)

+         safeset("archiveext",     "tar.gz")

+         safeset("forgesetupargs", "-c")

+         if (commit ~= "") or (tag ~= "") then

+           safeset("scm", "git")

+         end

+         local repo = string.match(forgeurl, "^[^:]+://.+/([^/?#]+)")

+         if (tag ~= "") then

+           safeset("archivename",   repo .. "-%{tag}")

+           safeset("archiveurl",    "%{forgeurl}/+archive/%{tag}.%{archiveext}")

          else

-           safeset("archivename", repo .. "-v%{version}")

-           safeset("archiveurl",  "%{forgeurl}/+archive/v%{version}.%{archiveext}")

+           if (commit ~= "") then

+             safeset("archivename", repo .. "-%{commit}")

+             safeset("archiveurl",  "%{forgeurl}/+archive/%{commit}.%{archiveext}")

+           else

+             safeset("archivename", repo .. "-v%{version}")

+             safeset("archiveurl",  "%{forgeurl}/+archive/v%{version}.%{archiveext}")

+           end

          end

        end

      end

-   end

-   if (forge == "bitbucket.org") then

-     forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

-     if (forgeurl == nil) then

-       if not silent then

-         rpm.expand("%{error:BitBucket URLs must match https://bitbucket.org/owner/repo !\\n}")

-       end

-     else

-       explicitset("forgeurl",   forgeurl)

-       if (commit == "") then

-         rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!\\n}")

-       end

-       local shortcommit = string.sub(commit, 1, 12)

-       safeset("archiveext", "tar.bz2")

-       safeset("scm", "git")

-       local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

-       local repo  = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

-       safeset("archivename",    owner .. "-" .. repo .. "-" .. shortcommit)

-       safeset("forgesetupargs", "-n %{archivename}")

-       if (tag ~= "") then

-         safeset("archiveurl",  "%{forgeurl}/get/%{tag}.%{archiveext}")

+     if (forge == "bitbucket.org") then

+       forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")

+       if (forgeurl == nil) then

+         if not silent then

+           rpm.expand("%{error:BitBucket URLs must match https://bitbucket.org/owner/repo !\\n}")

+         end

        else

-         safeset("archiveurl",  "%{forgeurl}/get/%{commit}.%{archiveext}")

+         explicitset("forgeurl",   forgeurl)

+         if (commit == "") then

+           rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!\\n}")

+         end

+         local shortcommit = string.sub(commit, 1, 12)

+         safeset("archiveext", "tar.bz2")

+         -- Default to git even though BitBucket allows choosing between several SCMs

+         -- Set scm to hg for example before calling the macro if your project does not use git

+         safeset("scm", "git")

+         local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")

+         local repo  = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")

+         safeset("archivename",    owner .. "-" .. repo .. "-" .. shortcommit)

+         safeset("forgesetupargs", "-n %{archivename}")

+         if (tag ~= "") then

+           safeset("archiveurl",  "%{forgeurl}/get/%{tag}.%{archiveext}")

+         else

+           safeset("archiveurl",  "%{forgeurl}/get/%{commit}.%{archiveext}")

+         end

        end

      end

-   end

-   -- Final tests to check forgeurl was successfuly parsed

-   if not silent then

      if (forge == "pagure.io") then

-       rpm.expand("%{warn:https://pagure.io/pagure/issue/861 needs to be resolved before the “pagure.io”\\nsoftware publishing service can be supported.\\n}")

+       if not silent then

+         rpm.expand("%{error:https://pagure.io/pagure/issue/861 needs to be resolved before the “pagure.io”\\nsoftware publishing service can be supported.\\n}")

+       end

      end

-     if (rpm.expand("%{?archivename}") == "") or (rpm.expand("%{?archiveurl}") == "") then

-       rpm.expand("%{error:Automation for the “" .. forge .. "”\\nsoftware publishing service is not implemented yet.\\nPlease extend the %%forgemeta macro!\\n}")

+     -- Final tests to check forgeurl was successfuly parsed

+     if not silent then

+       if (rpm.expand("%{?archivename}") == "") or (rpm.expand("%{?archiveurl}") == "") then

+         rpm.expand("%{error:Automation for the “" .. forge .. "”\\nsoftware publishing service is not implemented yet.\\nPlease extend the %%forgemeta macro!\\n}")

+       end

      end

    end

  end

The existing code does not handle transparently some borderline version tags people insist on using

Long term it may be simpler to define an uversion variable that traces what upstream thinks its version string is, munge it automatically to an rpm %{version}, set automatically the tag, instead of forcing the packager to
1. transform manually upstream version strings to rpm version strings
2. declare the real upstream tag
only to try to guess if the tag is a version string for github and upstream

version is an upstream concept anyway, like commit and tag

can we make support for 1.0.0~rc1 strings?

Metadata Update from @ignatenkobrain:
- Request assigned

7 years ago

The added code basically says that if the upstream tag is
v + rpm-version or
v + rpm-version + something that does not start with a digit

github probably thinks it's a version tag so use github rules for urls and archive content

so yes it will handle upstream tags such as v1.0.0~rc1

If the upstream tag is already 1.0.0~rc1 (because it's synced from a git system that does not try to prettify version tags with a v) I'd say the original code already works

The more elegant way to do it would be to try to parse the upstream version tag and generate the rpm version string, dist suffix and so on from it but I can only imagine the indignation if I proposed a macro that implied rpm versioning was not the alpha and omega every upstream must apply

So, Git doesn't allow ~ in tags. However, generally speaking, if it's something like 1.0-beta1, it cleanly maps to 1.0~beta1.

rebased onto 1073ba2

7 years ago

Pull-Request has been merged by tibbs

7 years ago