• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3# Copyright © 2022 Valve Corporation
4#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the "Software"),
7# to deal in the Software without restriction, including without limitation
8# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Software, and to permit persons to whom the
10# Software is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice (including the next
13# paragraph) shall be included in all copies or substantial portions of the
14# Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22# IN THE SOFTWARE.
23
24from jinja2 import Environment, FileSystemLoader
25from os import environ, path
26
27
28# Pass all the environment variables prefixed by B2C_
29values = {
30    key.removeprefix("B2C_").lower(): environ[key]
31    for key in environ if key.startswith("B2C_")
32}
33
34env = Environment(loader=FileSystemLoader(path.dirname(values['job_template'])),
35                  trim_blocks=True, lstrip_blocks=True)
36
37template = env.get_template(path.basename(values['job_template']))
38
39values['ci_job_id'] = environ['CI_JOB_ID']
40values['ci_runner_id'] = environ['CI_RUNNER_ID']
41values['job_volume_exclusions'] = [excl for excl in values['job_volume_exclusions'].split(",") if excl]
42values['working_dir'] = environ['CI_PROJECT_DIR']
43
44# Use the gateway's pull-through registry caches to reduce load on fd.o.
45values['local_container'] = environ['IMAGE_UNDER_TEST']
46values['local_container'] = values['local_container'].replace(
47    'registry.freedesktop.org',
48    '{{ fdo_proxy_registry }}'
49)
50
51if 'kernel_cmdline_extras' not in values:
52    values['kernel_cmdline_extras'] = ''
53
54with open(path.splitext(path.basename(values['job_template']))[0], "w") as f:
55    f.write(template.render(values))
56