Skip to content

Commit 6b901f3

Browse files
authored
Packaging: Inject st2 version into rpm/deb packages (pants-plugins/release) (#6321)
2 parents 8113a26 + 1370f97 commit 6b901f3

File tree

9 files changed

+95
-16
lines changed

9 files changed

+95
-16
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Added
7979
to pants' use of PEX lockfiles. This is not a user-facing addition.
8080
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
8181
#6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307
82-
#6311 #6314 #6315 #6317 #6319 #6312 #6320
82+
#6311 #6314 #6315 #6317 #6319 #6312 #6320 #6321
8383
Contributed by @cognifloyd
8484
* Build of ST2 EL9 packages #6153
8585
Contributed by @amanda11
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
orquesta@ git+https://github.com/StackStorm/orquesta.git@5ba1467614b2ef8b4709b2ca89e68baa671e8975
2+
setuptools

contrib/runners/orquesta_runner/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
# in-requirements.txt for that component and then run 'make requirements' to
77
# update the component requirements.txt
88
orquesta@ git+https://github.com/StackStorm/orquesta.git@5ba1467614b2ef8b4709b2ca89e68baa671e8975
9+
setuptools<78

fixed-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ tooz==6.3.0
7272
# virtualenv==20.29.2 (<21) has pip==25.0.1 wheel==0.45.1 setuptools==75.3.0
7373
# lockfiles/st2.lock has pip==25.0.1 wheel==0.45.1 setuptools==75.3.0
7474
virtualenv==20.29.2
75+
# This setuptools version number is in the Makefile, but CircleCI builds are pulling a version
76+
# that is incompatible with our logshipper fork.
77+
setuptools<78
7578
webob==1.8.9
7679
webtest==3.0.1
7780
zake==0.2.2

pants-plugins/release/rules.py

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@
2121
from __future__ import annotations
2222

2323
import re
24+
from dataclasses import dataclass
2425

26+
from pants.backend.nfpm.fields.version import NfpmVersionField, NfpmVersionSchemaField
27+
from pants.backend.nfpm.util_rules.inject_config import (
28+
InjectedNfpmPackageFields,
29+
InjectNfpmPackageFieldsRequest,
30+
)
2531
from pants.backend.python.util_rules.package_dists import (
2632
SetupKwargs,
2733
SetupKwargsRequest,
2834
)
2935
from pants.engine.fs import DigestContents, GlobMatchErrorBehavior, PathGlobs
36+
from pants.engine.internals.native_engine import Field
3037
from pants.engine.target import Target
3138
from pants.engine.rules import collect_rules, Get, MultiGet, rule, UnionRule
3239
from pants.util.frozendict import FrozenDict
@@ -88,6 +95,40 @@ def is_applicable(cls, _: Target) -> bool:
8895
# return target.address.spec.startswith("st2")
8996

9097

98+
@dataclass(frozen=True)
99+
class StackStormVersionRequest:
100+
version_file: str
101+
description_of_origin: str
102+
103+
104+
@dataclass(frozen=True)
105+
class StackStormVersion:
106+
value: str
107+
108+
109+
@rule
110+
async def extract_version(request: StackStormVersionRequest) -> StackStormVersion:
111+
version_digest_contents = await Get(
112+
DigestContents,
113+
PathGlobs(
114+
[request.version_file],
115+
description_of_origin=request.description_of_origin,
116+
glob_match_error_behavior=GlobMatchErrorBehavior.error,
117+
),
118+
)
119+
120+
version_file_contents = version_digest_contents[0].content.decode()
121+
version_match = re.search(
122+
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file_contents, re.M
123+
)
124+
if not version_match:
125+
raise ValueError(
126+
f"Could not find the __version__ in {request.version_file}\n{version_file_contents}"
127+
)
128+
129+
return StackStormVersion(version_match.group(1))
130+
131+
91132
@rule
92133
async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwargs:
93134
kwargs = request.explicit_kwargs.copy()
@@ -100,13 +141,12 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa
100141

101142
version_file = kwargs.pop("version_file")
102143

103-
version_digest_contents, readme_digest_contents = await MultiGet(
144+
version, readme_digest_contents = await MultiGet(
104145
Get(
105-
DigestContents,
106-
PathGlobs(
107-
[f"{request.target.address.spec_path}/{version_file}"],
146+
StackStormVersion,
147+
StackStormVersionRequest(
148+
version_file=f"{request.target.address.spec_path}/{version_file}",
108149
description_of_origin=f"StackStorm version file: {version_file}",
109-
glob_match_error_behavior=GlobMatchErrorBehavior.error,
110150
),
111151
),
112152
Get(
@@ -118,19 +158,10 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa
118158
),
119159
)
120160

121-
version_file_contents = version_digest_contents[0].content.decode()
122-
version_match = re.search(
123-
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file_contents, re.M
124-
)
125-
if not version_match:
126-
raise ValueError(
127-
f"Could not find the __version__ in {request.target.address.spec_path}/{version_file}\n{version_file_contents}"
128-
)
129-
130161
# Hardcode certain kwargs and validate that they weren't already set.
131162
hardcoded_kwargs = PROJECT_METADATA.copy()
132163
hardcoded_kwargs["project_urls"] = FrozenDict(PROJECT_URLS)
133-
hardcoded_kwargs["version"] = version_match.group(1)
164+
hardcoded_kwargs["version"] = version.value
134165

135166
long_description = (
136167
readme_digest_contents[0].content.decode() if readme_digest_contents else ""
@@ -162,8 +193,43 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa
162193
return SetupKwargs(kwargs, address=request.target.address)
163194

164195

196+
class StackStormNfpmPackageFieldsRequest(InjectNfpmPackageFieldsRequest):
197+
@classmethod
198+
def is_applicable(cls, _: Target) -> bool:
199+
return True
200+
201+
202+
@rule
203+
async def inject_package_fields(
204+
request: StackStormNfpmPackageFieldsRequest,
205+
) -> InjectedNfpmPackageFields:
206+
address = request.target.address
207+
208+
version_file = "st2common/st2common/__init__.py"
209+
extracted_version = await Get(
210+
StackStormVersion,
211+
StackStormVersionRequest(
212+
version_file=version_file,
213+
description_of_origin=f"StackStorm version file: {version_file}",
214+
),
215+
)
216+
217+
version: str = extracted_version.value
218+
if version.endswith("dev") and version[-4] != "-":
219+
# nfpm parses this into version[-version_prerelease][+version_metadata]
220+
# that dash is required to be a valid semver version.
221+
version = version.replace("dev", "-dev")
222+
223+
fields: list[Field] = [
224+
NfpmVersionSchemaField("semver", address=address),
225+
NfpmVersionField(version, address=address),
226+
]
227+
return InjectedNfpmPackageFields(fields, address=address)
228+
229+
165230
def rules():
166231
return [
167232
*collect_rules(),
168233
UnionRule(SetupKwargsRequest, StackStormSetupKwargsRequest),
234+
UnionRule(InjectNfpmPackageFieldsRequest, StackStormNfpmPackageFieldsRequest),
169235
]

pants.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ backend_packages = [
3131
# packaging
3232
"pants.backend.experimental.makeself",
3333

34+
# packaging
35+
"pants.backend.experimental.nfpm",
36+
3437
# internal plugins in pants-plugins/
3538
"pants.backend.plugin_development",
3639
"api_spec",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ requests==2.32.3
6262
retrying==1.3.4
6363
routes==2.5.1
6464
semver==3.0.4
65+
setuptools<78
6566
simplejson
6667
six==1.17.0
6768
sseclient-py==1.8.0

st2actions/in-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ lockfile
1919
# needed by core "linux" pack - TODO: create virtualenv for linux pack on postinst
2020
pyinotify
2121
logshipper@ git+https://github.com/StackStorm/logshipper.git@stackstorm_patched ; platform_system=="Linux"
22+
# logshipper has metadata in setup.cfg that is not supported by setuptools 78, so we need
23+
# an explicit dep (from fixed-requirements.txt) to prevent CircleCI from pulling that in.
24+
setuptools
2225
# required by pack_mgmt/setup_virtualenv.py#L135
2326
virtualenv
2427
# needed by requests

st2actions/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ python-dateutil==2.9.0.post0
2222
python-json-logger
2323
pyyaml==6.0.2
2424
requests==2.32.3
25+
setuptools<78
2526
six==1.17.0
2627
urllib3==2.2.3

0 commit comments

Comments
 (0)