Thermal Transport in Semiconductors and Metals from First-Principles