Source code for gcip2.ci.jobs.base
1import dataclasses
2from typing import Self
3
4import injector
5
6from gcip2.ci.jobs import assets
7from gcip2.pipeline_core import JobBuilderImpl, Stage
8
9
[docs]
10class Base(JobBuilderImpl):
11 _base = None
12
[docs]
13 def apply(self: Self) -> Self:
14 self.with_stage(Stage.JOBS)
15 self.model.interruptible = True
16 return self
17
18
[docs]
19@injector.inject
20@dataclasses.dataclass
21class BaseLinux(JobBuilderImpl):
22 _base = Base
23 _scipt_linux: assets.ScriptLinux
24 _after_script_linux: assets.AfterScriptLinux
25 _before_script_linux: assets.BeforeScriptLinux
26
[docs]
27 def apply(self: Self) -> Self:
28 self.model.after_script = [
29 self._after_script_linux.script,
30 "echo Do nothing.",
31 ]
32 self.model.before_script = [self._before_script_linux.script]
33 return self
34
35
[docs]
36@injector.inject
37@dataclasses.dataclass
38class BasePython(JobBuilderImpl):
39 _base = Base
40 _scipt_linux: assets.ScriptLinux
41 _after_script_linux: assets.AfterScriptLinux
42 _before_script_linux: assets.BeforeScriptLinux
43
[docs]
44 def apply(self: Self) -> Self:
45 super().apply()
46 self.model.after_script = [
47 self._after_script_linux.script,
48 "echo Do nothing.",
49 ]
50 self.model.before_script = [self._before_script_linux.script]
51 return self.with_compose_image("base_python")
52
53
[docs]
54class BaseTask(BasePython):
55 _base = BasePython
56
[docs]
57 def apply(self: Self) -> Self:
58 super().apply()
59 self.model.after_script = [
60 self._after_script_linux.script,
61 "dothat run ci-after-script",
62 ]
63 self.model.script = [
64 self._scipt_linux.script,
65 "dothat run ${CI_JOB_NAME}",
66 ]
67 return self.with_compose_image("base_python")
68
69
[docs]
70class PreCommit(JobBuilderImpl):
71 _name = "pre-commit"
72 _base = BaseTask
73
[docs]
74 def apply(self: Self) -> Self:
75 super().apply()
76 return self.with_compose_image("base_python")