Skip to content

build

build #170

Workflow file for this run

#makes a release with unity
name: make-build
on:
#schedule:
# - cron: '59 7 * * *' #runs at 11:59 pm, every day (PST -> UTC). Weekly builds EOD Monday
repository_dispatch:
types: build
permissions:
contents: write
jobs:
pull-svn:
uses: ./.github/workflows/pull-svn.yaml
secrets: inherit
permissions:
contents: write
check-project-changes:
runs-on: self-hosted
needs: pull-svn
steps:
- name: check-for-changes
id: check-for-changes
env:
SVN_DAILY_BUILD: ${{ vars.SVN_DAILY_BUILD }}
SVN_USERNAME: ${{ secrets.svn_username }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd svn-repo
Write-Host ">> Checking if unity project has been modified since last build..."
$last_build_list=($(svn ls $env:SVN_DAILY_BUILD --username $env:SVN_USERNAME --password $env:SVN_PASSWORD) -replace "[^0-9]" , "")
if ("$last_build_list" -eq "")
{
Write-Host ">> No builds recorded."
$should_build = "true"
}
else
{
$last_build = $last_build_list.Split(" ") | Select-Object -Last 1
$head = $(svn info -r HEAD --show-item revision --username $env:SVN_USERNAME --password $env:SVN_PASSWORD)
#check that HEAD revision contains changes since previous build
$should_build = "false"
if ($head -ne $last_build)
{
#check each revision for ANY changes to unity repo
Write-Host ">> Checking each revision in the range: [$last_build, $head]."
for($i = [int]"$last_build"; $i -le [int]"$head"; $i++)
{
$revision_changes = $(svn log -v -r $i --username $env:SVN_USERNAME --password $env:SVN_PASSWORD)
$change_count = ($revision_changes.Split("`n").Count - 1)
Write-Host ">> Checking revision $i."
if ( $change_count )
{
break
}
}
}
else
{
Write-Host ">> No new changes since last build."
}
}
#write to output
Write-Host "$should_build"
"output1=$should_build" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
outputs:
should-build: ${{ steps.check-for-changes.outputs.output1 }}
build:
needs: check-project-changes
if: ${{ needs.check-project-changes.outputs.should-build }}
runs-on: self-hosted
env:
SVN_USERNAME: ${{ secrets.svn_username }}
SVN_PASSWORD: ${{ secrets.svn_password }}
steps:
#DO NOT CHECKOUT GIT
- name: setup-build
id: setup-build
run: |
#clean up the directory in case a previous run failed
if ( Test-Path -Path svn-builds )
{
Remove-Item -Path ".\svn-builds" -Recurse -Force
}
if ( Test-Path -Path svn-daily-build )
{
Remove-Item -Path ".\svn-daily-build" -Recurse -Force
}
#make sure installer files are up-to-date
if ( !(Test-Path -Path svn-installer ))
{
New-Item -Path ".\svn-installer" -ItemType "Directory"
svn checkout --username $env:SVN_USERNAME --password $env:SVN_PASSWORD $env:SVN_INSTALLER svn-installer
}
else
{
cd svn-installer
svn update --username $env:SVN_USERNAME --password $env:SVN_PASSWORD
svn resolve --accept theirs-full --username $env:SVN_USERNAME --password $env:SVN_PASSWORD
cd ..
}
cd svn-repo
#create output values
$head=$(svn info --username $env:SVN_USERNAME --password $env:SVN_PASSWORD --revision HEAD --show-item revision)
$build_name="BATIOSr$head"
#write outputs
"BUILD_NUMBER=$head" | Out-File -FilePath $env:GITHUB_ENV -Append
"BUILD_NAME=$build_name" | Out-File -FilePath $env:GITHUB_ENV -Append
"output1=$head" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"output2=$build_name" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
cd ..
env:
SVN_INSTALLER: ${{ vars.svn_installer }}
#build the project from the command line; unity is installed on self-hosted runner
- name: make-build
env:
UNITY_PATH: ${{ secrets.unity_path }}
run: |
Write-Host ">> Building project."
Start-Process $env:UNITY_PATH -ArgumentList "-batchMode","-quit","-executeMethod","Builder.BuildProject","-projectPath","svn-repo","-outputPath","tempBuild","-buildTarget","StandaloneWindows64","-logFile","$(Get-Location)\buildLog.txt" -Wait
Write-Host ">> Build complete."
Write-Host ">> Build output:"
cat buildLog.txt
Remove-Item -Path ".\buildLog.txt" -Force
- name: make-installer
env:
SVN_INSTALLER: ${{ vars.svn_installer }}
run: |
#checkout the installer if you haven't already
if ( !(Test-Path -Path svn-installer) )
{
svn checkout --username $env:SVN_USERNAME --password $env:SVN_PASSWORD $env:SVN_INSTALLER svn-installer
}
#actually make the installer
Move-Item -Path(Get-ChildItem -Path ".\tempBuild" -Exclude "*DoNotShip",".svn") -Destination ".\svn-installer\GAMEDIRECTORY"
Start-Process "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" -ArgumentList ".\svn-installer\InstallScript.iss" -Wait
Remove-Item -Path ".\tempBuild" -Recurse -Force
#upload builds to svn builds folder
- name: upload-to-svn
id: upload-to-svn
env:
SVN_BUILD: ${{ vars.SVN_BUILD }}
SVN_DAILY_BUILD: ${{ vars.SVN_DAILY_BUILD }}
run: |
#update the daily build
Write-Host ">> Updating daily build."
Write-Host ">> Checking out the svn-daily-build"
New-Item -Path ".\svn-daily-build" -ItemType "Directory"
svn checkout --username $env:SVN_USERNAME --password $env:SVN_PASSWORD $env:SVN_DAILY_BUILD svn-daily-build
#7 day rolling window of daily builds
cd svn-daily-build
$daily_builds = (Get-ChildItem -Directory -Exclude ".svn")
if ($daily_builds.Length -ge 7)
{
#get name of folder to delete
$oldest_build = $daily_builds[0].basename
Write-Host ">> 7 day rolling window exceeded, deleting $oldest_build"
svn remove $daily_builds[0] --force --username $env:SVN_USERNAME --password $env:SVN_PASSWORD
}
cd ..
Write-Host ">> Setting up daily build folder"
New-Item -Path ".\svn-daily-build\$env:BUILD_NAME" -ItemType "Directory"
New-Item -Path ".\svn-daily-build\$env:BUILD_NAME\GAMEDIRECTORY" -ItemType "Directory"
New-Item -Path ".\svn-daily-build\$env:BUILD_NAME\INSTALLER" -ItemType "Directory"
Write-Host ">> Copying current build and installer to daily build folder"
Copy-Item -Path (Get-ChildItem -Path .\svn-installer\GAMEDIRECTORY -Exclude "DigiPen_EULA.rtf","icon.ico") -Destination ".\svn-daily-build\$env:BUILD_NAME\GAMEDIRECTORY"
Copy-Item -Path ".\svn-installer\INSTALLER\*" -Destination ".\svn-daily-build\$env:BUILD_NAME\INSTALLER"
Write-Host ">> Committing daily build folder"
cd svn-daily-build
svn add $env:BUILD_NAME --username $env:SVN_USERNAME --password $env:SVN_PASSWORD
svn commit --username $env:SVN_USERNAME --password $env:SVN_PASSWORD -m "Daily build"
cd ..
Write-Host ">> Cleaning up daily build upload."
Remove-Item -Path ".\svn-daily-build" -Recurse -Force
#upload the weekly builds on tuesday
Write-Host ">> Is today Tuesday?"
if ((Get-Date).DayOfWeek -eq "Tuesday")
{
Write-Host ">> Uploading new weekly build"
Write-Host ">> Checking out svn-builds"
New-Item -Path ".\svn-builds" -ItemType "Directory"
svn checkout --username $env:SVN_USERNAME --password $env:SVN_PASSWORD $env:SVN_BUILD svn-builds --depth empty
Write-Host ">> Moving new build and installer to svn-builds."
New-Item -Path ".\svn-builds\$env:BUILD_NAME" -ItemType "Directory"
New-Item -Path ".\svn-builds\$env:BUILD_NAME\GAMEDIRECTORY" -ItemType "Directory"
Move-Item -Path (Get-ChildItem -Path .\svn-installer\GAMEDIRECTORY -Exclude "DigiPen_EULA.rtf","icon.ico") -Destination ".\svn-builds\$env:BUILD_NAME\GameDirectory"
Move-Item -Path ".\svn-installer\INSTALLER" -Destination ".\svn-builds\$env:BUILD_NAME\Installer"
New-Item -Path ".\svn-installer\INSTALLER" -ItemType "Directory"
Write-Host ">> Committing new build to svn."
cd svn-builds
svn add $env:BUILD_NAME --username $env:SVN_USERNAME --password $env:SVN_PASSWORD
svn commit --username $env:SVN_USERNAME --password $env:SVN_PASSWORD -m "Weekly build"
cd ..
Write-Host ">> Cleaning up weekly build upload."
Remove-Item -Recurse -Force -Path ".\svn-builds\*"
}
else
{
Remove-Item -Path (Get-ChildItem -Path .\svn-installer\GAMEDIRECTORY -Exclude "DigiPen_EULA.rtf","icon.ico") -Recurse -Force
Remove-Item -Path ".\svn-installer\INSTALLER\*" -Force
}
Write-Host ">> Done!."
outputs:
build-number: ${{ steps.setup-build.outputs.output1 }}
build-name: ${{ steps.setup-build.outputs.output2 }}
#run build verification tests
run-bvt:
needs: build
uses: justinli00/leviathan/.github/workflows/run-tests.yaml@main
with:
revision: ${{ needs.build.outputs.build-number }}
test-revision: ${{ needs.build.outputs.build-number }}
secrets: inherit
permissions:
contents: write
ping-discord:
needs: [ build, run-bvt, check-project-changes ]
if: always()
runs-on: self-hosted
steps:
#this still gives errors, even though it's clean
- name: assemble-build-message
continue-on-error: true #to ignore errors, which always happen
env:
BUILD_NAME: ${{ needs.build.outputs.build-name}}
BUILD_NUMBER: ${{ needs.build.outputs.build-number}}
SVN_BUILD: ${{ vars.SVN_BUILD }}
SVN_DAILY_BUILD: ${{ vars.SVN_DAILY_BUILD }}
SVN_TEST: ${{ vars.SVN_TEST }}
run: |
if ( "$env:BUILD_NUMBER" -ne "" )
{
$message="[REVISION $env:BUILD_NUMBER]:`n"
$message+="New daily build up at: $env:SVN_DAILY_BUILD$env:BUILD_NAME`n"
$message+="View the BVT at: $env:SVN_TEST" + "results_$env:BUILD_NUMBER.xlsx`n"
if((Get-Date).DayOfWeek -eq "Tuesday")
{
Write-Host ">> It is Tuesday my dudes"
$message+="After today, it can be found at $env:SVN_BUILD$env:BUILD_NAME`n"
}
$message+="&" #append the delimiter to the end
"BUILD_MESSAGE<<&" | Out-File -FilePath $env:GITHUB_ENV -Append
$message | Out-File -FilePath $env:GITHUB_ENV -Append
"&" | Out-File -FilePath $env:GITHUB_ENV -Append
}
else
{
"BUILD_MESSAGE=No build was made, since there have been no changes made to the project since the previous build." | Out-File -FilePath $env:GITHUB_ENV -Append
}
#change the picture to use based on whether it passed or failed
- name: pick-picture
if: always()
run: |
if ( "${{ needs.build.result }}" -eq "Success" ) #powershell -eq for strings is not case-sensitive
{
"SAFFRON_IMAGE=${{ secrets.SUCCESS_EMBED }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"BUILD_STATUS=${{ needs.build.result }}" | Out-File -FilePath $env:GITHUB_ENV -Append
}
elseif ( ("${{ needs.build.result }}" -eq "Skipped") -or ("${{ needs.build.result }}" -eq "Cancelled") )
{
#skipped OR cancelled
"SAFFRON_IMAGE=${{ secrets.NOT_RUN_EMBED }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"BUILD_STATUS='Cancelled'" | Out-File -FilePath $env:GITHUB_ENV -Append
}
else
{
"SAFFRON_IMAGE=${{ secrets.FAIL_EMBED }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"BUILD_STATUS=${{ needs.build.result }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"BUILD_MESSAGE='Automated build failed.'" | Out-File -FilePath $env:GITHUB_ENV -Append
}
#make the ping
- name: use-webhook
if: always()
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.discord_webhook }}
status: ${{ env.BUILD_STATUS }}
content: ${{ env.BUILD_MESSAGE }}
title: "Daily Build"
nocontext: true
image: ${{ env.SAFFRON_IMAGE }}
avatar_url: ${{ secrets.NOT_RUN_EMBED }}
nofail: false #now that assemble-build-message doesn't show false negative, this will actually indicate result