There is currently no way to publish a script using the platform APIs. (I just confirmed this with the dev team). The only mechanism to publish is through the UI. If you are interested in asking for this as a feature, I recommend you open an idea in the Ideas portal.