Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2016303
D220.1749485389.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D220.1749485389.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,21 +4,13 @@
from buildbot.interfaces import IRenderable
from twisted.internet import defer
from .ci_syntax import ci_file
-from .helpers import rsync_rules_from_artifacts, ci_vars_to_cmds
+from .helpers import rsync_rules_from_artifacts, get_job_script
import re
import sys
def on_success(step):
return step.build.results == util.SUCCESS
-DEFAULT_SCRIPT_HEADER = '''\
-#!/bin/sh
-
-set -e -x
-cd /build
-
-'''
-
def fill_list(*args):
return list(args)
@@ -26,7 +18,6 @@
# 200 MiB
artifact_max_size = 200 * 1024 * 1024
default_image = 'alpine'
- script_header = DEFAULT_SCRIPT_HEADER
master_job_artifact_dir_pattern = '%(kw:st)s/repos/%(prop:lilybuild_repo_id)s/builds/%(prop:lilybuild_root_build_id)s/jobs/%(kw:job)s/artifacts'
artifact_file_name = 'artifacts.tar'
master_job_artifact_file_name_pattern = master_job_artifact_dir_pattern + '/' + artifact_file_name
@@ -96,11 +87,8 @@
def job_to_steps(self, job, job_index):
script_name = self.script_dir + '/run.sh'
variables = yield self.get_ci_variables(job)
- var_cmds = ci_vars_to_cmds(variables)
script_step = steps.StringDownload(
- self.script_header +
- '\n' + var_cmds + '\n\n' +
- '\n\n'.join(job.script),
+ get_job_script(variables, job),
name='Set up script',
workerdest=script_name,
workdir=self.work_root_dir,
diff --git a/lilybuild/lilybuild/helpers.py b/lilybuild/lilybuild/helpers.py
--- a/lilybuild/lilybuild/helpers.py
+++ b/lilybuild/lilybuild/helpers.py
@@ -47,3 +47,24 @@
value = shlex.quote('{}'.format(v[name]))
res.append(f'export {name}={value}')
return '\n'.join(res)
+
+DEFAULT_SCRIPT_HEADER = '''\
+#!/bin/sh
+
+set -e -x
+cd /build
+
+'''
+
+def get_job_script(variables, job):
+ var_cmds = ci_vars_to_cmds(variables)
+
+ return (
+ DEFAULT_SCRIPT_HEADER +
+ '\n' + var_cmds + '\n\n' +
+ '\n\n'.join(job.before_script) + '\n\n' +
+ '\n\n'.join(job.script) +
+ '\n\nset +e\n\n' +
+ '\n\n'.join(job.after_script) +
+ '\n\nexit 0'
+ )
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
@@ -2,13 +2,7 @@
import unittest
import yaml
from lilybuild.ci_syntax.ci_file import CIFile, CIValidationError
-import os
-
-self_dir = os.path.dirname(__file__)
-res_dir = os.path.join(self_dir, 'res')
-def get_res(name):
- with open(os.path.join(res_dir, name + '.yaml'), 'r') as f:
- return f.read()
+from lilybuild.tests.resources import get_res
class CIFileTest(unittest.TestCase):
def test_empty(self):
diff --git a/lilybuild/lilybuild/tests/helpers_test.py b/lilybuild/lilybuild/tests/helpers_test.py
--- a/lilybuild/lilybuild/tests/helpers_test.py
+++ b/lilybuild/lilybuild/tests/helpers_test.py
@@ -1,7 +1,16 @@
import unittest
import json
-from lilybuild.helpers import rsync_rules_from_artifacts, normalize_base_url, phorge_token_to_arcrc, ci_vars_to_cmds
+from lilybuild.ci_syntax.ci_file import CIFile
+from lilybuild.helpers import (
+ rsync_rules_from_artifacts,
+ normalize_base_url,
+ phorge_token_to_arcrc,
+ ci_vars_to_cmds,
+ get_job_script,
+ DEFAULT_SCRIPT_HEADER,
+)
+from lilybuild.tests.resources import get_res
class RsyncRulesTest(unittest.TestCase):
def test_empty(self):
@@ -80,5 +89,44 @@
self.assertEqual(ci_vars_to_cmds({'VAR': 'val'}), 'export VAR=val')
self.assertEqual(ci_vars_to_cmds({'VAR': 'foo bar'}), "export VAR='foo bar'")
+class GetJobScriptTest(unittest.TestCase):
+ def test_only_script(self):
+ r = CIFile(get_res('pages_attr'))
+ job_script = get_job_script({}, r.jobs['is-pages'])
+ self.assertEqual(job_script, f'''\
+{DEFAULT_SCRIPT_HEADER}
+
+
+
+
+make docs
+
+set +e
+
+
+
+exit 0''')
+
+ def test_before_and_after(self):
+ r = CIFile(get_res('defaults'))
+ job_script = get_job_script({}, r.jobs['build-a'])
+ self.assertEqual(job_script, f'''\
+{DEFAULT_SCRIPT_HEADER}
+
+
+ls
+
+make
+
+make install
+
+set +e
+
+find
+
+echo ok
+
+exit 0''')
+
if __name__ == '__main__':
unittest.main()
diff --git a/lilybuild/lilybuild/tests/resources.py b/lilybuild/lilybuild/tests/resources.py
new file mode 100644
--- /dev/null
+++ b/lilybuild/lilybuild/tests/resources.py
@@ -0,0 +1,9 @@
+
+import os
+
+self_dir = os.path.dirname(__file__)
+res_dir = os.path.join(self_dir, 'ci_syntax', 'res')
+
+def get_res(name):
+ with open(os.path.join(res_dir, name + '.yaml'), 'r') as f:
+ return f.read()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 9, 9:09 AM (19 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
213107
Default Alt Text
D220.1749485389.diff (4 KB)
Attached To
Mode
D220: Support before_script and after_script
Attached
Detach File
Event Timeline
Log In to Comment