Forget about giving away your position by racking a shotgun; you give your position away getting out of bed. Try this experiment:
On a quiet night with all of your stuff in the house turned off (including lights), have someone in your bedroom simulate the sounds of waking up in the middle of the night and getting ready to defend themselves while you are in a different part of the house. You may be surprised by how much noise is made.
Bingo. My floors are so creaky, you know from the other side of the apartment when someone is moving around.
Has this actually ever happened to any of you?
Somewhat. Someone broke into my house one night. I was downstairs, they broke in to the upstairs from the back porch. I grabbed a Model 12, racked it, then started yelling. They got the message, and left. Quickly. I never even saw them, because by the time I got upstairs they were gone. (and yes, I know someone actually broke in because there were fresh footprints in the newly fallen snow outside).
I don't know if it was the yelling, or the sound of the shotgun, or both that got their attention. But either way, it worked.
I am not very eager to take a life. I don't want to spend the time explaining myself to the police, or having to clean up 5 liters of possibly contaminated blood, or with the emotional trauma that sometimes comes after having to kill another human being.
So I'm going to do everything in my power to get an intruder to leave before I have to shoot them. That includes alerting them to the fact that if they continue to persist, 9 pellets of 00 buck will be heading their way and looking to get acquainted with their chest cavity, and the fastest way to tell them that is to rack a shotgun slide, followed by "Get out of my house" and whatever expletives seem appropriate.
Yes, this poses a risk. It alerts them to my presence, and if they are bound and determined to kill me, it negates any tactical surprise I may have had. But to me that risk IS worth it, to not have to deal with the mess involved with shooting another person.
Statistically, the vast majority of firearm-related self defense situations end up with nary a round being exchanged on either side, so there is good evidence that this tactic (trying to scare the intruder away) does work.
If they flee after that demonstration, so much the better. This is the preferred outcome of ANY self defense situation.
If they continue their antics, they get shot. This is not a preferred outcome, but its better than me being dead.