Powered by CherryPy
This scripts boots a server that can accept webhook payloads from Unity Cloud Build and handle the artifact so that:
- the latest artifacts are always at the specific paths
- the previous artifacts are archived with the timestamp at when the archive occurs.
This program was made to ensure that we don't have to download the artifacts from UCB by hand and the correct artifacts are in the correct directories, so that the same script can be used each time you update your game.
This may be achievable with Jenkins, but I just simply wanted to write this for personal educational purposes. So... whatevs.
This script is made with SteamCMD in mind, but if you are downloading the artifacts from Unity Cloud Build for uploading them to distributor using the similar tools, this script is for you.
Downloading them by hand is very prone to mistakes. Have you accidentally shipped a debug version to your regular players? Then consider using this tool.
- Python 3.8
- Best run on a pipenv environment
Optional:
- Docker
- Consider how to serve this webhook.
- This script need to be "visible" on the web.
If you have a server that can host this script, you can use that,
but if you don't, you may serve it from your PC, in which case you should set up a tunnel.
Search "webhook tunnel" for a starting idea how to do this.
- This script need to be "visible" on the web.
- Copy the .env.example file and rename it to
.env
(or copy the content of the next step.) - Set the content of the
.env
:
# keep it false unless you know what you are doing
APP_DEBUG=false
# It is your responsibility to set this random authorization key for UCB.
# Use whatever method you'd like but `openssl rand -base64 <integer>` should do.
# Surround the key between double quotes to avoid unexpected results.
# Take note of this value as you will be putting this value in the UCB settings.
# You MUST NOT leave this blank.
UCB_TOKEN="sampleAuthKeyYouGenerated"
# You can increase this, but usually you don't have that many concurrent builds running
# at once, so no need to increase this number
MAX_WORKERS=5
- Prepare the receiving server, or in this case, your PC.
- The serving port can be changed by editing
env.conf
. - If you decided to run it locally and tunnel it to the Internet:
- Docker Compose is recommended and is safer.
- It should work out of the box provided that you have followed the instruction up until this point.
- Just
docker compose up -d
to fire it up. - The serving port settings in
env.conf
should be kept as8080
in this case. 1 - The host port is also set to
8080
, so expose the8080
port 1 via the tunnel.
- Docker Compose is recommended and is safer.
- The serving port can be changed by editing
The server is ready at this point. Now head over to Unity Cloud Build dashboard and register the webhook.
- Go to your Unity Cloud Build webpage (https://dashboard.unity3d.com/)
and navigate to the "Integrations" page for your project
- Sidebar > Project > "Integrations" under "Current Project." Make sure your project is what you intended to modify.
- Press "New Integrations," then select "Webhook," and click "Next."
- For the events to receive, select "Build Success" under "Cloud Build." Click "Next."
- Choose any display name, and set webhook URL.
- If you are typing
localhost
or127.0.0.1
here, STOP as you have not fully understood how to serve this webhook receiver.
Read the previous section carefully before trying again.
- If you are typing
- For "Authorization Secret," put the auth token created.
It must match the one written in.env
minus the quotes. 2 - The "Authorization Type" dropdown should appear. Select "HMAC-SHA256 Signature."
- Content Type MUST be "application/json."
- Leave "Disable SSL/TLS Verification" off.
- if you are in a situation where you have to check this option, seriously reconsider your setup.
- Click "Save."
At this point, this script is ready to receive the webhook.
Here is the run-down of what happens on receiving the webhook:
- On successful builds, Unity Cloud Build notifies the script of them with the information of where to download the artifact.
- This script will look for the 'primary' artifact, which is most likely your game, and make the request to the URL provided in the previous step.
- The downloaded stuff will be temporarily put in the
tmp
directory. - After extracting the artifact, the script will copy it to the following directory:
./output/<Project Name>/<Target Name>
- If this directory exists, the existing one will be archived into
./output/archives
first. - If you enable IL2CPP, the artifact will contain
BackUpThisFolder_ButDontShipItWithYourGame
directory. In the case of UCB, we do not need to back it up, and it will not be copied.
- If this directory exists, the existing one will be archived into
This script does not support the "Notarization" required by Apple for macOS applications. You can set it up on UCB side.
Not implemented as of now, but very nice to have. This means e.g., to run upload tools after webhooks are received for each target in a configurable set.
Nice to have.
You can add files/directories to your artifacts (such as Addressables bundle files.)
To do this, place the files into the ./resources/accompaniment/<Project Name>
folder.
All the content will be copied to the output
folder every time an artifact is copied there.
If run directly on macOS, then the events can be logged as the notification.
Install terminal-notifier
to enable the feature.
MIT