Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement exportvariable filter #288

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/bot-build.slurm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# author: Kenneth Hoste (@boegel)
# author: Thomas Roeblitz (@trz42)
# author: Sam Moors (@smoors)
#
# license: GPLv2
#
Expand All @@ -23,6 +24,14 @@
# for example, repos.cfg and configuration file bundles for repositories

echo "Starting bot-build.slurm"
EXPORT_VARS_SCRIPT=bot/export_vars.sh
if [ -f ${EXPORT_VARS_SCRIPT} ]; then
echo "${EXPORT_VARS_SCRIPT} script found in '${PWD}', so sourcing it!"
source ${EXPORT_VARS_SCRIPT}
else
echo "could not find ${EXPORT_VARS_SCRIPT} script in '${PWD}', skipping" >&2
fi
echo "$EXPORT_VARS_SCRIPT finished"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this line into the branch that actually sources the script. If the script couldn't be found, it would first echo that it wasn't found and then that it is finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #291

BOT_BUILD_SCRIPT=bot/build.sh
if [ -f ${BOT_BUILD_SCRIPT} ]; then
echo "${BOT_BUILD_SCRIPT} script found in '${PWD}', so running it!"
Expand Down
31 changes: 31 additions & 0 deletions tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
_ERROR_GIT_CLONE = "curl"
_ERROR_NONE = "none"

# other constants
EXPORT_VARS_FILE = 'export_vars.sh'

Job = namedtuple('Job', ('working_dir', 'arch_target', 'repo_id', 'slurm_opts', 'year_month', 'pr_id', 'accelerator'))

Expand Down Expand Up @@ -463,6 +465,29 @@ def apply_cvmfs_customizations(cvmfs_customizations, arch_job_dir):
# for now, only existing mappings may be customized


def prepare_export_vars_file(job_dir, exportvars):
"""
Set up EXPORT_VARS_FILE in directory <job_dir>/bot. This file will be
sourced before running the bot/build.sh script.

Args:
job_dir (string): working directory of the job
exportvars (list): strings of the form VAR=VALUE to be exported

Returns:
None (implicitly)
"""
fn = sys._getframe().f_code.co_name

content = '\n'.join(f'export {x}' for x in exportvars)
export_vars_path = os.path.join(job_dir, 'bot', EXPORT_VARS_FILE)

with open(export_vars_path, 'w') as file:
file.write(content)

log(f"{fn}(): created exported variables file {export_vars_path}")


def prepare_jobs(pr, cfg, event_info, action_filter):
"""
Prepare all jobs whose context matches the given filter. Preparation includes
Expand Down Expand Up @@ -510,6 +535,9 @@ def prepare_jobs(pr, cfg, event_info, action_filter):
log(f"{fn}(): found no accelerator requirement")
accelerator = None

# determine exportvars from action_filter argument
exportvars = action_filter.get_filter_by_component(tools_filter.FILTER_COMPONENT_EXPORT)

jobs = []
for arch, slurm_opt in arch_map.items():
arch_dir = arch.replace('/', '_')
Expand Down Expand Up @@ -564,6 +592,9 @@ def prepare_jobs(pr, cfg, event_info, action_filter):

prepare_job_cfg(job_dir, build_env_cfg, repocfg, repo_id, cpu_target, os_type, accelerator)

if exportvars:
prepare_export_vars_file(job_dir, exportvars)

# enlist jobs to proceed
job = Job(job_dir, arch, repo_id, slurm_opt, year_month, pr_id, accelerator)
jobs.append(job)
Expand Down
4 changes: 3 additions & 1 deletion tools/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
# (none yet)


# NOTE because one can use any prefix of one of the four components below to
# NOTE because one can use any prefix of one of the components below to
# define a filter, we need to make sure that no two filters share the same
# prefix OR we have to change the handling of filters.
FILTER_COMPONENT_ACCEL = 'accelerator'
FILTER_COMPONENT_ARCH = 'architecture'
FILTER_COMPONENT_EXPORT = 'exportvariable'
FILTER_COMPONENT_INST = 'instance'
FILTER_COMPONENT_JOB = 'job'
FILTER_COMPONENT_REPO = 'repository'
FILTER_COMPONENTS = [FILTER_COMPONENT_ACCEL,
FILTER_COMPONENT_ARCH,
FILTER_COMPONENT_EXPORT,
FILTER_COMPONENT_INST,
FILTER_COMPONENT_JOB,
FILTER_COMPONENT_REPO
Expand Down
Loading