Action while post is being published

It sounds like you’re looking for the publish_post hook which (per the Codex):

Runs when a post is published, or if it is edited and its status is “published”. Action function arguments: post ID.

Alternately, there’s save_post which is

triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email.