The U.S. government narrowly avoided a shutdown as both the House and Senate approved a funding bill in the early hours of Saturday.