Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve exit status of nix develop #23

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ jobs:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- uses: ./
- name: Make the nix command fail
uses: ./
with:
arguments: --a-bad-flag
id: should-fail
continue-on-error: true
- name: Fail if the action succeeded when the nix command failed
if: steps.should-fail.outcome == 'success'
run: exit 1
check:
strategy:
matrix:
Expand Down
14 changes: 11 additions & 3 deletions nix-develop-gha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ contains() {

envOutput=

# Iterate over the output of `env -0` in the shell environment
while IFS='=' read -r -d '' n v; do
# Iterate over the output of `env -0`
# On the last loop, exit with the last value read, which will be the exit
# status of `nix develop`.
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
Expand Down Expand Up @@ -68,4 +70,10 @@ 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 # Even if the next line fails, run the line after that
# Run env -0 in the shell environment, prefixed with an extra
# delimiter to fence off output from the shellHook.
nix develop "${arguments[@]}" --command bash -c "echo -ne '\0'; env -0"
printf '%s' "$?" # Print the exit status of the previous line. This will always be the last value of the while loop
)
Loading