US President Donald Trump has signed a 1.3 trillion dollar spending measure averting a government shutdown at midnight, acting just hours after saying he was considering a veto.

Mr Trump complained that the legislation does not fully fund his plans for a border wall with Mexico and does not address some 800,000 “Dreamer” immigrants who are now protected from deportation under a programme that he has moved to eliminate.

He said he signed it in order to provide needed money for the military.

Earlier, Mr Trump cast doubt on whether he would back the massive spending bill, saying he was “considering” a veto.

Then, adding to the made-for-TV drama, he scheduled a news conference.

Telegraphing the outcome, an internal White House television feed advertised the event this way: “President Trump Participates in a Bill Signing.”

With Congress already on recess, Mr Trump had said on Twitter that he was weighing a veto.

He said that young immigrants now protected in the US under Barack Obama’s Delayed Action for Childhood Arrivals “have been totally abandoned by the Democrats (not even mentioned in Bill) and the BORDER WALL, which is desperately needed for our National Defense, is not fully funded”.

Several advisers inside and outside the White House had characterised the tweet as Mr Trump blowing off steam.

Mr Trump’s tweet had been at odds with what top members of Mr Trump’s administration and House Speaker Paul Ryan said on Thursday, and with a formal statement of administration policy, which said Mr Trump was supportive of the measure.

It came hours after the Senate passed the 1.3 trillion dollar spending package aimed at keeping the government open past midnight.

Mr Trump has been increasingly frustrated with the media coverage of the bill, as conservative politicians and other critics have railed against it on cable news and in private calls.

His tweet was cheered by the conservative House Freedom Caucus, which voted against the spending bill along with two dozen Republicans in the Senate.

Representative Mark Meadows, chairman of the freedom caucus and a friend of the president, said in a tweet that the group would “fully support” a veto, adding that Congress should pass a short-term budget resolution while Mr Trump and congressional leaders “negotiate a better deal for the forgotten men and women of America”.

Senator Bob Corker also egged Mr Trump on.

“Please do, Mr. President,” he tweeted. “I am just down the street and will bring you a pen. The spending levels without any offsets are grotesque, throwing all of our children under the bus. Totally irresponsible.”

“Make my day, Mr. President,” taunted Representative Kurt Schrader.

The Senate passage of the bill averted a third federal shutdown this year, an outcome both parties wanted to avoid.

But the budget caps-busting deal drew serious conservative opposition.

It also failed to resolve the stalemate over shielding young Dreamer immigrants from deportation after Mr Trump’s decision to end the Deferred Action for Childhood Arrivals programme last year.

While Mr Trump has repeatedly criticised Democrats over DACA, he cancelled the programme last autumn, ending the issuance of new DACA permits. A judge has forced the administration to continue issuing renewals.

The spending package includes 1.6 billion dollars for Mr Trump’s long-promised border wall with Mexico.

The money was far less than the 25 billion dollars over 10 years Mr Trump had asked for as part of a last-ditch deal that would have included providing a temporary extension of the DACA programme.