Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Last active March 20, 2019 14:44
Show Gist options
  • Save Jimbly/470405895ca7b352f97b8fc562024bde to your computer and use it in GitHub Desktop.
Save Jimbly/470405895ca7b352f97b8fc562024bde to your computer and use it in GitHub Desktop.
Discord Build Scripts
@echo off
@REM You Discord APP ID
SET APP_ID=451234567890123456
@REM Name of your "test" branch you publish to first. "beta" is a reasonable name too
SET BRANCH_TEST=test
@REM Path to `dispatch` executable - if it's in your global path, just "dispatch" is fine.
SET DISPATCH=bin\dispatch
SETLOCAL ENABLEDELAYEDEXPANSION
pushd
@REM Ensure working directory is the script's drive and directory
for %%a in (%0) do set ROOT=%%~dpa
for %%a in (%0) do set ROOT_DRIVE=%%~da
%ROOT_DRIVE%
cd %ROOT%\
IF ERRORLEVEL 1 goto error
@REM Ensure logged in, log in if needed
%DISPATCH% branch list %APP_ID% 2>nul >nul
IF ERRORLEVEL 1 (
@echo dispatch error, probably not logged in, trying Discord login...
%DISPATCH% login
IF ERRORLEVEL 1 goto error
%DISPATCH% branch list %APP_ID% 2>nul
IF ERRORLEVEL 1 goto error
)
@REM Get Branch ID of "test" branch
SET BRANCH_ID_TEST=
for /F "delims=| tokens=2,3 skip=2" %%A in ('%DISPATCH% branch list %APP_ID% 2^>nul ') do (
SET B2=%%B
if "!B2: =!"=="%BRANCH_TEST%" (
SET BRANCH_ID_TEST=%%A
)
)
IF "%BRANCH_ID_TEST%"=="" goto error
SET BRANCH_ID_TEST=%BRANCH_ID_TEST: =%
@echo BRANCH_ID_TEST="%BRANCH_ID_TEST%"
@REM Get Branch ID of master branch
SET BRANCH_ID_MASTER=
for /F "delims=| tokens=2,3 skip=2" %%A in ('%DISPATCH% branch list %APP_ID% 2^>nul ') do (
SET B2=%%B
if "!B2: =!"=="master" (
SET BRANCH_ID_MASTER=%%A
)
)
IF "%BRANCH_ID_MASTER%"=="" goto error
SET BRANCH_ID_MASTER=%BRANCH_ID_MASTER: =%
@echo BRANCH_ID_MASTER="%BRANCH_ID_MASTER%"
@REM Uncomment this to test just publishing without pushing new builds
@REM goto justpublish
@REM Push build to test
%DISPATCH% build push %BRANCH_ID_TEST% Splody\discord_config.json .
IF ERRORLEVEL 1 goto error
@REM Push build to master
%DISPATCH% build push %BRANCH_ID_MASTER% Splody\discord_config.json .
IF ERRORLEVEL 1 goto error
:justpublish
@REM Get last build ID pushed to test branch
SET BUILD_ID=
for /F "delims=| tokens=2 skip=2" %%A in ('%DISPATCH% build list %APP_ID% %BRANCH_ID_TEST% 2^>nul ') do (
if "!BUILD_ID!"=="" (
SET BUILD_ID=%%A
)
)
IF "%BUILD_ID%"=="" goto error
SET BUILD_ID=%BUILD_ID: =%
@echo Using BUILD_ID="%BUILD_ID%"
@REM Publish build to test branch
@echo Publishing build to "%BRANCH_TEST%" branch...
%DISPATCH% build publish %APP_ID% %BRANCH_ID_TEST% %BUILD_ID%
IF ERRORLEVEL 1 goto error
@REM Test that the build has made it to the test branch
@REM Get live build ID
SET LIVE_BUILD_ID=
for /F "delims=| tokens=3,4 skip=2" %%A in ('%DISPATCH% branch list %APP_ID% 2^>nul ') do (
SET A2=%%A
if "!A2: =!"=="%BRANCH_TEST%" (
SET LIVE_BUILD_ID=%%B
)
)
SET LIVE_BUILD_ID=%LIVE_BUILD_ID: =%
@echo LIVE_BUILD_ID=%LIVE_BUILD_ID%
if "%LIVE_BUILD_ID%" == "%BUILD_ID%" (
@echo Build successfully set live on '%BRANCH_TEST%' branch
) else (
@echo Warning: Build not yet live on '%BRANCH_TEST%' branch
)
@REM Script to set live on Master
@REM Test command for patching:
@REM %DISPATCH% build update %APP_ID% %BRANCH_ID_TEST% C:\TEMP\DiscordTest --platform win32 --locale en
@echo Completed successfully.
goto done
:error
@echo Error detected (%ERRORLEVEL%), aborting
:done
popd
pause
@echo off
@REM You Discord APP ID
SET APP_ID=451234567890123456
@REM Path to `dispatch` executable - if it's in your global path, just "dispatch" is fine.
SET DISPATCH=bin\dispatch
SETLOCAL ENABLEDELAYEDEXPANSION
pushd
@REM Ensure working directory is the script's drive and directory
for %%a in (%0) do set ROOT=%%~dpa
for %%a in (%0) do set ROOT_DRIVE=%%~da
%ROOT_DRIVE%
cd %ROOT%\
IF ERRORLEVEL 1 goto error
%DISPATCH% branch list %APP_ID% 2>nul >nul
IF ERRORLEVEL 1 (
@echo dispatch error, probably not logged in, trying Discord login...
%DISPATCH% login
IF ERRORLEVEL 1 goto error
%DISPATCH% branch list %APP_ID% 2>nul
IF ERRORLEVEL 1 goto error
)
@REM Get Branch ID of master branch
SET BRANCH_ID_MASTER=
for /F "delims=| tokens=2,3 skip=2" %%A in ('%DISPATCH% branch list %APP_ID% 2^>nul ') do (
SET B2=%%B
if "!B2: =!"=="master" (
SET BRANCH_ID_MASTER=%%A
)
)
IF "%BRANCH_ID_MASTER%"=="" goto error
SET BRANCH_ID_MASTER=%BRANCH_ID_MASTER: =%
@echo BRANCH_ID_MASTER="%BRANCH_ID_MASTER%"
@REM Get build ID
SET BUILD_ID=
for /F "delims=| tokens=2 skip=2" %%A in ('%DISPATCH% build list %APP_ID% %BRANCH_ID_MASTER%') do (
if "!BUILD_ID!"=="" (
SET BUILD_ID=%%A
)
)
SET BUILD_ID=%BUILD_ID: =%
IF "%BUILD_ID%"=="" goto error
@echo Using BUILD_ID="%BUILD_ID%"
@REM Publish build to master branch
%DISPATCH% build publish %APP_ID% %BRANCH_ID_MASTER% %BUILD_ID%
IF ERRORLEVEL 1 goto error
@REM Test that the build has made it to the master branch
@REM Get live build ID
SET LIVE_BUILD_ID=
for /F "delims=| tokens=3,4 skip=2" %%A in ('%DISPATCH% branch list %APP_ID%') do (
SET A2=%%A
if "!A2: =!"=="master" (
SET LIVE_BUILD_ID=%%B
)
)
SET LIVE_BUILD_ID=%LIVE_BUILD_ID: =%
@echo LIVE_BUILD_ID=%LIVE_BUILD_ID%
if "%LIVE_BUILD_ID%" == "%BUILD_ID%" (
@echo Build successfully set live on 'master' branch
) else (
@echo Warning: Build not yet live on 'master' branch
)
@echo Completed successfully.
@goto done
:error
@echo Error detected (%ERRORLEVEL%), aborting
:done
popd
pause
@Jimbly
Copy link
Author

Jimbly commented Mar 20, 2019

Purpose

Push a build to Discord in a test branch, allow publishing later.

Unfortunately, since the way Discord does branches is a bit backwards, this is rather complicated, and requires pushing your build two entire times (hopefully it gets an identical build) to two different branches, so you can test one one branch and then promote the (hopefully identical!) build on the master branch.

Usage

Before use, follow the instructions in the Discord SDK to create one branch named "master" and one named "test". Update the first lines of these scripts with your APP_ID, the path to where you have dispatch installed, and, optionally, the name of your test branch.

RunDiscord_Upload.bat first, this will upload your build to both test and master, setting it live on only the test branch. You should then be able to download the build through Discord.

After testing, run Discord_PromoteToMaster.bat, which should be very quick, which will set the latest build live on master. Note that this blindly sets the latest build live, so if someone else pushed a build, or you pushed a second build, there's no magic way for it to know which build to set live.

Disclaimer: These scripts rely on the "human-readable" output of dispatch, which is subject to change. They do check errors thoroughly, so it should be safe (fail and notify) if something changes significantly, but more subtle changes could break things, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment