From 1bd9aadd43af16a2a95bc913067ee7b9c3ff15e8 Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Mon, 11 Nov 2024 20:11:24 -0800 Subject: [PATCH] Preserve exit status of nix develop --- .github/workflows/ci.yml | 7 +++++++ nix-develop-gha.sh | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25aafba..da5adb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,13 @@ jobs: - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v30 - uses: ./ + - name: Make the nix command fail + uses: ./ --bad-arg + id: should-fail + continue-on-error: true + - name: Fail if the action succeeded when it should have failed + if: steps.should-fail.outcome == success() + run: exit 1 check: strategy: matrix: diff --git a/nix-develop-gha.sh b/nix-develop-gha.sh index eaaea0a..6718ed6 100755 --- a/nix-develop-gha.sh +++ b/nix-develop-gha.sh @@ -12,7 +12,8 @@ contains() { envOutput= # Iterate over the output of `env -0` in the shell environment -while IFS='=' read -r -d '' n v; do +while IFS='=' read -r -d '' n v || exit "$n" +do # If this variable is empty then we're in the first loop, and $n is the # output of the shellHook _before_ `env` is run. if ! [ "$envOutput" ]; then @@ -68,4 +69,4 @@ while IFS='=' read -r -d '' n v; do fi # Add all environment variables except for PATH to GITHUB_ENV. printf "%s=%s\n" "$n" "$v" >>"${GITHUB_ENV:-/dev/stderr}" -done < <(nix develop "${arguments[@]}" --command bash -c "echo -ne '\0'; env -0") +done < <(set +e; nix develop "${arguments[@]}" --command bash -c "echo -ne '\0'; env -0"; printf "$?")