I painted my engine compartment about 20 years ago. I went to a local paint store and told them what I was doing.
The key to this is prep and paint. You want to spend a lot of time making sure the surface is ready for paint. You want a really good quality primer and paint. Rattle can isn't going to cut it. It will look good for a while (mostly) but will end up uneven and easy to scratch. I got a compressor, a paint gun (low quality) and turned my garage into a 'paint booth'.
I can't give you specific instructions. I remember I cleaned the heck out of it. Sanded, steel wool, brushes and I forget what else. And the paint place sold me a final 'cleaner' to remove all residue. Prep Prep PREP.
I still remember when we went over to the ventilators. One was 20 bucks more than the others, I asked her if it was worth it, she asked me if my lungs were worth twenty bucks...
I have to say after a couple of engine pulls, lots of work, some smacking with tools it still looks good.
I know this is lacking in specifics but:
1. PREP
2. PAINT
3. LUNGS!