Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Last active June 24, 2021 06:24
Show Gist options
  • Save Jimbly/f3c37d4be5a9e9d103cfb3633b328324 to your computer and use it in GitHub Desktop.
Save Jimbly/f3c37d4be5a9e9d103cfb3633b328324 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
@bbb93ef26e3c101ff11cdd21cab08a94

ok

@bbb93ef26e3c101ff11cdd21cab08a94

very cool

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