You can write a Python script to run a geoprocessing workflow and publish it as a geoprocessing service. The primary method of running a script is to use ArcPy.
Once a customized tool is run successfully, use arcpy functionality to publish it as a geoprocessing service. First, create a service definition draft file using either the GeoProcessingSharingDraft class and CreateSharingDraft, or the CreateGPSDDraft function. Then, create a service definition file using the Stage Service tool, and use the Upload Service Definition tool to complete the publishing process.
The GeoProcessingSharingDraft class and CreateSharingDraft function are only available from ArcGIS Pro 3.0 and later.