Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Uploading to Steam via Post Build Script

Discussion in 'Unity Cloud Build' started by alan-lawrance, Jan 3, 2021.

  1. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    299
    Would it be possible to run steamcmd to upload a build to Steam by using a Post Build Script?

    I'm curious if anyone has tried it. The roadblocks may be:

    1. Access to the Steam upload tools. Could be solved by adding to own repo and accessing in build script using relative path?

    2. Making sure the Steam upload tools work. I believe this means using the mac version, as all cloud builds run on macs.

    3. Get access to the uncompressed build for upload. I am not sure if we can do that, or if there would need to be a manual unzip. Is there some scratch directory we could use?

    So the idea is to have the Post Build script automatically upload the build to Steam. It could use environment variables for things like the steam branch name.
     
  2. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    299
    Getting closer with this. I'm able to access the uncompressed build in $WORKSPACE/.build/last/<config> from a post build script.

    I have been able to successfully launch steamcmd.sh, but it fails due to needing a steam code. steamcmd supports a "set_steam_guard_code" parameter, but I don't think is going to work with Unity Cloud Build spinning up a new virtual machine for each build.
     
  3. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,002
    I think @victorw will know more about whether it's possible but I'm not sure it would be easy, especially if you need to run custom upload tools as I doubt Unity would allow that. The only reason you can upload iOS builds is because the tools are part of xCode and are already installed.

    If it helps I used to upload to TestFlight using an external server. You can setup cloud build to notify you when a build is complete. I used that to call a script on my server that then used the cloud build API to get a list of the latest cloud builds, download the uncompress build using the data provided and upload it to TestFlight. Maybe you could do something similar for Steam?

    p.s. Here's a guide I wrote for creating a 'build bot' for Microsoft Teams. The PHP script might be handy if you take the server approach, it allows you to download all the latest cloud build info including download URLs etc... https://forum.unity.com/threads/guide-creating-a-cloud-build-bot-in-microsoft-teams.663301/
     
    Last edited: Jan 4, 2021
  4. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    299
    I have a system that uses a node app on EC2 to listen for build notifications, which then downloads the build, unzips it, and then uploads to steam. However I am looking for a zero cost solution, and this feels like it is close (I've already verified that steamcmd launches fine). The only known roadblock left is the steam guard code.

    You can upload directly to TestFlight using a Post Build Script in UCB, which was the inspiration for doing the same for Steam.
     
  5. jaydeebee

    jaydeebee

    Joined:
    Dec 9, 2020
    Posts:
    4
    Heh, I'm in the forums today to see if anyone's solved this. I think I've actually gotten further than most, though, so hopefully I can point a direction. Ultimately, at least for me, I don't think post-build scripts will work for Steam without some changes from Unity, though.

    My environment: Mac build of a Mac target.

    The Steam docs mention that, if you're using a machine that gets reimaged regularly, like a VM, then you just need to make sure to repopulate the <steam>/config/config.vdf and <steam>/config/ssfn* files. The latter is a "Sentry File" (its exact filename is given on a "SentryFile" line in config.vdf), and contains the "proof" that the machine has previously passed Steamguard.

    But there's more.

    The additional difficulties and my workarounds:

    • [edit] All of this is being orchestrated by a post-build.sh script that I put into my git tree.[/edit]
    • Steam isn't installed on the build servers (...is it?). I added the ContentBuilder directory to my git tree, at mytree.git/tools/steam/, so for instance, mytree.git/tools/steam/builder_osx/steamcmd.sh is the path to steamcmd.
    • $HOME on the build server is /BUILD_PATH, so Steam's directory would normally be at /BUILD_PATH/Library/Application Support/Steam. Unfortunately, something in that path isn't writable, so you can't put Steam's files there.
    • I worked around this by adding a stub Steam directory within a stub home directory to my git repo. In other words, drop your config.vdf at mytree.git/tools/steam/home/Library/Application Support/Steam/config/config.vdf, and when you call steamcmd, make sure to export HOME=`pwd`/tools/steam/home first. The `pwd` will substitute the current directory, which ought to be your build root.
    • My config.vdf lists its SentryFile as home/Library/Application Support/Steam/ssfn<somenumber> (that is, uses a relative pathname), and when I run steamcmd, I do so from the mytree.git/tools/steam directory. My goal was to not commit absolute pathnames, in case things moved.
    • Similar for my mytree.git/tools/steam/config/*.vdf files: relative pathnames. Overall, pathnames will be tricky, since there're lots of opportunities for things to be different here.
    • In my case, I'm trying not to commit the Sentry file (or team username/password) to git, since they're sensitive. My post-build script looks for environmental variables set in the build environment and relies on those.

    Doing all that got it to upload the build to steam! Hooray!

    ...except that post-build runs before notarization happens, so the app that it uploads to Steam isn't notarized. This unfortunately seems to be a deal-breaker. I think we need a post-notarization script to do the upload for mac targets.

    I haven't tried Windows targets at all. That was going to be Next for me.
     
  6. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    299
    Thanks for the detailed steps -- I am have been trying the same approach. I haven't got it to work quite yet for Windows (getting stopped on Steamguard), which may be due to me generating the ssfn file on Windows.

    The notarization step issue for Mac could be a show-stopper though, as if it can't work for Macs then this path is a dead-end for developers who support Mac (like me).

    Could Unity please offer some insight on whether we can get the post-build script to run after notarization?
     
unityunity