mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-11 17:50:08 +01:00
Merge branch 'main' into testing
This commit is contained in:
commit
b309fb59db
1 changed files with 99 additions and 14 deletions
|
|
@ -17,7 +17,6 @@
|
||||||
preHook = "";
|
preHook = "";
|
||||||
allowedRequisites = null;
|
allowedRequisites = null;
|
||||||
initialPath = [pkgs.coreutils pkgs.findutils];
|
initialPath = [pkgs.coreutils pkgs.findutils];
|
||||||
shell = "/bin/bash";
|
|
||||||
extraNativeBuildInputs = [];
|
extraNativeBuildInputs = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -245,18 +244,104 @@
|
||||||
);
|
);
|
||||||
in {
|
in {
|
||||||
name = "gitlab-ci:pipeline:${pipeline_name}:job:${key}";
|
name = "gitlab-ci:pipeline:${pipeline_name}:job:${key}";
|
||||||
value = pkgs.writeShellScriptBin "gitlab-ci-job:${key}" ''
|
value = let
|
||||||
|
actualJobScript = pkgs.writeShellScript "gitlab-ci-job:${key}:raw" ''
|
||||||
# set up deps and environment variables containing store paths
|
# set up deps and environment variables containing store paths
|
||||||
. ${jobsMappedForDeps."gitlab-ci:pipeline:${pipeline_name}:job-deps:${key}"}
|
. ${jobsMappedForDeps."gitlab-ci:pipeline:${pipeline_name}:job-deps:${key}"}
|
||||||
# normal environment variables
|
# normal environment variables
|
||||||
${variableExports}
|
${variableExports}
|
||||||
# run before_script, script and after_script
|
# run before_script, script and after_script
|
||||||
echo -e "\e[32mRunning before_script...\e[0m"
|
echo -e "\e[32mRunning before_script...\e[0m"
|
||||||
|
set -x
|
||||||
${lib.concatLines (job.before_script or [])}
|
${lib.concatLines (job.before_script or [])}
|
||||||
|
{ set +x; } 2>/dev/null
|
||||||
echo -e "\e[32mRunning script...\e[0m"
|
echo -e "\e[32mRunning script...\e[0m"
|
||||||
|
set -x
|
||||||
${lib.concatLines job.script}
|
${lib.concatLines job.script}
|
||||||
|
{ set +x; } 2>/dev/null
|
||||||
echo -e "\e[32mRunning after_script...\e[0m"
|
echo -e "\e[32mRunning after_script...\e[0m"
|
||||||
|
set -x
|
||||||
${lib.concatLines (job.after_script or [])}
|
${lib.concatLines (job.after_script or [])}
|
||||||
|
{ set +x; } 2>/dev/null
|
||||||
|
'';
|
||||||
|
sandboxHelper = pkgs.writeShellScriptBin "gitlab-ci-job-sandbox-helper" ''
|
||||||
|
echo -e "\e[32mSetting up...\e[0m"
|
||||||
|
|
||||||
|
actualJobScript=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
INCLUDE_DIRTY=false
|
||||||
|
NO_SANDBOX=false
|
||||||
|
KEEP_TMP=false
|
||||||
|
KEEP_ENV=""
|
||||||
|
# parse flags
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--include-dirty)
|
||||||
|
INCLUDE_DIRTY=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-sandbox)
|
||||||
|
NO_SANDBOX=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--keep-tmp)
|
||||||
|
KEEP_TMP=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--keep-env)
|
||||||
|
KEEP_ENV="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$NO_SANDBOX" = false ]; then
|
||||||
|
echo "Running with simple sandboxing"
|
||||||
|
if [ "$KEEP_TMP" = false ]; then
|
||||||
|
trap "rm -rf '$TMPDIR'" EXIT
|
||||||
|
else
|
||||||
|
echo "Temp dir will be preserved at: $TMPDIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check if dirty
|
||||||
|
DIRTY_PATCH=""
|
||||||
|
if ! git diff --quiet && ! git diff --staged --quiet; then
|
||||||
|
echo "Warning: working tree is dirty."
|
||||||
|
DIRTY_PATCH=$(mktemp -t "nix-gitlab-ci.XXX.patch")
|
||||||
|
git diff --staged > "$DIRTY_PATCH"
|
||||||
|
trap "rm -f '$DIRTY_PATCH'" EXIT
|
||||||
|
fi
|
||||||
|
TMPDIR=$(mktemp -dt "nix-gitlab-ci.XXX")
|
||||||
|
git clone . $TMPDIR
|
||||||
|
pushd $TMPDIR >/dev/null
|
||||||
|
if [[ ! -z "$DIRTY_PATCH" && "$INCLUDE_DIRTY" = true ]]; then
|
||||||
|
echo "Copying dirty changes..."
|
||||||
|
git apply "$DIRTY_PATCH" 2>/dev/null || echo "Failed to copy dirty changes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running job in $TMPDIR"
|
||||||
|
env -i $(
|
||||||
|
if [[ -n "$KEEP_ENV" ]]; then
|
||||||
|
IFS=',' read -ra VARS <<< "$KEEP_ENV"
|
||||||
|
for var in "''${VARS[@]}"; do
|
||||||
|
printf '%s=%q ' "$var" "''${!var}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
) bash $actualJobScript
|
||||||
|
popd >/dev/null
|
||||||
|
else
|
||||||
|
exec $actualJobScript
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
# this way the sandbox helper just needs to be built once
|
||||||
|
pkgs.writeShellScriptBin "gitlab-ci-job:${key}" ''
|
||||||
|
exec ${lib.getExe sandboxHelper} ${actualJobScript} $@
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
jobs;
|
jobs;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue