1
+ #! /bin/bash
2
+
3
+ # This library holds utilities for building RPMs from Origin.
4
+
5
+ # os::build::rpm::generate_nevra_vars determines the NEVRA of the RPMs
6
+ # that would be built from the current git state.
7
+ #
8
+ # Globals:
9
+ # - OS_GIT_VERSION
10
+ # Arguments:
11
+ # - None
12
+ # Exports:
13
+ # - OS_RPM_NAME
14
+ # - OS_RPM_VERSION
15
+ # - OS_RPM_RELEASE
16
+ function os::build::rpm::get_nvr_vars() {
17
+ # the package name can be overwritten but is normally 'origin'
18
+ OS_RPM_NAME=" ${OS_RPM_NAME:- " origin" } "
19
+
20
+ # we can extract the pacakge version from the build version
21
+ os::build::get_version_vars
22
+ if [[ " ${OS_GIT_VERSION} " =~ ^v([0-9](\. [0-9]+)* )(.* ) ]]; then
23
+ OS_RPM_VERSION=" ${BASH_REMATCH[1]} "
24
+ metadata=" ${BASH_REMATCH[3]} "
25
+ else
26
+ os::log::fatal " Malformed \$ OS_GIT_VERSION: ${OS_GIT_VERSION} "
27
+ fi
28
+
29
+ # we can generate the package release from the git version metadata
30
+ # OS_GIT_VERSION will always have metadata, but either contain
31
+ # pre-release information _and_ build metadata, or only the latter
32
+ # ex.
33
+ # -alpha.0+shasums-123-dirty
34
+ # -alpha.0+shasums-123
35
+ # +shasums-123-dirty
36
+ # +shasums-123
37
+ if [[ " ${metadata: 0: 1} " == " +" ]]; then
38
+ # we only have build metadata, but need to massage it so
39
+ # we can generate a valid RPM release from it
40
+ if [[ " ${metadata} " =~ ^\+ ([a-z0-9]{7})-([0-9]+)(-dirty)? $ ]]; then
41
+ build_sha=" ${BASH_REMATCH[1]} "
42
+ build_num=" ${BASH_REMATCH[2]} "
43
+ else
44
+ os::log::fatal " Malformed git version metadata: ${metadata} "
45
+ fi
46
+ OS_RPM_RELEASE=" 1.${build_num} .${build_sha} "
47
+ elif [[ " ${metadata: 0: 1} " == " -" ]]; then
48
+ # we have both build metadata and pre-release info
49
+ if [[ " ${metadata} " =~ ^-([^\+ ]+)\+ ([a-z0-9]{7})-([0-9]+)(-dirty)? $ ]]; then
50
+ pre_release=" ${BASH_REMATCH[1]} "
51
+ build_sha=" ${BASH_REMATCH[2]} "
52
+ build_num=" ${BASH_REMATCH[3]} "
53
+ else
54
+ os::log::fatal " Malformed git version metadata: ${metadata} "
55
+ fi
56
+ OS_RPM_RELEASE=" 0.${pre_release} .${build_num} .${build_sha} "
57
+ else
58
+ os::log::fatal " Malformed git version metadata: ${metadata} "
59
+ fi
60
+
61
+ export OS_RPM_NAME OS_RPM_VERSION OS_RPM_RELEASE
62
+ }
63
+
64
+
65
+ # os::build::rpm::format_nvr formats the rpm NVR vars generated by
66
+ # os::build::rpm::get_nvr_vars and will generate them if necessary
67
+ #
68
+ # Globals:
69
+ # - OS_RPM_NAME
70
+ # - OS_RPM_VERSION
71
+ # - OS_RPM_RELEASE
72
+ # Arguments:
73
+ # None
74
+ # Returns:
75
+ # None
76
+ function os::build::rpm::format_nvr() {
77
+ if [[ -z " ${OS_RPM_NAME:- } " || -z " ${OS_RPM_VERSION:- } " || -z " ${OS_RPM_RELEASE:- } " ]]; then
78
+ os::build::rpm::get_nvr_vars
79
+ fi
80
+
81
+ echo " ${OS_RPM_NAME} -${OS_RPM_VERSION} -${OS_RPM_RELEASE} "
82
+ }
0 commit comments