basstler-github 4.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- basstler/github/__init__.py +0 -0
- basstler/github/actions_budget.py +428 -0
- basstler/github/actions_secret.py +25 -0
- basstler/github/actions_settings.py +162 -0
- basstler/github/actions_usage.py +297 -0
- basstler/github/basstler_project.py +75 -0
- basstler/github/branch_pull_request.py +24 -0
- basstler/github/client.py +452 -0
- basstler/github/comparison.py +60 -0
- basstler/github/constants.py +197 -0
- basstler/github/credential.py +85 -0
- basstler/github/exceptions.py +264 -0
- basstler/github/file_proposal.py +440 -0
- basstler/github/fork_sync.py +44 -0
- basstler/github/git_objects.py +57 -0
- basstler/github/graphql.py +101 -0
- basstler/github/issue.py +221 -0
- basstler/github/label.py +78 -0
- basstler/github/login_lending.py +46 -0
- basstler/github/main_failure.py +289 -0
- basstler/github/permission_level.py +33 -0
- basstler/github/pull_request.py +74 -0
- basstler/github/pull_request_changes.py +141 -0
- basstler/github/pull_request_description.py +145 -0
- basstler/github/pull_request_ends.py +58 -0
- basstler/github/pull_request_form.py +136 -0
- basstler/github/pull_request_models.py +321 -0
- basstler/github/pull_request_record.py +369 -0
- basstler/github/pull_request_source.py +395 -0
- basstler/github/pull_request_state.py +437 -0
- basstler/github/queries/pull_request_for_branch.graphql +17 -0
- basstler/github/queries/review_threads_page.graphql +72 -0
- basstler/github/query_documents.py +37 -0
- basstler/github/release_version.py +565 -0
- basstler/github/remote.py +36 -0
- basstler/github/repository.py +532 -0
- basstler/github/repository_access.py +459 -0
- basstler/github/repository_attachment.py +95 -0
- basstler/github/repository_details.py +98 -0
- basstler/github/repository_option.py +43 -0
- basstler/github/repository_resources.py +133 -0
- basstler/github/rest_models.py +353 -0
- basstler/github/review_models.py +223 -0
- basstler/github/run_listing.py +148 -0
- basstler/github/stack_configuration.py +178 -0
- basstler/github/states.py +257 -0
- basstler/github/token_form.py +360 -0
- basstler/github/tooling_labels.py +83 -0
- basstler/github/user_steps.py +170 -0
- basstler/github/web_form.py +56 -0
- basstler/github/web_page.py +33 -0
- basstler/github/wire_form.py +159 -0
- basstler/github/workflow_run.py +126 -0
- basstler/github/workflows.py +561 -0
- basstler/templates/actions_budget.py.jinja +26 -0
- basstler_github-4.2.0.dist-info/METADATA +16 -0
- basstler_github-4.2.0.dist-info/RECORD +60 -0
- basstler_github-4.2.0.dist-info/WHEEL +4 -0
- basstler_github-4.2.0.dist-info/licenses/LICENSE +202 -0
- basstler_github-4.2.0.dist-info/licenses/NOTICE +13 -0
|
File without changes
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Actions budget: the rules basstler holds every workflow of a repository to, within
|
|
3
|
+
limits the repository sets.
|
|
4
|
+
|
|
5
|
+
The workflow files are the only statement of what each workflow does. The repository's
|
|
6
|
+
budget file, a Python module defining :attr:`BudgetDefinition.FUNCTION`, holds only what they cannot
|
|
7
|
+
say: the limits every workflow is held to, and the workflows whose own limits differ. A
|
|
8
|
+
workflow the budget does not name is held to the defaults, so a new workflow needs no
|
|
9
|
+
entry before it is checked.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import dataclasses
|
|
16
|
+
import re
|
|
17
|
+
import runpy
|
|
18
|
+
from collections.abc import Iterable, Mapping
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from enum import StrEnum
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
from basstler.class_property import classproperty
|
|
25
|
+
from basstler.exceptions import (
|
|
26
|
+
BudgetFileExists,
|
|
27
|
+
BudgetViolation,
|
|
28
|
+
JobTimeoutOverCeiling,
|
|
29
|
+
MissingBudgetFunction,
|
|
30
|
+
MissingForkGuard,
|
|
31
|
+
MissingJobTimeout,
|
|
32
|
+
MissingLabelGuard,
|
|
33
|
+
MissingPullRequestCancellation,
|
|
34
|
+
OverrideWithoutWorkflow,
|
|
35
|
+
ScheduledWorkflow,
|
|
36
|
+
TooManyJobsOnEveryPush,
|
|
37
|
+
UncountableJobs,
|
|
38
|
+
)
|
|
39
|
+
from basstler.github.workflows import ActivityType, Job, TriggerEvent, Workflow
|
|
40
|
+
from basstler.locations import PackageLocation, ProjectLocation
|
|
41
|
+
from basstler.render_common import create_template_environment
|
|
42
|
+
from basstler.text_file import TextFile
|
|
43
|
+
|
|
44
|
+
# %% vocabulary
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BudgetDefinition(StrEnum):
|
|
48
|
+
"""
|
|
49
|
+
The names a budget file defines.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
FUNCTION = "actions_budget"
|
|
53
|
+
"""
|
|
54
|
+
The function returning the repository's :class:`ActionsBudget`.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class BudgetTemplate(StrEnum):
|
|
59
|
+
"""
|
|
60
|
+
The template a budget file is written from.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
FILE = "actions_budget.py.jinja"
|
|
64
|
+
"""
|
|
65
|
+
The whole budget file.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# %% the limits one workflow is held to
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True)
|
|
73
|
+
class WorkflowLimits:
|
|
74
|
+
"""
|
|
75
|
+
The limits one workflow is held to.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
job_timeout_minutes: int = 60
|
|
79
|
+
"""
|
|
80
|
+
The most any job may declare as its ``timeout-minutes``.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
jobs_per_push_run: int = 4
|
|
84
|
+
"""
|
|
85
|
+
The most jobs a run may take runners for when the workflow runs on every push.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
skips_push_on_fork: bool = True
|
|
89
|
+
"""
|
|
90
|
+
Whether a workflow answering ``push`` has to skip it on a fork, which only re-tests
|
|
91
|
+
code the upstream repository has already tested.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
runs_per_day: int | None = None
|
|
95
|
+
"""
|
|
96
|
+
The most runs the workflow may have in 24 hours, or ``None`` for no ceiling.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
jobs_per_day: int | None = None
|
|
100
|
+
"""
|
|
101
|
+
The most jobs the workflow's runs may have in 24 hours, or ``None`` for no ceiling.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
@classproperty
|
|
105
|
+
def fork_push_condition(cls) -> str:
|
|
106
|
+
"""
|
|
107
|
+
The condition that skips a job on a push to a fork. Read off the event, so no
|
|
108
|
+
repository is named.
|
|
109
|
+
"""
|
|
110
|
+
return "github.event_name != 'push' || !github.event.repository.fork"
|
|
111
|
+
|
|
112
|
+
@classproperty
|
|
113
|
+
def repository_pin(cls) -> re.Pattern[str]:
|
|
114
|
+
"""
|
|
115
|
+
A condition that runs a job in one named repository only, which a fork never is.
|
|
116
|
+
"""
|
|
117
|
+
return re.compile(r"^github\.repository == '[^']+'(?: && .*)?$")
|
|
118
|
+
|
|
119
|
+
def skips_forks(self, job: Job) -> bool:
|
|
120
|
+
"""
|
|
121
|
+
:param job: A first job of a workflow answering ``push``.
|
|
122
|
+
:return: Whether its condition skips a push to a fork: it carries
|
|
123
|
+
:attr:`fork_push_condition`, or it is :attr:`repository_pin` with no
|
|
124
|
+
alternative that could run it anyway.
|
|
125
|
+
"""
|
|
126
|
+
if self.fork_push_condition in job.condition:
|
|
127
|
+
return True
|
|
128
|
+
return bool(self.repository_pin.match(job.condition)) and (
|
|
129
|
+
"||" not in job.condition
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
@classproperty
|
|
133
|
+
def label_reference(cls) -> str:
|
|
134
|
+
"""
|
|
135
|
+
What a job answering ``labeled`` compares to run only for the labels it is about.
|
|
136
|
+
"""
|
|
137
|
+
return "github.event.label.name"
|
|
138
|
+
|
|
139
|
+
def differences_from(self, other: WorkflowLimits) -> dict[str, Any]:
|
|
140
|
+
"""
|
|
141
|
+
:param other: The limits compared against.
|
|
142
|
+
:return: The limits whose value here differs from the other's, keyed by field
|
|
143
|
+
name.
|
|
144
|
+
"""
|
|
145
|
+
own, others = dataclasses.asdict(self), dataclasses.asdict(other)
|
|
146
|
+
return {name: value for name, value in own.items() if others[name] != value}
|
|
147
|
+
|
|
148
|
+
def fitting(self, workflow: Workflow) -> WorkflowLimits:
|
|
149
|
+
"""
|
|
150
|
+
:param workflow: A workflow.
|
|
151
|
+
:return: These limits, raised just as far as the workflow needs to keep to them
|
|
152
|
+
where a limit can be raised.
|
|
153
|
+
"""
|
|
154
|
+
timeouts = [job.timeout_minutes for job in workflow.jobs if job.timeout_minutes]
|
|
155
|
+
jobs = workflow.jobs_per_run if workflow.runs_on_every_push else None
|
|
156
|
+
return dataclasses.replace(
|
|
157
|
+
self,
|
|
158
|
+
job_timeout_minutes=max([self.job_timeout_minutes, *timeouts]),
|
|
159
|
+
jobs_per_push_run=max(self.jobs_per_push_run, jobs or 0),
|
|
160
|
+
skips_push_on_fork=self.skips_push_on_fork
|
|
161
|
+
and not self._unguarded_fork_pushes(workflow),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
def violations_of(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
165
|
+
"""
|
|
166
|
+
:param workflow: A workflow held to these limits.
|
|
167
|
+
:return: Every way it breaks them, in the order the rules are listed here.
|
|
168
|
+
"""
|
|
169
|
+
return (
|
|
170
|
+
*self._schedule_violations(workflow),
|
|
171
|
+
*self._cancellation_violations(workflow),
|
|
172
|
+
*self._timeout_violations(workflow),
|
|
173
|
+
*self._guard_violations(workflow),
|
|
174
|
+
*self._job_count_violations(workflow),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
def _schedule_violations(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
178
|
+
"""
|
|
179
|
+
:param workflow: A workflow held to these limits.
|
|
180
|
+
:return: The schedule violation, if the workflow runs on one.
|
|
181
|
+
"""
|
|
182
|
+
if TriggerEvent.SCHEDULE not in workflow.events:
|
|
183
|
+
return ()
|
|
184
|
+
return (ScheduledWorkflow(workflow=workflow.file_name),)
|
|
185
|
+
|
|
186
|
+
def _cancellation_violations(
|
|
187
|
+
self, workflow: Workflow
|
|
188
|
+
) -> tuple[BudgetViolation, ...]:
|
|
189
|
+
"""
|
|
190
|
+
:param workflow: A workflow held to these limits.
|
|
191
|
+
:return: The violation of a workflow that runs on every pull-request push
|
|
192
|
+
without cancelling the run for the commit before.
|
|
193
|
+
"""
|
|
194
|
+
if not any(
|
|
195
|
+
trigger.runs_on_every_pull_request_push for trigger in workflow.triggers
|
|
196
|
+
):
|
|
197
|
+
return ()
|
|
198
|
+
if workflow.concurrency is not None and workflow.concurrency.cancel_in_progress:
|
|
199
|
+
return ()
|
|
200
|
+
return (MissingPullRequestCancellation(workflow=workflow.file_name),)
|
|
201
|
+
|
|
202
|
+
def _timeout_violations(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
203
|
+
"""
|
|
204
|
+
:param workflow: A workflow held to these limits.
|
|
205
|
+
:return: Runner jobs without a timeout, or with one above the ceiling.
|
|
206
|
+
"""
|
|
207
|
+
runner_jobs = tuple(job for job in workflow.jobs if job.runs_on_a_runner)
|
|
208
|
+
missing = tuple(
|
|
209
|
+
MissingJobTimeout(workflow=workflow.file_name, job=job.identifier)
|
|
210
|
+
for job in runner_jobs
|
|
211
|
+
if job.timeout_minutes is None
|
|
212
|
+
)
|
|
213
|
+
over = tuple(
|
|
214
|
+
JobTimeoutOverCeiling(
|
|
215
|
+
workflow=workflow.file_name,
|
|
216
|
+
job=job.identifier,
|
|
217
|
+
timeout_minutes=job.timeout_minutes,
|
|
218
|
+
ceiling_minutes=self.job_timeout_minutes,
|
|
219
|
+
)
|
|
220
|
+
for job in runner_jobs
|
|
221
|
+
if job.timeout_minutes is not None
|
|
222
|
+
and job.timeout_minutes > self.job_timeout_minutes
|
|
223
|
+
)
|
|
224
|
+
return (*missing, *over)
|
|
225
|
+
|
|
226
|
+
def _unguarded_fork_pushes(self, workflow: Workflow) -> tuple[str, ...]:
|
|
227
|
+
"""
|
|
228
|
+
:param workflow: A workflow.
|
|
229
|
+
:return: The first jobs that run on a push to a fork, when the workflow answers
|
|
230
|
+
``push``.
|
|
231
|
+
"""
|
|
232
|
+
if TriggerEvent.PUSH not in workflow.events:
|
|
233
|
+
return ()
|
|
234
|
+
return tuple(
|
|
235
|
+
job.identifier for job in workflow.first_jobs if not self.skips_forks(job)
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
def _guard_violations(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
239
|
+
"""
|
|
240
|
+
:param workflow: A workflow held to these limits.
|
|
241
|
+
:return: First jobs missing the fork condition or a label check.
|
|
242
|
+
"""
|
|
243
|
+
unguarded_push = tuple(
|
|
244
|
+
MissingForkGuard(
|
|
245
|
+
workflow=workflow.file_name,
|
|
246
|
+
job=job,
|
|
247
|
+
condition=self.fork_push_condition,
|
|
248
|
+
)
|
|
249
|
+
for job in (
|
|
250
|
+
self._unguarded_fork_pushes(workflow) if self.skips_push_on_fork else ()
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
answers_labels = any(
|
|
254
|
+
ActivityType.LABELED in trigger.activity_types
|
|
255
|
+
for trigger in workflow.triggers
|
|
256
|
+
)
|
|
257
|
+
unguarded_label = tuple(
|
|
258
|
+
MissingLabelGuard(workflow=workflow.file_name, job=job.identifier)
|
|
259
|
+
for job in (workflow.first_jobs if answers_labels else ())
|
|
260
|
+
if self.label_reference not in job.condition
|
|
261
|
+
)
|
|
262
|
+
return (*unguarded_push, *unguarded_label)
|
|
263
|
+
|
|
264
|
+
def _job_count_violations(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
265
|
+
"""
|
|
266
|
+
:param workflow: A workflow held to these limits.
|
|
267
|
+
:return: The violation of a workflow running on every push with more jobs than
|
|
268
|
+
allowed, or with jobs that cannot be counted.
|
|
269
|
+
"""
|
|
270
|
+
if not workflow.runs_on_every_push:
|
|
271
|
+
return ()
|
|
272
|
+
jobs = workflow.jobs_per_run
|
|
273
|
+
if jobs is None:
|
|
274
|
+
return (UncountableJobs(workflow=workflow.file_name),)
|
|
275
|
+
if jobs <= self.jobs_per_push_run:
|
|
276
|
+
return ()
|
|
277
|
+
return (
|
|
278
|
+
TooManyJobsOnEveryPush(
|
|
279
|
+
workflow=workflow.file_name,
|
|
280
|
+
jobs=jobs,
|
|
281
|
+
ceiling=self.jobs_per_push_run,
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
# %% the budget file
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
@dataclass(frozen=True)
|
|
290
|
+
class ActionsBudget:
|
|
291
|
+
"""
|
|
292
|
+
A repository's budget: the limits every workflow is held to, and the workflows
|
|
293
|
+
whose own limits differ.
|
|
294
|
+
"""
|
|
295
|
+
|
|
296
|
+
defaults: WorkflowLimits = field(default_factory=WorkflowLimits)
|
|
297
|
+
"""
|
|
298
|
+
The limits of every workflow :attr:`overrides` does not name.
|
|
299
|
+
"""
|
|
300
|
+
|
|
301
|
+
overrides: Mapping[str, WorkflowLimits] = field(default_factory=dict)
|
|
302
|
+
"""
|
|
303
|
+
The limits of the workflows whose own differ from :attr:`defaults`, by file name.
|
|
304
|
+
|
|
305
|
+
.. note:: Each is the workflow's whole set of limits: a limit it leaves out is
|
|
306
|
+
:class:`WorkflowLimits`' own default, not the one in :attr:`defaults`.
|
|
307
|
+
"""
|
|
308
|
+
|
|
309
|
+
@classmethod
|
|
310
|
+
def from_file(cls, path: Path) -> ActionsBudget:
|
|
311
|
+
"""
|
|
312
|
+
:param path: A budget file.
|
|
313
|
+
:return: The budget its :attr:`BudgetDefinition.FUNCTION` returns.
|
|
314
|
+
"""
|
|
315
|
+
definitions = runpy.run_path(str(path))
|
|
316
|
+
if BudgetDefinition.FUNCTION not in definitions:
|
|
317
|
+
raise MissingBudgetFunction(path=path, function=BudgetDefinition.FUNCTION)
|
|
318
|
+
return definitions[BudgetDefinition.FUNCTION]()
|
|
319
|
+
|
|
320
|
+
@classmethod
|
|
321
|
+
def load(cls) -> ActionsBudget:
|
|
322
|
+
"""
|
|
323
|
+
:return: The repository's own budget, or basstler's defaults when the repository
|
|
324
|
+
has no budget file.
|
|
325
|
+
"""
|
|
326
|
+
path = PackageLocation.SOURCE_TREE / ProjectLocation.ACTIONS_BUDGET
|
|
327
|
+
if not path.exists():
|
|
328
|
+
return cls()
|
|
329
|
+
return cls.from_file(path)
|
|
330
|
+
|
|
331
|
+
@classmethod
|
|
332
|
+
def baseline_for(
|
|
333
|
+
cls, workflows: Iterable[Workflow], defaults: WorkflowLimits
|
|
334
|
+
) -> ActionsBudget:
|
|
335
|
+
"""
|
|
336
|
+
:param workflows: The workflows the budget is for.
|
|
337
|
+
:param defaults: The limits every workflow is held to.
|
|
338
|
+
:return: A budget naming each workflow that needs a limit raised to keep to it,
|
|
339
|
+
with that limit raised just as far as it needs.
|
|
340
|
+
"""
|
|
341
|
+
fitted = {
|
|
342
|
+
workflow.file_name: defaults.fitting(workflow) for workflow in workflows
|
|
343
|
+
}
|
|
344
|
+
return cls(
|
|
345
|
+
defaults=defaults,
|
|
346
|
+
overrides={
|
|
347
|
+
file_name: limits
|
|
348
|
+
for file_name, limits in fitted.items()
|
|
349
|
+
if limits != defaults
|
|
350
|
+
},
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
@property
|
|
354
|
+
def has_daily_ceilings(self) -> bool:
|
|
355
|
+
"""
|
|
356
|
+
Whether any workflow is held to a ceiling on its runs or jobs per day.
|
|
357
|
+
"""
|
|
358
|
+
return any(
|
|
359
|
+
limits.runs_per_day is not None or limits.jobs_per_day is not None
|
|
360
|
+
for limits in (self.defaults, *self.overrides.values())
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
def limits_of(self, file_name: str) -> WorkflowLimits:
|
|
364
|
+
"""
|
|
365
|
+
:param file_name: A workflow's file name.
|
|
366
|
+
:return: The limits it is held to.
|
|
367
|
+
"""
|
|
368
|
+
return self.overrides.get(file_name, self.defaults)
|
|
369
|
+
|
|
370
|
+
def violations_of(self, workflow: Workflow) -> tuple[BudgetViolation, ...]:
|
|
371
|
+
"""
|
|
372
|
+
:param workflow: Any workflow.
|
|
373
|
+
:return: Every way it breaks this budget.
|
|
374
|
+
"""
|
|
375
|
+
return self.limits_of(workflow.file_name).violations_of(workflow)
|
|
376
|
+
|
|
377
|
+
def overrides_without_workflow(
|
|
378
|
+
self, workflows: Iterable[Workflow]
|
|
379
|
+
) -> tuple[OverrideWithoutWorkflow, ...]:
|
|
380
|
+
"""
|
|
381
|
+
:param workflows: Every workflow of the repository.
|
|
382
|
+
:return: The overrides naming a workflow file that is not among them.
|
|
383
|
+
"""
|
|
384
|
+
file_names = {workflow.file_name for workflow in workflows}
|
|
385
|
+
return tuple(
|
|
386
|
+
OverrideWithoutWorkflow(workflow=file_name)
|
|
387
|
+
for file_name in self.overrides
|
|
388
|
+
if file_name not in file_names
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
def write(self, path: Path) -> None:
|
|
392
|
+
"""
|
|
393
|
+
Write this budget as a new budget file.
|
|
394
|
+
|
|
395
|
+
:param path: Where the file goes; nothing may exist there yet.
|
|
396
|
+
"""
|
|
397
|
+
if path.exists():
|
|
398
|
+
raise BudgetFileExists(path=path)
|
|
399
|
+
template = create_template_environment().get_template(BudgetTemplate.FILE.value)
|
|
400
|
+
basstler_defaults = WorkflowLimits()
|
|
401
|
+
TextFile(path).write(
|
|
402
|
+
template.render(
|
|
403
|
+
function=BudgetDefinition.FUNCTION,
|
|
404
|
+
defaults=self.defaults.differences_from(basstler_defaults),
|
|
405
|
+
overrides={
|
|
406
|
+
file_name: limits.differences_from(basstler_defaults)
|
|
407
|
+
for file_name, limits in sorted(self.overrides.items())
|
|
408
|
+
},
|
|
409
|
+
)
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
# %% writing the repository's budget
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def main() -> None:
|
|
417
|
+
"""
|
|
418
|
+
Write the repository's budget file, raising basstler's default limits just as far as
|
|
419
|
+
each of its workflows needs today.
|
|
420
|
+
"""
|
|
421
|
+
argparse.ArgumentParser(description=main.__doc__).parse_args()
|
|
422
|
+
ActionsBudget.baseline_for(
|
|
423
|
+
Workflow.every_workflow_in_the_repository(), WorkflowLimits()
|
|
424
|
+
).write(PackageLocation.SOURCE_TREE / ProjectLocation.ACTIONS_BUDGET)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
if __name__ == "__main__":
|
|
428
|
+
main()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The names of the Actions secrets basstler's workflows read.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from enum import StrEnum
|
|
8
|
+
|
|
9
|
+
from basstler.github.repository import Repository
|
|
10
|
+
|
|
11
|
+
# %% a secret
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ActionsSecret(StrEnum):
|
|
15
|
+
"""
|
|
16
|
+
The name of an Actions secret a workflow reads; each feature declares its own as
|
|
17
|
+
members of a subclass.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def path_on(self, repository: Repository) -> str:
|
|
21
|
+
"""
|
|
22
|
+
:param repository: The repository that stores it.
|
|
23
|
+
:return: :meth:`Repository.actions_secret_path` of this secret there.
|
|
24
|
+
"""
|
|
25
|
+
return repository.actions_secret_path(self)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A repository's Actions settings: whether Actions run, whether one workflow runs, and
|
|
3
|
+
whether one secret is stored - each read, and where GitHub allows it, written.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
from typing import Annotated, Any
|
|
11
|
+
|
|
12
|
+
from pydantic import Field, TypeAdapter
|
|
13
|
+
|
|
14
|
+
from basstler.class_property import classproperty
|
|
15
|
+
from basstler.github.workflows import RepositoryWorkflow
|
|
16
|
+
from basstler.github.actions_secret import ActionsSecret
|
|
17
|
+
from basstler.github.client import HttpMethod
|
|
18
|
+
from basstler.github.repository_resources import RepositoryRead, SettingWrite
|
|
19
|
+
from basstler.github.user_steps import AllowActions, EnableWorkflow, UserStep
|
|
20
|
+
from basstler.json_model import ValidatedJSONModel
|
|
21
|
+
|
|
22
|
+
# %% whether Actions run
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ActionsPermissions(ValidatedJSONModel):
|
|
26
|
+
"""
|
|
27
|
+
Whether a repository runs Actions at all.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
enabled: bool
|
|
31
|
+
"""
|
|
32
|
+
Whether Actions may run in the repository.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class ActionsPermissionsRead(RepositoryRead[ActionsPermissions]):
|
|
38
|
+
"""
|
|
39
|
+
Reads whether a repository runs Actions.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def path(self) -> str:
|
|
44
|
+
return self.repository.actions_permissions_path
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ActionsEnabling(SettingWrite[ActionsPermissions]):
|
|
48
|
+
"""
|
|
49
|
+
Lets a repository run Actions.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
enabled: bool = True
|
|
53
|
+
"""
|
|
54
|
+
Whether Actions may run; always on.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
@classproperty
|
|
58
|
+
def method(cls) -> HttpMethod:
|
|
59
|
+
return HttpMethod.PUT
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def path(self) -> str:
|
|
63
|
+
return self.repository.actions_permissions_path
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def manual_step(self) -> UserStep:
|
|
67
|
+
return AllowActions(self.repository, known_off=True)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# %% whether one workflow runs
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class WorkflowState(StrEnum):
|
|
74
|
+
"""
|
|
75
|
+
The states GitHub reports a workflow in.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
ACTIVE = "active"
|
|
79
|
+
"""
|
|
80
|
+
It runs when started.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class WorkflowDetails(ValidatedJSONModel):
|
|
85
|
+
"""
|
|
86
|
+
One workflow of a repository, as its REST resource describes it.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
state: str
|
|
90
|
+
"""
|
|
91
|
+
Whether it runs, :attr:`WorkflowState.ACTIVE`, or why not; a fork's workflows start
|
|
92
|
+
out disabled.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True)
|
|
97
|
+
class WorkflowRead(RepositoryWorkflow, RepositoryRead[WorkflowDetails]):
|
|
98
|
+
"""
|
|
99
|
+
Reads one workflow of a repository.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def path(self) -> str:
|
|
104
|
+
return self.repository.workflow_resource_path(self.workflow_path)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class WorkflowEnabling(RepositoryWorkflow, SettingWrite[WorkflowDetails]):
|
|
108
|
+
"""
|
|
109
|
+
Enables one workflow of a repository.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
@classproperty
|
|
113
|
+
def method(cls) -> HttpMethod:
|
|
114
|
+
return HttpMethod.PUT
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def path(self) -> str:
|
|
118
|
+
return f"{self.repository.workflow_resource_path(self.workflow_path)}/enable"
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def manual_step(self) -> UserStep:
|
|
122
|
+
return EnableWorkflow(self.repository, self.workflow_path)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# %% whether one secret is stored
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class StoredSecretMetadata[Secret: ActionsSecret](ValidatedJSONModel):
|
|
129
|
+
"""
|
|
130
|
+
One Actions secret a repository stores, as GitHub describes it without its value.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
secret: Annotated[Secret, Field(alias="name")]
|
|
134
|
+
"""
|
|
135
|
+
The secret, which GitHub names it by.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@dataclass(frozen=True)
|
|
140
|
+
class ActionsSecretRead[Secret: ActionsSecret](
|
|
141
|
+
RepositoryRead[StoredSecretMetadata[Secret]]
|
|
142
|
+
):
|
|
143
|
+
"""
|
|
144
|
+
Reads whether a repository stores one Actions secret; GitHub never serves its value.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
secret: Secret
|
|
148
|
+
"""
|
|
149
|
+
The secret.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def path(self) -> str:
|
|
154
|
+
return self.secret.path_on(self.repository)
|
|
155
|
+
|
|
156
|
+
def parse(self, body: Any) -> StoredSecretMetadata[Secret]:
|
|
157
|
+
"""
|
|
158
|
+
:meth:`RepositoryRead.parse`, into the metadata of :attr:`secret`'s own kind.
|
|
159
|
+
"""
|
|
160
|
+
return TypeAdapter(StoredSecretMetadata[type(self.secret)]).validate_python(
|
|
161
|
+
body
|
|
162
|
+
)
|