Investigating the role of shocks, thermal instability and gravity in molecular cloud formation