Thank you so much @rouble for sharing your solution - saved my ass man, I've been fighting with this in a GitHub Workflow for more than a day.
For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:
echo "before"
grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi
echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"
echo "after"