chore(utils): fix before_script getting overwritten and add collapsible sections

This commit is contained in:
technofab 2024-03-17 18:26:45 +01:00
parent 93baeca411
commit f460960ce6
2 changed files with 40 additions and 37 deletions

View file

@ -71,22 +71,22 @@
setupScript = extra_setup: setupScript = extra_setup:
pkgs.writeShellScriptBin "setup_nix_ci" '' pkgs.writeShellScriptBin "setup_nix_ci" ''
echo -e "\\e[0Ksection_start:`date +%s`:nix_setup[collapsed=true]\\r\\e[0KSetting up Nix CI" echo -e "\\e[0Ksection_start:`date +%s`:nix_setup[collapsed=true]\\r\\e[0KSetting up Nix CI"
nix path-info --all > /tmp/nix-store-before nix path-info --all > /tmp/nix-store-before
${extra_setup} ${extra_setup}
export NIX_CONF=" export NIX_CONF="
extra-trusted-public-keys = $NIX_PUBLIC_KEYS \n extra-trusted-public-keys = $NIX_PUBLIC_KEYS \n
extra-trusted-substituters = $NIX_SUBSTITUTERS \n extra-trusted-substituters = $NIX_SUBSTITUTERS \n
extra-substituters = $NIX_SUBSTITUTERS \n extra-substituters = $NIX_SUBSTITUTERS \n
$NIX_EXTRA_CONF $NIX_EXTRA_CONF
" "
echo -e "\\e[0Ksection_end:`date +%s`:nix_setup\\r\\e[0K" echo -e "\\e[0Ksection_end:`date +%s`:nix_setup\\r\\e[0K"
${ ${
"" # load the job's deps only if the name was passed "" # load the job's deps only if the name was passed
} }
if [[ ! -z $1 ]]; then if [[ ! -z $1 ]]; then
echo -e "\\e[0Ksection_start:`date +%s`:nix_deps[collapsed=true]\\r\\e[0KFetching deps for job" echo -e "\\e[0Ksection_start:`date +%s`:nix_deps[collapsed=true]\\r\\e[0KFetching deps for job"
nix build .#gitlab-ci-job-deps:$1 nix build .#gitlab-ci-job-deps:$1
source $(readlink -f result) source $(readlink -f result)
echo -e "\\e[0Ksection_end:`date +%s`:nix_deps\\r\\e[0K" echo -e "\\e[0Ksection_end:`date +%s`:nix_deps\\r\\e[0K"
fi fi
''; '';

View file

@ -6,35 +6,38 @@
}: jobArgs: }: jobArgs:
jobArgs jobArgs
// { // {
before_script = [ before_script =
'' (jobArgs.before_script or [])
eval "$(ssh-agent -s)" >/dev/null;
mkdir -p ~/.ssh; touch ~/.ssh/known_hosts;
ssh-keyscan -t rsa $CI_SERVER_HOST >> ~/.ssh/known_hosts;
echo "$GIT_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - >/dev/null;
git config --global user.email "$GIT_EMAIL" >/dev/null;
git config --global user.name "$GIT_NAME" >/dev/null;
export CI_PUSH_REPO=`echo $CI_REPOSITORY_URL | sed -e "s|.*@\(.*\)|git@\1|" -e "s|/|:|"`;
git remote rm origin && git remote add origin ''${CI_PUSH_REPO}
''
];
script =
(jobArgs.script or [])
++ (
if builtins.length files == 0
then []
else [
''
git add ${builtins.concatStringsSep " " files}
''
]
)
++ [ ++ [
'' ''
git diff --cached --exit-code >/dev/null && echo -e "\\e[0Ksection_start:`date +%s`:commit_setup[collapsed=true]\\r\\e[0KSetting up commitAndPushFiles"
echo "Nothing to commit" || eval "$(ssh-agent -s)" >/dev/null;
git commit -m "${message}" --no-verify; mkdir -p ~/.ssh; touch ~/.ssh/known_hosts;
git push --tags origin ''${GIT_SOURCE_REF:-HEAD}:''${GIT_TARGET_REF:-$CI_COMMIT_REF_NAME} -o ci.skip ssh-keyscan -t rsa $CI_SERVER_HOST >> ~/.ssh/known_hosts;
echo "$GIT_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - >/dev/null;
git config --global user.email "$GIT_EMAIL" >/dev/null;
git config --global user.name "$GIT_NAME" >/dev/null;
export CI_PUSH_REPO=`echo $CI_REPOSITORY_URL | sed -e "s|.*@\(.*\)|git@\1|" -e "s|/|:|"`;
git remote rm origin && git remote add origin ''${CI_PUSH_REPO}
echo -e "\\e[0Ksection_end:`date +%s`:commit_setup\\r\\e[0K"
''
];
script = let
addScript =
if builtins.length files == 0
then ""
else "git add ${builtins.concatStringsSep " " files}";
in
(jobArgs.script or [])
++ [
''
echo -e "\\e[0Ksection_start:`date +%s`:commit[collapsed=true]\\r\\e[0KCommiting & pushing changes if necessary"
${addScript}
git diff --cached --exit-code >/dev/null &&
echo "Nothing to commit" ||
git commit -m "${message}" --no-verify;
git push --tags origin ''${GIT_SOURCE_REF:-HEAD}:''${GIT_TARGET_REF:-$CI_COMMIT_REF_NAME} -o ci.skip
echo -e "\\e[0Ksection_end:`date +%s`:commit\\r\\e[0K"
'' ''
]; ];
deps = (jobArgs.deps or []) ++ [pkgs.openssh pkgs.gitMinimal pkgs.gnused]; deps = (jobArgs.deps or []) ++ [pkgs.openssh pkgs.gitMinimal pkgs.gnused];