Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F13590372
D250.1765191401.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D250.1765191401.diff
View Options
diff --git a/lilybuild/lilybuild/ci_steps.py b/lilybuild/lilybuild/ci_steps.py
--- a/lilybuild/lilybuild/ci_steps.py
+++ b/lilybuild/lilybuild/ci_steps.py
@@ -4,6 +4,7 @@
from buildbot.interfaces import IRenderable
from twisted.internet import defer
from .ci_syntax import ci_file
+from .ci_syntax import rules as ci_rules
from .helpers import rsync_rules_from_artifacts, get_job_script, normalize_image
from .phorge import SendCoverageToPhorge
import re
@@ -67,11 +68,39 @@
job_prop = self.getProperty('lilybuild_job_prop')
job = ci_file.CIJob.from_prop(job_prop)
job_index = self.getProperty('lilybuild_job_index')
+ variables = yield self.get_ci_variables(job)
- next_steps = yield self.job_to_steps(job, job_index)
-
- self.build.addStepsAfterCurrentStep(next_steps)
- return util.SUCCESS
+ should_run = True
+ if len(job.rules):
+ should_run = False
+ for r in job.rules:
+ try:
+ rule_str = r.get('if')
+ if not rule_str:
+ continue
+
+ res = ci_rules.evaluate_rule(ci_rules.parse_rule(rule_str), variables)
+ if not res:
+ continue
+ when = r.get('when', 'on_success')
+ if when == 'never':
+ should_run = False
+ else:
+ should_run = True
+ break
+ except SyntaxError:
+ self.addCompleteLog('error', f'Rule "{rule_str}" has syntax errors')
+ except:
+ pass
+
+ if should_run:
+ next_steps = self.job_to_steps(job, job_index, variables)
+
+ self.build.addStepsAfterCurrentStep(next_steps)
+ return util.SUCCESS
+ else:
+ self.addCompleteLog('info', 'Job skipped by a rule')
+ return util.SKIPPED
@defer.inlineCallbacks
def get_ci_variables(self, job):
@@ -147,10 +176,11 @@
))
return r
- @defer.inlineCallbacks
- def job_to_steps(self, job, job_index):
+ def job_to_steps(self, job, job_index, variables):
script_name = self.script_dir + '/run.sh'
- variables = yield self.get_ci_variables(job)
+
+ source_step = self.lbc.create_source_step()
+
script_step = steps.StringDownload(
get_job_script(variables, job),
name='Set up script',
@@ -170,6 +200,7 @@
dep_job_indices = self.getProperty('lilybuild_dependency_job_indices')
if dep_job_indices:
for i in dep_job_indices:
+ # The steps may not run or may not have an artifact even if it runs
download_job = steps.FileDownload(
mastersrc=util.Interpolate(
self.master_job_artifact_file_name_pattern,
@@ -181,6 +212,8 @@
workerdest=self.artifact_file_name,
workdir=self.work_root_dir,
doStepIf=on_success,
+ haltOnFailure=False,
+ flunkOnFailure=False,
)
unarchive_job = steps.ShellCommand(
@@ -195,6 +228,8 @@
}),
workdir=self.work_root_dir,
doStepIf=on_success,
+ haltOnFailure=False,
+ flunkOnFailure=False,
)
artifact_steps += [download_job, unarchive_job]
@@ -223,7 +258,7 @@
alwaysRun=True,
)
- steps_to_run = [script_step, chmod_step] + artifact_steps + [run_step, clean_script_step]
+ steps_to_run = [source_step, script_step, chmod_step] + artifact_steps + [run_step, clean_script_step]
if 'paths' in job.artifacts:
steps_to_run += self.get_upload_artifacts_jobs(
'files',
diff --git a/lilybuild/lilybuild/ci_syntax/ci_file.py b/lilybuild/lilybuild/ci_syntax/ci_file.py
--- a/lilybuild/lilybuild/ci_syntax/ci_file.py
+++ b/lilybuild/lilybuild/ci_syntax/ci_file.py
@@ -99,15 +99,18 @@
self.script = normalize_script(job_struct.get('script'))
self.after_script = normalize_script(job_struct.get('after_script'))
self.artifacts = job_struct.get('artifacts') or {}
+ self.rules = job_struct.get('rules') or []
self.dependencies = job_struct.get('dependencies')
def get_predefined_ci_variables(self):
- return {
+ vs = {
'CI': 'true',
'CI_JOB_NAME': self.name,
'CI_JOB_NAME_SLUG': ci_slugify(self.name),
'CI_JOB_STAGE': self.stage,
}
+ vs.update(self.struct_raw.get('variables', {}))
+ return vs
def has_artifacts_archive(self):
return self.artifacts and 'paths' in self.artifacts
diff --git a/lilybuild/lilybuild/config.py b/lilybuild/lilybuild/config.py
--- a/lilybuild/lilybuild/config.py
+++ b/lilybuild/lilybuild/config.py
@@ -107,7 +107,6 @@
def add_lilybuild_job_builder(self):
factory_job = util.BuildFactory()
- factory_job.addStep(self.create_source_step())
factory_job.addStep(RunCIJobStep(
lbc=self,
workdir=work_root,
diff --git a/lilybuild/lilybuild/tests/ci_syntax/ci_file_test.py b/lilybuild/lilybuild/tests/ci_syntax/ci_file_test.py
--- a/lilybuild/lilybuild/tests/ci_syntax/ci_file_test.py
+++ b/lilybuild/lilybuild/tests/ci_syntax/ci_file_test.py
@@ -176,6 +176,10 @@
'tags': ['aarch64']
})
+ def test_variables(self):
+ r = CIFile(get_res('variables'))
+ self.assertEqual(r.jobs['build-a'].get_predefined_ci_variables()['foo'], 'bar')
+
class GetJobExtendSeqTest(unittest.TestCase):
def test_no_extends(self):
all_jobs = {
diff --git a/lilybuild/lilybuild/tests/ci_syntax/res/variables.yaml b/lilybuild/lilybuild/tests/ci_syntax/res/variables.yaml
new file mode 100644
--- /dev/null
+++ b/lilybuild/lilybuild/tests/ci_syntax/res/variables.yaml
@@ -0,0 +1,15 @@
+stages:
+ - build
+
+build-a:
+ image: test
+ stage: build
+ variables:
+ foo: bar
+ before_script: ls
+ script:
+ - make
+ - make install
+ after_script:
+ - - find
+ - echo ok
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 8, 2:56 AM (4 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
703806
Default Alt Text
D250.1765191401.diff (6 KB)
Attached To
Mode
D250: Check rules when executing step
Attached
Detach File
Event Timeline
Log In to Comment