mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 18:20:07 +01:00
48 lines
1.4 KiB
Nix
48 lines
1.4 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
cilib = import ./. {inherit lib pkgs;};
|
|
inherit (cilib.helpers) filterJobVariables;
|
|
in {
|
|
mkJobRun = {
|
|
key,
|
|
job,
|
|
jobDeps,
|
|
}: let
|
|
variablesWithoutStorePaths = filterJobVariables false job;
|
|
variableExports = lib.concatLines (
|
|
lib.mapAttrsToList (name: value: "export ${name}=\"${value}\"") variablesWithoutStorePaths
|
|
);
|
|
sandboxHelper = pkgs.writeShellScriptBin "gitlab-ci-job-sandbox-helper" (builtins.readFile ./sandbox_helper.sh);
|
|
actualJobScript = pkgs.writeShellScript "gitlab-ci-job:${key}:raw" ''
|
|
# set up deps and environment variables containing store paths
|
|
. ${jobDeps}
|
|
# normal environment variables
|
|
${variableExports}
|
|
# run before_script, script and after_script
|
|
echo -e "\e[32mRunning before_script...\e[0m"
|
|
set -x
|
|
${lib.concatLines (job.before_script or [])}
|
|
{ set +x; } 2>/dev/null
|
|
echo -e "\e[32mRunning script...\e[0m"
|
|
set -x
|
|
${lib.concatLines job.script}
|
|
{ set +x; } 2>/dev/null
|
|
echo -e "\e[32mRunning after_script...\e[0m"
|
|
set -x
|
|
${lib.concatLines (job.after_script or [])}
|
|
{ set +x; } 2>/dev/null
|
|
'';
|
|
in
|
|
# this way the sandbox helper just needs to be built once
|
|
pkgs.writeShellScriptBin "gitlab-ci-job:${key}" ''
|
|
exec ${lib.getExe sandboxHelper} ${actualJobScript} $@
|
|
''
|
|
// {
|
|
passthru = {
|
|
inherit jobDeps actualJobScript;
|
|
};
|
|
};
|
|
}
|