Wrap it in a function and hook it to transition_post_status
:
function wpse_18140_transition_post_status( $new, $old, $post ) {
if ( $new === 'publish' && $new !== $old ) {
// Your code here
}
}
add_action( 'transition_post_status', 'wpse_18140_transition_post_status', 10, 3 );
This will run everytime a post is published, but not when you simply update the post content.