@@ -18,11 +18,11 @@ import (
1818// but with a leading `v`.
1919var semVerTag = regexp .MustCompile (`^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` )
2020
21- // versions represents Docker image names and tags, and Debian package version .
21+ // versions represents Docker image names and tags, and package versions used by Debian and RPM .
2222type versions struct {
2323 dockerDevelopmentImages []string
2424 dockerProductionImages []string
25- debian string
25+ packageVersion string
2626}
2727
2828// parseGitTag parses git tag in specific format and returns SemVer components.
@@ -82,11 +82,13 @@ func debugEnv(action *githubactions.Action) {
8282 }
8383}
8484
85- // defineVersion extracts Docker image names and tags, and Debian package version using the environment variables defined by GitHub Actions.
85+ // defineVersion extracts Docker image names and tags, and package versions used by Debian and RPM
86+ // using the environment variables defined by GitHub Actions.
8687//
87- // The Debian package version is based on `default_version` in the control file.
88- // See https://www.debian.org/doc/debian-policy/ch-controlfields.html#version.
89- // We use `upstream_version` only.
88+ // The Debian and RPM package versions are based on `default_version` in the control file.
89+ // See https://www.debian.org/doc/debian-policy/ch-controlfields.html#version,
90+ // and https://fedoraproject.org/wiki/PackagingDrafts/TildeVersioning#Basic_versioning_rules.
91+ // The Debian uses `upstream_version` only.
9092// For that reason, we can't use `-`, so we replace it with `~`.
9193func defineVersion (controlDefaultVersion , pgVersion string , getenv githubactions.GetenvFunc ) (* versions , error ) {
9294 repo := getenv ("GITHUB_REPOSITORY" )
@@ -139,29 +141,33 @@ func defineVersion(controlDefaultVersion, pgVersion string, getenv githubactions
139141 return res , nil
140142}
141143
142- // defineVersionForPR defines Docker image names and tags, and Debian package version for PR.
144+ // defineVersionForPR defines Docker image names and tags, and package version for PR.
143145// See [defineVersion].
144146func defineVersionForPR (controlDefaultVersion , pgVersion , owner , repo , branch string ) * versions {
145147 // for branches like "dependabot/submodules/XXX"
146148 parts := strings .Split (branch , "/" )
147149 branch = parts [len (parts )- 1 ]
148150
151+ packageVersion := fmt .Sprintf ("%s-pr-%s" , controlDefaultVersion , branch )
152+ packageVersion = disallowedDebian .ReplaceAllString (packageVersion , "~" )
153+ packageVersion = disallowedRPM .ReplaceAllString (packageVersion , "~" )
154+
149155 res := & versions {
150156 dockerDevelopmentImages : []string {
151157 fmt .Sprintf ("ghcr.io/%s/postgres-%s-dev:%s-pr-%s" , owner , repo , pgVersion , branch ),
152158 },
153159 dockerProductionImages : []string {
154160 fmt .Sprintf ("ghcr.io/%s/postgres-%s-dev:%s-pr-%s-prod" , owner , repo , pgVersion , branch ),
155161 },
156- debian : disallowedDebian . ReplaceAllString ( fmt . Sprintf ( "%s-pr-%s" , controlDefaultVersion , branch ), "~" ) ,
162+ packageVersion : packageVersion ,
157163 }
158164
159165 // PRs are only for testing; no Quay.io and Docker Hub repos
160166
161167 return res
162168}
163169
164- // defineVersionForBranch defines Docker image names and tags, and Debian package version for branch.
170+ // defineVersionForBranch defines Docker image names and tags, and package version for branch.
165171// See [defineVersion].
166172func defineVersionForBranch (controlDefaultVersion , pgVersion , owner , repo , branch string ) (* versions , error ) {
167173 if branch != "ferretdb" {
@@ -175,7 +181,7 @@ func defineVersionForBranch(controlDefaultVersion, pgVersion, owner, repo, branc
175181 dockerProductionImages : []string {
176182 fmt .Sprintf ("ghcr.io/%s/postgres-%s-dev:%s-ferretdb-prod" , owner , repo , pgVersion ),
177183 },
178- debian : fmt .Sprintf ("%s~ferretdb" , controlDefaultVersion ),
184+ packageVersion : fmt .Sprintf ("%s~ferretdb" , controlDefaultVersion ),
179185 }
180186
181187 // forks don't have Quay.io and Docker Hub orgs
@@ -196,7 +202,7 @@ func defineVersionForBranch(controlDefaultVersion, pgVersion, owner, repo, branc
196202 return res , nil
197203}
198204
199- // defineVersionForTag defines Docker image names and tags, and Debian package version for tag.
205+ // defineVersionForTag defines Docker image names and tags, and package version for tag.
200206// See [defineVersion].
201207func defineVersionForTag (controlDefaultVersion , pgVersion , owner , repo , tag string ) (* versions , error ) {
202208 major , minor , patch , prerelease , err := parseGitTag (tag )
@@ -219,8 +225,12 @@ func defineVersionForTag(controlDefaultVersion, pgVersion, owner, repo, tag stri
219225 tags = append (tags , "latest" )
220226 }
221227
228+ packageVersion := fmt .Sprintf ("%s-%s" , tagVersion , prerelease )
229+ packageVersion = disallowedDebian .ReplaceAllString (packageVersion , "~" )
230+ packageVersion = disallowedRPM .ReplaceAllString (packageVersion , "~" )
231+
222232 res := versions {
223- debian : disallowedDebian . ReplaceAllString ( fmt . Sprintf ( "%s-%s" , tagVersion , prerelease ), "~" ) ,
233+ packageVersion : packageVersion ,
224234 }
225235
226236 for _ , t := range tags {
@@ -253,7 +263,7 @@ func defineVersionForTag(controlDefaultVersion, pgVersion, owner, repo, tag stri
253263func setSummary (action * githubactions.Action , version * versions ) {
254264 var buf strings.Builder
255265
256- fmt .Fprintf (& buf , "Debian package version (`upstream_version` only): `%s`\n \n " , version .debian )
266+ fmt .Fprintf (& buf , "Package version (Debian with `upstream_version` only, or RPM ): `%s`\n \n " , version .packageVersion )
257267
258268 w := tabwriter .NewWriter (& buf , 1 , 1 , 1 , ' ' , tabwriter .Debug )
259269 fmt .Fprintf (w , "\t Type\t Docker image\t \n " )
@@ -278,7 +288,7 @@ func setSummary(action *githubactions.Action, version *versions) {
278288func main () {
279289 controlFileF := flag .String ("control-file" , "../pg_documentdb/documentdb.control" , "pg_documentdb/documentdb.control file path" )
280290 pgVersionF := flag .String ("pg-version" , "17" , "Major PostgreSQL version" )
281- debianOnlyF := flag .Bool ("debian- only" , false , "Only set output for Debian package version" )
291+ packageVersionOnlyF := flag .Bool ("package-version- only" , false , "Only set output for package version" )
282292
283293 flag .Parse ()
284294
@@ -307,13 +317,13 @@ func main() {
307317 action .Fatalf ("%s" , err )
308318 }
309319
310- action .SetOutput ("debian_version " , res .debian )
320+ action .SetOutput ("package_version " , res .packageVersion )
311321
312- if * debianOnlyF {
322+ if * packageVersionOnlyF {
313323 // Only 3 summaries are shown in the GitHub Actions UI by default,
314- // and Docker summaries are more important (and include Debian version anyway).
315- output := fmt . Sprintf ( "Debian package version (`upstream_version` only): `%s`" , res .debian )
316- action . Infof ( "%s" , output )
324+ // and Docker summaries are more important (and include package version anyway).
325+ action . Infof ( " package version (Debian with `upstream_version` only, or RPM ): `%s`" , res .packageVersion )
326+
317327 return
318328 }
319329
0 commit comments