Skip to content

Commit f2856d2

Browse files
committed
Bring configuration over to python
Add 2 Python functions that will be used at a later commit in order to consolidate the configuration code in a single place. ghstack-source-id: 9dd09f7 Pull Request resolved: #1145
1 parent 116824e commit f2856d2

1 file changed

Lines changed: 89 additions & 10 deletions

File tree

snapshot_manager/snapshot_manager/config.py

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@ class Config:
1111
chroot_pattern: str = r"^(fedora-(rawhide|[0-9]+)|rhel-[8,9]-)"
1212
"""Regular expression to select chroots from all chroots currently supported on Copr."""
1313

14+
chroots: list[str] = None
15+
"""A list of chroot names. To be filled automatically for you from the chroot_pattern. See util.augment_config_with_chroots()"""
16+
1417
packages: list[str] = dataclasses.field(
1518
default_factory=lambda: [
1619
"llvm",
1720
]
1821
)
1922
"""List of packages that are relevant to you."""
2023

21-
active_build_state_pattern: str = r"(running|waiting|pending|importing|starting)"
22-
"""Regular expression to select what states of a copr build are considered active."""
23-
2424
datetime: "datetime.datetime" = datetime.datetime.now()
2525
"""Datetime of today"""
2626

2727
build_strategy: str = "big-merge"
2828
"""The build strategy to use a by default."""
2929

3030
github_repo: str = "fedora-llvm-team/llvm-snapshots-test"
31-
"""Default github repo to use"""
31+
"""Default github repo to use for creating issues"""
32+
33+
package_clone_url: str = "https://src.fedoraproject.org/rpms/llvm.git"
34+
"""The package to clone from when creating RPMs"""
3235

33-
github_token_env: str = "GH_TEST_TOKEN"
36+
package_clone_ref: str = "rawhide"
37+
"""The git clone ref to use for creating the RPMs"""
38+
39+
github_token_env: str = "GITHUB_TOKEN"
3440
"""Default name of the environment variable which holds the github token"""
3541

3642
update_marker: str = "<!--UPDATES_FOLLOW_HERE-->"
@@ -42,6 +48,9 @@ class Config:
4248
creator_handle: str = "github-actions[bot]"
4349
"""The Github user that is expected to have created the daily issue (TODO(kwk): Improve documentation)"""
4450

51+
copr_target_project: str = "@fedora-llvm-team/llvm-snapshots"
52+
"""The Copr project that the daily snapshot will be converted to if all goes well"""
53+
4554
copr_ownername: str = "@fedora-llvm-team"
4655
"""The Copr owner name of the project to work with"""
4756

@@ -80,11 +89,6 @@ def copr_projectname(self) -> str:
8089
"""
8190
return self.copr_project_tpl.replace("YYYYMMDD", self.yyyymmdd)
8291

83-
@property
84-
def copr_project(self) -> str:
85-
"""Returns the owner/project string for the current date."""
86-
return f"{self.config.copr_ownername}/{self.config.copr_projectname}"
87-
8892
@property
8993
def copr_monitor_url(self) -> str:
9094
"""Takes the copr_monitor_tpl and replaces the YYYYMMDD placeholder (if any) with a date.
@@ -113,3 +117,78 @@ def yyyymmdd(self) -> str:
113117
'20240229'
114118
"""
115119
return self.datetime.strftime("%Y%m%d")
120+
121+
def to_github_dict(self) -> dict:
122+
"""Returns a subset of config entries to be used in a github workflow matrix.
123+
124+
The keys in this dict are accessed from github workflow files using the "matrix." object.
125+
For example the maintainer handle will be accessed as `${{ matrix.maintainer_handle }}`.
126+
127+
Examples:
128+
129+
>>> import pprint
130+
>>> pprint.pprint(Config(build_strategy="mybuildstrategy",
131+
... copr_target_project="@mycoprgroup/mycoprproject",
132+
... package_clone_url="https://src.fedoraproject.org/rpms/mypackage.git",
133+
... package_clone_ref="mainbranch",
134+
... maintainer_handle="fakeperson",
135+
... copr_project_tpl="SomeProjectTemplate-YYYYMMDD",
136+
... copr_monitor_tpl="https://copr.fedorainfracloud.org/coprs/g/mycoprgroup/SomeProjectTemplate-YYYYMMDD/monitor/",
137+
... chroot_pattern="^(fedora-(rawhide|[0-9]+)|rhel-[8,9]-)",
138+
... chroots=["fedora-rawhide-x86_64", "rhel-9-ppc64le"]
139+
... ).to_github_dict())
140+
{'chroot_pattern': '^(fedora-(rawhide|[0-9]+)|rhel-[8,9]-)',
141+
'chroots': 'fedora-rawhide-x86_64 rhel-9-ppc64le',
142+
'clone_ref': 'mainbranch',
143+
'clone_url': 'https://src.fedoraproject.org/rpms/mypackage.git',
144+
'copr_monitor_tpl': 'https://copr.fedorainfracloud.org/coprs/g/mycoprgroup/SomeProjectTemplate-YYYYMMDD/monitor/',
145+
'copr_ownername': '@fedora-llvm-team',
146+
'copr_project_tpl': 'SomeProjectTemplate-YYYYMMDD',
147+
'copr_target_project': '@mycoprgroup/mycoprproject',
148+
'maintainer_handle': 'fakeperson',
149+
'name': 'mybuildstrategy'}
150+
"""
151+
return {
152+
"name": self.build_strategy,
153+
"copr_target_project": self.copr_target_project,
154+
"clone_url": self.package_clone_url,
155+
"clone_ref": self.package_clone_ref,
156+
"maintainer_handle": self.maintainer_handle,
157+
"copr_ownername": self.copr_ownername,
158+
"copr_project_tpl": self.copr_project_tpl,
159+
"copr_monitor_tpl": self.copr_monitor_tpl,
160+
"chroot_pattern": self.chroot_pattern,
161+
"chroots": " ".join(self.chroots),
162+
}
163+
164+
165+
def build_config_map() -> dict[str, Config]:
166+
"""Builds a dictionary for each supported build strategy with the name of the build strategy as key.
167+
168+
Returns:
169+
dict: The config map with build strategies as keys and config objects as values.
170+
"""
171+
configs = [
172+
Config(
173+
build_strategy="big-merge",
174+
copr_target_project="@fedora-llvm-team/llvm-snapshots",
175+
package_clone_url="https://src.fedoraproject.org/rpms/llvm.git",
176+
package_clone_ref="rawhide",
177+
maintainer_handle="tbaederr",
178+
copr_project_tpl="llvm-snapshots-big-merge-YYYYMMDD",
179+
copr_monitor_tpl="https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots-big-merge-YYYYMMDD/monitor/",
180+
chroot_pattern="^(fedora-(rawhide|[0-9]+)|rhel-[8,9]-)",
181+
),
182+
Config(
183+
build_strategy="pgo",
184+
copr_target_project="@fedora-llvm-team/llvm-snapshots-pgo",
185+
package_clone_url="https://src.fedoraproject.org/forks/kkleine/rpms/llvm.git",
186+
package_clone_ref="pgo",
187+
maintainer_handle="kwk",
188+
copr_project_tpl="llvm-snapshots-pgo-YYYYMMDD",
189+
copr_monitor_tpl="https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots-pgo-YYYYMMDD/monitor/",
190+
chroot_pattern="(fedora-41)",
191+
),
192+
]
193+
194+
return {config.build_strategy: config for config in configs}

0 commit comments

Comments
 (0)