Least action principles with applications to gradient flows and kinetic equations