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
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A workflow file, read into the triggers, concurrency and jobs it declares.
|
|
3
|
+
|
|
4
|
+
YAML 1.1 reads a bare ``on`` key as the boolean true, so the trigger block is looked up
|
|
5
|
+
under both; everything else is read under the key GitHub documents.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from enum import StrEnum
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Annotated, Any
|
|
16
|
+
|
|
17
|
+
import yaml
|
|
18
|
+
from pydantic import Field
|
|
19
|
+
|
|
20
|
+
from basstler.class_property import classproperty
|
|
21
|
+
from basstler.locations import PackageLocation, ProjectLocation
|
|
22
|
+
from basstler.text_file import TextFile
|
|
23
|
+
|
|
24
|
+
# %% vocabulary
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TriggerEvent(StrEnum):
|
|
28
|
+
"""
|
|
29
|
+
The events a workflow in this repository answers to, as its trigger block names them.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
PUSH = "push"
|
|
33
|
+
"""
|
|
34
|
+
A push to a branch.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
PULL_REQUEST = "pull_request"
|
|
38
|
+
"""
|
|
39
|
+
A pull request event, whose activity types say which.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
PULL_REQUEST_TARGET = "pull_request_target"
|
|
43
|
+
"""
|
|
44
|
+
A pull request event run in the base repository's context, with its secrets, even
|
|
45
|
+
for a pull request from a fork; its activity types say which.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
WORKFLOW_DISPATCH = "workflow_dispatch"
|
|
49
|
+
"""
|
|
50
|
+
Started by hand or through the API.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
WORKFLOW_CALL = "workflow_call"
|
|
54
|
+
"""
|
|
55
|
+
Run as a job of another workflow, which is what makes a workflow reusable.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
WORKFLOW_RUN = "workflow_run"
|
|
59
|
+
"""
|
|
60
|
+
Another workflow's run reaching the activity types named.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
SCHEDULE = "schedule"
|
|
64
|
+
"""
|
|
65
|
+
A cron entry. Read so that a workflow carrying one can be reported; never declared.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class ActivityType(StrEnum):
|
|
70
|
+
"""
|
|
71
|
+
The activity types a trigger in this repository narrows its event to.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
OPENED = "opened"
|
|
75
|
+
"""
|
|
76
|
+
A pull request was opened.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
REOPENED = "reopened"
|
|
80
|
+
"""
|
|
81
|
+
A closed pull request was reopened.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
SYNCHRONIZE = "synchronize"
|
|
85
|
+
"""
|
|
86
|
+
A pull request's head branch was pushed to.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
READY_FOR_REVIEW = "ready_for_review"
|
|
90
|
+
"""
|
|
91
|
+
A draft pull request was marked ready for review.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
CONVERTED_TO_DRAFT = "converted_to_draft"
|
|
95
|
+
"""
|
|
96
|
+
A pull request was converted back to a draft.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
LABELED = "labeled"
|
|
100
|
+
"""
|
|
101
|
+
A label was added to a pull request.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
CLOSED = "closed"
|
|
105
|
+
"""
|
|
106
|
+
A pull request was closed, merged or not.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
COMPLETED = "completed"
|
|
110
|
+
"""
|
|
111
|
+
A watched workflow's run finished.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
@classproperty
|
|
115
|
+
def pull_request_defaults(cls) -> frozenset[ActivityType]:
|
|
116
|
+
"""
|
|
117
|
+
What GitHub runs a ``pull_request`` workflow on when the trigger names no types.
|
|
118
|
+
"""
|
|
119
|
+
return frozenset({cls.OPENED, cls.SYNCHRONIZE, cls.REOPENED})
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class WorkflowKey(StrEnum):
|
|
123
|
+
"""
|
|
124
|
+
The keys of a workflow file this module reads.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
TRIGGERS = "on"
|
|
128
|
+
"""
|
|
129
|
+
The trigger block, which YAML 1.1 reads under the boolean true instead.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
TYPES = "types"
|
|
133
|
+
"""
|
|
134
|
+
A trigger's activity types.
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
BRANCHES = "branches"
|
|
138
|
+
"""
|
|
139
|
+
A trigger's branch filters.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
PATHS = "paths"
|
|
143
|
+
"""
|
|
144
|
+
A trigger's path filters.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
CONCURRENCY = "concurrency"
|
|
148
|
+
"""
|
|
149
|
+
The workflow's concurrency, a bare group or a mapping.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
GROUP = "group"
|
|
153
|
+
"""
|
|
154
|
+
A concurrency mapping's group.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
CANCEL_IN_PROGRESS = "cancel-in-progress"
|
|
158
|
+
"""
|
|
159
|
+
Whether a new run in the group cancels the one in progress.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
JOBS = "jobs"
|
|
163
|
+
"""
|
|
164
|
+
The workflow's jobs, by key.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
RUNS_ON = "runs-on"
|
|
168
|
+
"""
|
|
169
|
+
The runner a job takes, absent on a job calling a reusable workflow.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
TIMEOUT_MINUTES = "timeout-minutes"
|
|
173
|
+
"""
|
|
174
|
+
How long a job may run.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
NEEDS = "needs"
|
|
178
|
+
"""
|
|
179
|
+
The jobs a job waits for.
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
CONDITION = "if"
|
|
183
|
+
"""
|
|
184
|
+
A job's condition.
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
USES = "uses"
|
|
188
|
+
"""
|
|
189
|
+
The reusable workflow a job calls.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
STRATEGY = "strategy"
|
|
193
|
+
"""
|
|
194
|
+
A job's strategy, which holds its matrix.
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
MATRIX = "matrix"
|
|
198
|
+
"""
|
|
199
|
+
A job's matrix: its axes, and the combinations included and excluded.
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
INCLUDE = "include"
|
|
203
|
+
"""
|
|
204
|
+
The combinations a matrix adds.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
EXCLUDE = "exclude"
|
|
208
|
+
"""
|
|
209
|
+
The combinations a matrix removes.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# %% a workflow of a repository
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@dataclass(frozen=True)
|
|
217
|
+
class RepositoryWorkflow:
|
|
218
|
+
"""
|
|
219
|
+
Names one workflow of a repository by its file.
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
workflow_path: Annotated[Path, Field(exclude=True)]
|
|
223
|
+
"""
|
|
224
|
+
The workflow's file in the repository.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# %% what a workflow declares
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@dataclass(frozen=True)
|
|
232
|
+
class Trigger:
|
|
233
|
+
"""
|
|
234
|
+
One event a workflow answers to, narrowed by its filters.
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
event: TriggerEvent
|
|
238
|
+
"""
|
|
239
|
+
The event.
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
activity_types: frozenset[ActivityType] = frozenset()
|
|
243
|
+
"""
|
|
244
|
+
The activity types named, or empty when the trigger names none.
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
branches: frozenset[str] = frozenset()
|
|
248
|
+
"""
|
|
249
|
+
The branch filters named, or empty when the trigger names none.
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
paths: frozenset[str] = frozenset()
|
|
253
|
+
"""
|
|
254
|
+
The path filters a change has to match for the trigger to fire, or empty when the
|
|
255
|
+
trigger names none.
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def runs_on_every_pull_request_push(self) -> bool:
|
|
260
|
+
"""
|
|
261
|
+
:return: Whether this is a pull-request trigger that runs on each push to the pull
|
|
262
|
+
request, which is when a newer run makes an older one worthless.
|
|
263
|
+
"""
|
|
264
|
+
if self.event not in (
|
|
265
|
+
TriggerEvent.PULL_REQUEST,
|
|
266
|
+
TriggerEvent.PULL_REQUEST_TARGET,
|
|
267
|
+
):
|
|
268
|
+
return False
|
|
269
|
+
activity_types = self.activity_types or ActivityType.pull_request_defaults
|
|
270
|
+
return ActivityType.SYNCHRONIZE in activity_types
|
|
271
|
+
|
|
272
|
+
@property
|
|
273
|
+
def runs_on_every_push(self) -> bool:
|
|
274
|
+
"""
|
|
275
|
+
:return: Whether the trigger runs on each push to a pull request, or on pushes to
|
|
276
|
+
any branch rather than to named ones.
|
|
277
|
+
"""
|
|
278
|
+
if self.runs_on_every_pull_request_push:
|
|
279
|
+
return True
|
|
280
|
+
if self.event is not TriggerEvent.PUSH:
|
|
281
|
+
return False
|
|
282
|
+
return not self.branches or any("*" in branch for branch in self.branches)
|
|
283
|
+
|
|
284
|
+
@classmethod
|
|
285
|
+
def from_workflow(cls, event: str, filters: Any) -> Trigger:
|
|
286
|
+
"""
|
|
287
|
+
:param event: The event's key in the trigger block.
|
|
288
|
+
:param filters: What the key holds: a mapping of filters, nothing for an
|
|
289
|
+
unfiltered trigger, or a schedule's list of cron entries.
|
|
290
|
+
:return: The trigger.
|
|
291
|
+
"""
|
|
292
|
+
if not isinstance(filters, Mapping):
|
|
293
|
+
filters = {}
|
|
294
|
+
return cls(
|
|
295
|
+
event=TriggerEvent(event),
|
|
296
|
+
activity_types=frozenset(
|
|
297
|
+
ActivityType(activity_type)
|
|
298
|
+
for activity_type in filters.get(WorkflowKey.TYPES, ())
|
|
299
|
+
),
|
|
300
|
+
branches=frozenset(filters.get(WorkflowKey.BRANCHES, ())),
|
|
301
|
+
paths=frozenset(filters.get(WorkflowKey.PATHS, ())),
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
@dataclass(frozen=True)
|
|
306
|
+
class Concurrency:
|
|
307
|
+
"""
|
|
308
|
+
The group a workflow's runs queue in, and whether a new run cancels the one before.
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
group: str
|
|
312
|
+
"""
|
|
313
|
+
The group expression, as written.
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
cancel_in_progress: bool
|
|
317
|
+
"""
|
|
318
|
+
Whether a new run in the group cancels the one in progress.
|
|
319
|
+
"""
|
|
320
|
+
|
|
321
|
+
@classmethod
|
|
322
|
+
def from_workflow(cls, declared: str | Mapping[str, Any]) -> Concurrency:
|
|
323
|
+
"""
|
|
324
|
+
:param declared: The ``concurrency`` value, either a bare group or a mapping.
|
|
325
|
+
:return: The concurrency.
|
|
326
|
+
"""
|
|
327
|
+
if isinstance(declared, str):
|
|
328
|
+
return cls(group=declared, cancel_in_progress=False)
|
|
329
|
+
return cls(
|
|
330
|
+
group=declared[WorkflowKey.GROUP],
|
|
331
|
+
cancel_in_progress=declared.get(WorkflowKey.CANCEL_IN_PROGRESS, False),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
@dataclass(frozen=True)
|
|
336
|
+
class Job:
|
|
337
|
+
"""
|
|
338
|
+
One job of a workflow, as far as the budget is concerned.
|
|
339
|
+
"""
|
|
340
|
+
|
|
341
|
+
identifier: str
|
|
342
|
+
"""
|
|
343
|
+
The job's key under ``jobs``.
|
|
344
|
+
"""
|
|
345
|
+
|
|
346
|
+
runs_on_a_runner: bool
|
|
347
|
+
"""
|
|
348
|
+
Whether the job takes a runner itself, rather than calling a reusable workflow whose
|
|
349
|
+
own jobs do.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
timeout_minutes: int | None
|
|
353
|
+
"""
|
|
354
|
+
The job's ``timeout-minutes``, or none when it declares none.
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
needs: tuple[str, ...]
|
|
358
|
+
"""
|
|
359
|
+
The jobs this one waits for.
|
|
360
|
+
"""
|
|
361
|
+
|
|
362
|
+
condition: str
|
|
363
|
+
"""
|
|
364
|
+
The job's ``if`` condition, or empty when it has none.
|
|
365
|
+
"""
|
|
366
|
+
|
|
367
|
+
instances: int | None
|
|
368
|
+
"""
|
|
369
|
+
How many times at most one run of the workflow runs the job, once per matrix
|
|
370
|
+
combination, or none when the matrix is computed at run time.
|
|
371
|
+
"""
|
|
372
|
+
|
|
373
|
+
reusable_workflow: str | None
|
|
374
|
+
"""
|
|
375
|
+
The reusable workflow the job calls, as the job names it, or none for a job that
|
|
376
|
+
takes a runner itself.
|
|
377
|
+
"""
|
|
378
|
+
|
|
379
|
+
@classmethod
|
|
380
|
+
def from_workflow(cls, identifier: str, declared: Mapping[str, Any]) -> Job:
|
|
381
|
+
"""
|
|
382
|
+
:param identifier: The job's key.
|
|
383
|
+
:param declared: The job's mapping.
|
|
384
|
+
:return: The job.
|
|
385
|
+
"""
|
|
386
|
+
needs = declared.get(WorkflowKey.NEEDS, ())
|
|
387
|
+
strategy = declared.get(WorkflowKey.STRATEGY, {})
|
|
388
|
+
return cls(
|
|
389
|
+
identifier=identifier,
|
|
390
|
+
runs_on_a_runner=WorkflowKey.RUNS_ON in declared,
|
|
391
|
+
timeout_minutes=declared.get(WorkflowKey.TIMEOUT_MINUTES),
|
|
392
|
+
needs=(needs,) if isinstance(needs, str) else tuple(needs),
|
|
393
|
+
condition=str(declared.get(WorkflowKey.CONDITION, "")),
|
|
394
|
+
instances=cls.matrix_combinations(strategy.get(WorkflowKey.MATRIX)),
|
|
395
|
+
reusable_workflow=declared.get(WorkflowKey.USES),
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
@staticmethod
|
|
399
|
+
def matrix_combinations(matrix: Any) -> int | None:
|
|
400
|
+
"""
|
|
401
|
+
:param matrix: A job's ``strategy.matrix``, or none when it has no matrix.
|
|
402
|
+
:return: The most combinations it runs: the product of its axes, less the
|
|
403
|
+
excluded and plus the included ones, or the included ones alone when it has
|
|
404
|
+
no axes. None when the matrix, an axis or a combination list is an expression
|
|
405
|
+
evaluated at run time.
|
|
406
|
+
"""
|
|
407
|
+
if matrix is None:
|
|
408
|
+
return 1
|
|
409
|
+
if not isinstance(matrix, Mapping):
|
|
410
|
+
return None
|
|
411
|
+
included = matrix.get(WorkflowKey.INCLUDE, [])
|
|
412
|
+
excluded = matrix.get(WorkflowKey.EXCLUDE, [])
|
|
413
|
+
axes = [
|
|
414
|
+
values
|
|
415
|
+
for key, values in matrix.items()
|
|
416
|
+
if key not in (WorkflowKey.INCLUDE, WorkflowKey.EXCLUDE)
|
|
417
|
+
]
|
|
418
|
+
if not all(isinstance(values, list) for values in (*axes, included, excluded)):
|
|
419
|
+
return None
|
|
420
|
+
if not axes:
|
|
421
|
+
return max(len(included), 1)
|
|
422
|
+
return math.prod(len(values) for values in axes) - len(excluded) + len(included)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@dataclass(frozen=True)
|
|
426
|
+
class Workflow:
|
|
427
|
+
"""
|
|
428
|
+
A workflow file, read into what the budget holds it to.
|
|
429
|
+
"""
|
|
430
|
+
|
|
431
|
+
path: Path
|
|
432
|
+
"""
|
|
433
|
+
The workflow file.
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
triggers: tuple[Trigger, ...]
|
|
437
|
+
"""
|
|
438
|
+
The events it answers to, in the order the file names them.
|
|
439
|
+
"""
|
|
440
|
+
|
|
441
|
+
concurrency: Concurrency | None
|
|
442
|
+
"""
|
|
443
|
+
Its concurrency, or none when it declares none.
|
|
444
|
+
"""
|
|
445
|
+
|
|
446
|
+
jobs: tuple[Job, ...]
|
|
447
|
+
"""
|
|
448
|
+
Its jobs, in the order the file names them.
|
|
449
|
+
"""
|
|
450
|
+
|
|
451
|
+
@classmethod
|
|
452
|
+
def at(cls, path: Path) -> Workflow:
|
|
453
|
+
"""
|
|
454
|
+
:param path: The workflow file.
|
|
455
|
+
:return: The workflow.
|
|
456
|
+
"""
|
|
457
|
+
declared = yaml.safe_load(TextFile(path).read())
|
|
458
|
+
# YAML 1.1 reads a bare ``on`` key as the boolean true.
|
|
459
|
+
triggers = declared.get(True, declared.get(WorkflowKey.TRIGGERS))
|
|
460
|
+
if isinstance(triggers, str):
|
|
461
|
+
triggers = [triggers]
|
|
462
|
+
if isinstance(triggers, list):
|
|
463
|
+
triggers = {event: None for event in triggers}
|
|
464
|
+
concurrency = declared.get(WorkflowKey.CONCURRENCY)
|
|
465
|
+
return cls(
|
|
466
|
+
path=path,
|
|
467
|
+
triggers=tuple(
|
|
468
|
+
Trigger.from_workflow(event, filters)
|
|
469
|
+
for event, filters in triggers.items()
|
|
470
|
+
),
|
|
471
|
+
concurrency=(
|
|
472
|
+
None if concurrency is None else Concurrency.from_workflow(concurrency)
|
|
473
|
+
),
|
|
474
|
+
jobs=tuple(
|
|
475
|
+
Job.from_workflow(identifier, job)
|
|
476
|
+
for identifier, job in declared[WorkflowKey.JOBS].items()
|
|
477
|
+
),
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
@classmethod
|
|
481
|
+
def every_workflow_in_the_repository(cls) -> tuple[Workflow, ...]:
|
|
482
|
+
"""
|
|
483
|
+
:return: Every workflow GitHub runs from this checkout, in file name order.
|
|
484
|
+
"""
|
|
485
|
+
directory = PackageLocation.SOURCE_TREE / ProjectLocation.WORKFLOWS
|
|
486
|
+
return tuple(cls.at(path) for path in sorted(directory.glob("*.yml")))
|
|
487
|
+
|
|
488
|
+
@classproperty
|
|
489
|
+
def local_reference_prefix(cls) -> str:
|
|
490
|
+
"""
|
|
491
|
+
How a job names a reusable workflow of its own repository.
|
|
492
|
+
"""
|
|
493
|
+
return f"./{ProjectLocation.WORKFLOWS.value.as_posix()}/"
|
|
494
|
+
|
|
495
|
+
@property
|
|
496
|
+
def file_name(self) -> str:
|
|
497
|
+
"""
|
|
498
|
+
:return: The file's name, which is how the budget refers to the workflow.
|
|
499
|
+
"""
|
|
500
|
+
return self.path.name
|
|
501
|
+
|
|
502
|
+
@property
|
|
503
|
+
def runs_on_every_push(self) -> bool:
|
|
504
|
+
"""
|
|
505
|
+
:return: Whether any of its triggers runs it on every push.
|
|
506
|
+
"""
|
|
507
|
+
return any(trigger.runs_on_every_push for trigger in self.triggers)
|
|
508
|
+
|
|
509
|
+
@property
|
|
510
|
+
def jobs_per_run(self) -> int | None:
|
|
511
|
+
"""
|
|
512
|
+
:return: The most jobs one run takes runners for, counting every matrix
|
|
513
|
+
combination and the jobs of each reusable workflow called, or none when a
|
|
514
|
+
matrix is computed at run time or a called workflow lives in another
|
|
515
|
+
repository.
|
|
516
|
+
"""
|
|
517
|
+
counts = tuple(self.runner_jobs_of(job) for job in self.jobs)
|
|
518
|
+
if None in counts:
|
|
519
|
+
return None
|
|
520
|
+
return sum(counts)
|
|
521
|
+
|
|
522
|
+
def runner_jobs_of(self, job: Job) -> int | None:
|
|
523
|
+
"""
|
|
524
|
+
:param job: One of this workflow's jobs.
|
|
525
|
+
:return: The jobs it takes runners for, or none when that cannot be counted.
|
|
526
|
+
"""
|
|
527
|
+
if job.instances is None:
|
|
528
|
+
return None
|
|
529
|
+
if job.reusable_workflow is None:
|
|
530
|
+
return job.instances
|
|
531
|
+
if not job.reusable_workflow.startswith(self.local_reference_prefix):
|
|
532
|
+
return None
|
|
533
|
+
called = Workflow.at(
|
|
534
|
+
self.path.parent
|
|
535
|
+
/ job.reusable_workflow.removeprefix(self.local_reference_prefix)
|
|
536
|
+
).jobs_per_run
|
|
537
|
+
if called is None:
|
|
538
|
+
return None
|
|
539
|
+
return job.instances * called
|
|
540
|
+
|
|
541
|
+
@property
|
|
542
|
+
def events(self) -> frozenset[TriggerEvent]:
|
|
543
|
+
"""
|
|
544
|
+
:return: The events this workflow answers to.
|
|
545
|
+
"""
|
|
546
|
+
return frozenset(trigger.event for trigger in self.triggers)
|
|
547
|
+
|
|
548
|
+
def trigger(self, event: TriggerEvent) -> Trigger:
|
|
549
|
+
"""
|
|
550
|
+
:param event: An event this workflow answers to.
|
|
551
|
+
:return: Its trigger for that event.
|
|
552
|
+
"""
|
|
553
|
+
return next(trigger for trigger in self.triggers if trigger.event is event)
|
|
554
|
+
|
|
555
|
+
@property
|
|
556
|
+
def first_jobs(self) -> tuple[Job, ...]:
|
|
557
|
+
"""
|
|
558
|
+
:return: The jobs that wait for no other, which are the ones a skip has to be
|
|
559
|
+
written on.
|
|
560
|
+
"""
|
|
561
|
+
return tuple(job for job in self.jobs if not job.needs)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Actions budget basstler holds every workflow in ``.github/workflows`` to. Edit this
|
|
3
|
+
file by hand from here on.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from basstler.github.actions_budget import ActionsBudget, WorkflowLimits
|
|
9
|
+
|
|
10
|
+
# %% the budget
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def {{ function }}() -> ActionsBudget:
|
|
14
|
+
"""
|
|
15
|
+
:return: This repository's Actions budget.
|
|
16
|
+
"""
|
|
17
|
+
return ActionsBudget(
|
|
18
|
+
{% if defaults %}
|
|
19
|
+
defaults=WorkflowLimits({% for name, value in defaults.items() %}{{ name }}={{ value }}{% if not loop.last %}, {% endif %}{% endfor %}),
|
|
20
|
+
{% endif %}
|
|
21
|
+
overrides={
|
|
22
|
+
{% for file_name, limits in overrides.items() %}
|
|
23
|
+
{{ file_name | tojson }}: WorkflowLimits({% for name, value in limits.items() %}{{ name }}={{ value }}{% if not loop.last %}, {% endif %}{% endfor %}),
|
|
24
|
+
{% endfor %}
|
|
25
|
+
},
|
|
26
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: basstler-github
|
|
3
|
+
Version: 4.2.0
|
|
4
|
+
Summary: The GitHub client and the models of GitHub's data, for basstler.
|
|
5
|
+
Project-URL: Source, https://github.com/KAOS-repositories/basstler
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/KAOS-repositories/basstler/issues
|
|
7
|
+
Author-email: Abdelrhman Bassiouny <bido.bassuny@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Requires-Dist: basstler-core==4.2.0
|
|
13
|
+
Requires-Dist: basstler-git==4.2.0
|
|
14
|
+
Requires-Dist: cyclopts>=5.3
|
|
15
|
+
Requires-Dist: pydantic>=2.11
|
|
16
|
+
Requires-Dist: pyyaml>=6
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
basstler/github/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
basstler/github/actions_budget.py,sha256=3xxuAKfjT1u07AkaYpmgw819bpemMlrQT1wQWdTzR2g,14815
|
|
3
|
+
basstler/github/actions_secret.py,sha256=IdcviQzF0hI5FKl88RxFewEcsILaHqDOU_WMz05CSZs,623
|
|
4
|
+
basstler/github/actions_settings.py,sha256=yvbvN_mLZKA0AucHSNleE5obzJkSjPiRef3hlw4MqBw,3904
|
|
5
|
+
basstler/github/actions_usage.py,sha256=UIxz6Rm4VJbOpNwDC83_1_Z4-Z-GEZDy9B-vKG7OZ1s,8770
|
|
6
|
+
basstler/github/basstler_project.py,sha256=PqeRb1_VJP9Y1Rko1C9dLV54jY6-fg2eYUSToFC6xJg,2182
|
|
7
|
+
basstler/github/branch_pull_request.py,sha256=ZmhqCbPWwY1hgmRsod-2G3suurVPTs1O9DmpS-2SvgM,438
|
|
8
|
+
basstler/github/client.py,sha256=jwAOdvbPNWqT4nartnxNYgwmGDzMXUtTwqdkeK7XFkc,13429
|
|
9
|
+
basstler/github/comparison.py,sha256=HcgxV_PhvUzaWZp8r8rn4DGcR4wuvQu0a-RVTvdP0uw,1239
|
|
10
|
+
basstler/github/constants.py,sha256=maHX064DK6j5tAC477dj7eZXm2ApBth1Gm-UcFxwv-M,5846
|
|
11
|
+
basstler/github/credential.py,sha256=U7BfPPpheecI7gbzG4Z6wrkzVAn8PbM34y2dAf8KWJY,1990
|
|
12
|
+
basstler/github/exceptions.py,sha256=Z0jTUlDJadr5dvJHTHuu9XCwobV9OsNiQyJm3DyCqOA,7370
|
|
13
|
+
basstler/github/file_proposal.py,sha256=DULXDgb5SPCkTN6hIuvbA9rGXHPJ3QhLRDlgl37sjcw,13692
|
|
14
|
+
basstler/github/fork_sync.py,sha256=jRkuDJ9HMgALl5jiIVqay36ZJEM1imQXBXxb1phgU1s,1269
|
|
15
|
+
basstler/github/git_objects.py,sha256=R2Z-4PumHrn9QjiKXFA0iocii5ABzjq-KzeIF0Adh_c,1233
|
|
16
|
+
basstler/github/graphql.py,sha256=-_EmXCrXSCDTQkAGcRHLXm-jAuZeBbweHdKh3uI2SAM,2283
|
|
17
|
+
basstler/github/issue.py,sha256=lqIFgySbj7mmzlpSVqaP49plZ-ZSQuqJs1wpo1LEtzk,4413
|
|
18
|
+
basstler/github/label.py,sha256=GDPhOgfPNbwo8BBKC3NDHS8YHA7PwRFdScqQivLjQio,1623
|
|
19
|
+
basstler/github/login_lending.py,sha256=Zh48YqbCvoQ01AtEWdVHjw7zqLNKsgnI0u8eZHdAUUw,1371
|
|
20
|
+
basstler/github/main_failure.py,sha256=DpibMNsVEhro_ibVXBC3VQVrnA8KdbknZ242eQ0PSsg,8693
|
|
21
|
+
basstler/github/permission_level.py,sha256=dQK7L9bcHWBCf3-8H6wG16InUKcMtKIiqb7zjmDHafk,695
|
|
22
|
+
basstler/github/pull_request.py,sha256=EbPsF3wvOCxTo4Vz5qslERYKdVevZoeWA9_gbliCBYU,1871
|
|
23
|
+
basstler/github/pull_request_changes.py,sha256=WYa1rmooktRW-EtLWQ38hXY2CbHWd8KMsN9I4O8DeyQ,3562
|
|
24
|
+
basstler/github/pull_request_description.py,sha256=fmNjzt5hvbtFTSO78lKCuNYgtqU057ZSLcrqAF5D1PI,4993
|
|
25
|
+
basstler/github/pull_request_ends.py,sha256=5kNfb4-PMnC1VnT1P9sY9Ufgn_TAfvRxl3yBTsjcTqE,1266
|
|
26
|
+
basstler/github/pull_request_form.py,sha256=aJfTBwQKYHstMh0ev7sy2_aOI_sUVnVVKq4SzTXJgbo,3882
|
|
27
|
+
basstler/github/pull_request_models.py,sha256=iKvrtPdqViUADwGDUE1gCC6uiVoJqsCg7GwkaBPw_-c,8573
|
|
28
|
+
basstler/github/pull_request_record.py,sha256=RYuIERCyGDgEH7TbzeZ3Bxo5cb-Xzx0aIHpLpzOlklc,11942
|
|
29
|
+
basstler/github/pull_request_source.py,sha256=4_Fj_eKv7DRduKi4emLZLBBhayYZyv0gnPZFDIi_JJU,15199
|
|
30
|
+
basstler/github/pull_request_state.py,sha256=OgruNai-MA0MhY56zH9uq43AQhghcbfghenN5mrUwuk,15586
|
|
31
|
+
basstler/github/query_documents.py,sha256=YoT0LZ1-qBHRhew5c-qcdupGpWlbzLKgOPfKz685d3c,865
|
|
32
|
+
basstler/github/release_version.py,sha256=5BFBJW2m3wdmKltZFE8jwDvV4caro-V_cftCCfutEiE,17454
|
|
33
|
+
basstler/github/remote.py,sha256=BJ54OB-Yd8MD-WDo7n8fgtv_P21zYW149GYv7omvXaM,1002
|
|
34
|
+
basstler/github/repository.py,sha256=_waHYsxwI2uYIKxqvgGYZgdeIG_PWsPLhwjYrGf4O8M,17393
|
|
35
|
+
basstler/github/repository_access.py,sha256=1rbSqo0PQt1BVXL8Mb1LTVVxZMSC4t3heVI08T8T3Jc,14889
|
|
36
|
+
basstler/github/repository_attachment.py,sha256=kuNIK7fq1lKqDtFAzKATBkaobwfK_dGHLmK1XI1H72A,2765
|
|
37
|
+
basstler/github/repository_details.py,sha256=XpdJwSm2QsMtO9Yb0PFJK9VKHusX4Y3eoxG1jBbEHSo,2863
|
|
38
|
+
basstler/github/repository_option.py,sha256=uZ8pCXOmqqk9VtIYZYqby788l5pkRSsZt2Nt-Davuis,1024
|
|
39
|
+
basstler/github/repository_resources.py,sha256=hPaIO4X5C0D45iAAU26H-7o5H2ZHOx3v2ILdcHujPaQ,3991
|
|
40
|
+
basstler/github/rest_models.py,sha256=_F4fKMkOMUm2s72jMFBfFaowOCgIjyChXbMY3Z1HL8Q,9203
|
|
41
|
+
basstler/github/review_models.py,sha256=9QKdxYcoeX1nnA5_8XbMdXpCoT-aHx4-dUyfFO4ANs0,5168
|
|
42
|
+
basstler/github/run_listing.py,sha256=AxOLAL40cWBmcmBSc-nbcKR-3Kmyah8V-G3MOM_MRsk,4339
|
|
43
|
+
basstler/github/stack_configuration.py,sha256=mWVIyi7fcRCVateaSqJdVy1ECg-ljETvUvURdGZrAa8,5799
|
|
44
|
+
basstler/github/states.py,sha256=BjaqDKouFT3iaPGcGUIvzw2WEmDZDje_77AEBQO_9Is,6750
|
|
45
|
+
basstler/github/token_form.py,sha256=nZY935rGdJlVvud0tBf17Nsj0J76xYkCxoDVhn-uHm8,9515
|
|
46
|
+
basstler/github/tooling_labels.py,sha256=5QnYG63L0uj_vqJhIz6--u-2tFRhuW36GNea7dGK8BY,2711
|
|
47
|
+
basstler/github/user_steps.py,sha256=7xFIzlQBugdIwsx7kOAG6qt1QR_Js939_7G8KEpdw44,4049
|
|
48
|
+
basstler/github/web_form.py,sha256=l4JdYoLxAoHO24-zNiEYjzoVz7EPaQEpVUFolQYoTd4,1394
|
|
49
|
+
basstler/github/web_page.py,sha256=L2TQO5gj3_cMggKrkUwl-_BeX-UajJxHBZQ8sxeGW0c,670
|
|
50
|
+
basstler/github/wire_form.py,sha256=cn5Ln1PHU8HlOVb-B-fncFS4MOd1ZXbwKMJlYgIGQWI,4982
|
|
51
|
+
basstler/github/workflow_run.py,sha256=rcmlHTCkrZnJ3EBB5BesGMTA8amp5ghCW6UbVOPrZkw,3000
|
|
52
|
+
basstler/github/workflows.py,sha256=4GOupYHXPwT7Y6-WvYf8fERjotxuqupwo8wsPjR6zzg,15272
|
|
53
|
+
basstler/github/queries/pull_request_for_branch.graphql,sha256=IwGT8viiIfL1KAqgZYsuzgBUCvNsqb2QjwS37rmWUAc,375
|
|
54
|
+
basstler/github/queries/review_threads_page.graphql,sha256=sEMB3d68YxTVpznHdR7re3lp8-AH_2jaOh5nNx5FwKA,1433
|
|
55
|
+
basstler/templates/actions_budget.py.jinja,sha256=1Q4UQMe_X427zavffjAzZgk6Iw2VThQl4jt6q28Ufro,818
|
|
56
|
+
basstler_github-4.2.0.dist-info/METADATA,sha256=jU7Qa403DNMZy-wybPvxHGfls1U1Q_DUPHVEVm-Lj5s,592
|
|
57
|
+
basstler_github-4.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
58
|
+
basstler_github-4.2.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
59
|
+
basstler_github-4.2.0.dist-info/licenses/NOTICE,sha256=dBp1KVYEzyxlNrbsD-iH86mHlxEPlBHlGoqx8R_GNDM,695
|
|
60
|
+
basstler_github-4.2.0.dist-info/RECORD,,
|