fix(sandbox_helper): fix comparisons, rename TMPDIR variable, add help

1. fixes comparisons with true for flag variables
2. renames TMPDIR to NGCI_TMPDIR so it doesn't interfere with the
   standardized TMPDIR var (and at some point accidentally deleting /tmp)
3. add small help message when invalid arg/param is passed
4. run `git add .` on copied git repo in /tmp so staged files stay
   staged there aswell
This commit is contained in:
technofab 2025-11-13 21:40:24 +01:00
parent afe1e02310
commit f5181b7b61
No known key found for this signature in database

View file

@ -28,18 +28,19 @@ while [[ $# -gt 0 ]]; do
;; ;;
*) *)
echo "Unknown option: $1" >&2 echo "Unknown option: $1" >&2
echo "use --include-dirty, --no-sandbox, --keep-tmp and --keep-env <ENV>" >&2
exit 1 exit 1
;; ;;
esac esac
done done
if [ "$NO_SANDBOX" = false ]; then if [ $NO_SANDBOX = false ]; then
echo "Running with simple sandboxing" echo "Running with simple sandboxing"
TMPDIR=$(mktemp -dt "nix-gitlab-ci.XXX") NGCI_TMPDIR=$(mktemp -dt "nix-gitlab-ci.XXX")
if [ "$KEEP_TMP" = false ]; then if [ $KEEP_TMP = false ]; then
trap "rm -rf '$TMPDIR'" EXIT trap "rm -rf '$NGCI_TMPDIR'" EXIT
else else
echo "Temp dir will be preserved at: $TMPDIR" echo "Temp dir will be preserved at: $NGCI_TMPDIR"
fi fi
# check if dirty # check if dirty
@ -50,14 +51,15 @@ if [ "$NO_SANDBOX" = false ]; then
git diff --staged > "$DIRTY_PATCH" git diff --staged > "$DIRTY_PATCH"
trap "rm -f '$DIRTY_PATCH'" EXIT trap "rm -f '$DIRTY_PATCH'" EXIT
fi fi
git clone . $TMPDIR git clone . $NGCI_TMPDIR
pushd $TMPDIR >/dev/null pushd $NGCI_TMPDIR >/dev/null
if [[ ! -z "$DIRTY_PATCH" && "$INCLUDE_DIRTY" = true ]]; then if [[ ! -z "$DIRTY_PATCH" && $INCLUDE_DIRTY = true ]]; then
echo "Copying dirty changes..." echo "Copying dirty changes..."
git apply "$DIRTY_PATCH" 2>/dev/null || echo "Failed to copy dirty changes" git apply "$DIRTY_PATCH" 2>/dev/null || echo "Failed to copy dirty changes"
git add . # required so the files are staged again
fi fi
echo "Running job in $TMPDIR" echo "Running job in $NGCI_TMPDIR"
env -i $( env -i $(
if [[ -n "$KEEP_ENV" ]]; then if [[ -n "$KEEP_ENV" ]]; then
IFS=',' read -ra VARS <<< "$KEEP_ENV" IFS=',' read -ra VARS <<< "$KEEP_ENV"