From the question
The problem is that recently Google is requiring to publish forms before using them. I tried to look for some function to use it in GAS but I do not find any. Can anyone tell me a way to publish forms in a script, so I do not have to do it manually?
You are referring to the change announced in Adding granular control options for who can respond to Google Forms.
This announcement does not mention an update or change to the Google Apps Script, and the Google Apps Script release notes do not say anything new related to Google Forms.