Skip to content

Valkyrie build triggered by Quantumrunner #84

Valkyrie build triggered by Quantumrunner

Valkyrie build triggered by Quantumrunner #84

name: Build and optionally release
description: |
This workflow builds the Valkyrie project using Unity and optionally creates a release on GitHub.
The build artifacts are uploaded as artifacts and can be used in the release step if requested.
run-name: Valkyrie build triggered by ${{ github.actor }}
env:
JAVA_HOME: C:\hostedtoolcache\windows\Java_Corretto_jdk\8.462.08-1\x64
on:
workflow_dispatch:
inputs:
customReleaseName:
description: 'Custom Release Name (Alphanumeric only). If set instead of version from file this name will be used for the release and the build artifacts.'
required: false
type: string
create_release:
description: 'Create release'
required: false
default: false
type: boolean
DraftRelease:
description: 'Draft release'
required: false
default: false
type: boolean
PreRelease:
description: 'Pre release'
required: false
default: false
type: boolean
buildWindows:
description: 'Build Windows'
required: false
default: true
type: boolean
buildMac:
description: 'Build Mac'
required: false
default: true
type: boolean
buildLinux:
description: 'Build Linux'
required: false
default: true
type: boolean
buildAndroid:
description: 'Build Android'
required: false
default: true
type: boolean
jobs:
Build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
#Get the version for build and store in environment variable for later use.
#Get the version for build and store in environment variable for later use.
- name: Get version
run: |
$versionFile = "${{ github.workspace }}/unity/Assets/Resources/version.txt"
$version = Get-Content $versionFile
$customName = "${{ github.event.inputs.customReleaseName }}"
if (-not [string]::IsNullOrWhiteSpace($customName)) {
if ($customName -match '^[a-zA-Z0-9]+$') {
Write-Host "Using Custom Release Name: $customName"
echo "RELEASE_NAME=$customName" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
Write-Error "Custom Release Name '$customName' is invalid. Must be alphanumeric only."
exit 1
}
} else {
Write-Host "Using Version from file: $version"
echo "RELEASE_NAME=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
}
# Build_Version is kept for backward compatibility if other scripts use it,
# but we rely on RELEASE_NAME for artifacts/tags now.
echo "Build_Version=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
## Save build version as artifact to ensure it can be used in the release step.
## Save release name as artifact to ensure it can be used in the release step.
- name: Save release name as artifact
run: echo $env:RELEASE_NAME | Set-Content build_version.txt
- uses: actions/upload-artifact@v4
with:
name: build-version
path: build_version.txt
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'corretto'
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
#Downloading and installing unity
#It should be possible to install more than one module at a time
#but it doesn't seem to work so the action has to be repeated for
#each module.
- name: Setup Unity Editor
uses: seinsinnes/setup-unity@v1.1.0
with:
unity-version: 2019.4.41f1
install-path: "C:/Program Files"
- name: Setup Unity Linux Module
if: ${{ github.event.inputs.buildLinux == 'true' || github.event.inputs.buildLinux == '' }}
uses: seinsinnes/setup-unity@v1.1.0
with:
unity-version: 2019.4.41f1
unity-modules: "linux-mono"
install-path: "C:/Program Files"
- name: Setup Unity Mac Module
if: ${{ github.event.inputs.buildMac == 'true' || github.event.inputs.buildMac == '' }}
uses: seinsinnes/setup-unity@v1.1.0
with:
unity-version: 2019.4.41f1
unity-modules: "mac-mono"
install-path: "C:/Program Files"
- name: Setup Unity Android Module
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
uses: seinsinnes/setup-unity@v1.1.0
with:
unity-version: 2019.4.41f1
unity-modules: "android"
install-path: "C:/Program Files"
#Activate requires unity account creds for unity license checkout.
- name: Activate Unity
uses: kuler90/activate-unity@v1
with:
unity-username: ${{ secrets.UNITY_USERNAME }}
unity-password: ${{ secrets.UNITY_PASSWORD }}
unity-authenticator-key: ${{ secrets.UNITY_AUTHENTICATOR_KEY }}
#Move unity to where the build script expects it to be installed.
- name: Move unity to expected location
run: Rename-Item "C:/Program Files/2019.4.41f1" Unity
#Remove all pre-installed android sdk build tool versions except 28.0.3
#Get-ChildItem -Path "C:/Android/android-sdk/build-tools" -Exclude 28.0.3,29.0.2 | Remove-Item -Recurse -Force
- name: Remove unwanted android sdk build tool versions
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
run: |
Move-Item -Path C:/Android/android-sdk/build-tools/* -Destination c:/windows/temp
Get-ChildItem -Path "C:/Android/android-sdk/build-tools"
#Remove all pre-installed android sdk platform versions except 29
#Get-ChildItem -Path "C:/Android/android-sdk/platforms" -Exclude android-29 | Remove-Item -Recurse -Force
- name: Remove unwanted android sdk platform versions
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
run: |
Move-Item -Path C:/Android/android-sdk/platforms/* -Destination c:/windows/temp
Get-ChildItem -Path "C:/Android/android-sdk/platforms"
#Android managesdk requires java 17
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
#Download and extract android sdk platform and build tools
#Download and extract android sdk platform and build tools
- name: Install android sdk platform and build tools
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
run: |
C:/Android/android-sdk/cmdline-tools/latest/bin/sdkmanager.bat "platforms;android-29"
C:/Android/android-sdk/cmdline-tools/latest/bin/sdkmanager.bat "build-tools;28.0.3" "build-tools;29.0.2" "cmdline-tools;latest" "tools"
- uses: repolevedavaj/install-nsis@v1.0.3
with:
nsis-version: '3.10'
#Run build script
#Run build script
- name: Run build PowerShell script
run: pwsh -File ${{ github.workspace }}/build.ps1
env:
PACKAGE_VERSION: ${{ env.RELEASE_NAME }}
BUILD_WINDOWS: ${{ github.event.inputs.buildWindows == 'true' || github.event.inputs.buildWindows == '' }}
BUILD_MAC: ${{ github.event.inputs.buildMac == 'true' || github.event.inputs.buildMac == '' }}
BUILD_LINUX: ${{ github.event.inputs.buildLinux == 'true' || github.event.inputs.buildLinux == '' }}
BUILD_ANDROID: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
- name: Archive windows unity build log
if: ${{ github.event.inputs.buildWindows == 'true' || github.event.inputs.buildWindows == '' }}
uses: actions/upload-artifact@v4
with:
name: windows-unity-build-log
path: ${{ github.workspace }}/build/Editor_valkyrie-windows.log
- name: Archive macos unity build log
if: ${{ github.event.inputs.buildMac == 'true' || github.event.inputs.buildMac == '' }}
uses: actions/upload-artifact@v4
with:
name: macos-unity-build-log
path: ${{ github.workspace }}/build/Editor_valkyrie-macos.log
- name: Archive linux unity build log
if: ${{ github.event.inputs.buildLinux == 'true' || github.event.inputs.buildLinux == '' }}
uses: actions/upload-artifact@v4
with:
name: linux-unity-build-log
path: ${{ github.workspace }}/build/Editor_valkyrie-linux.log
- name: Archive android unity build log
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
uses: actions/upload-artifact@v4
with:
name: android-unity-build-log
path: ${{ github.workspace }}/build/Editor_valkyrie-android.log
- name: Archive windows zip build
if: ${{ github.event.inputs.buildWindows == 'true' || github.event.inputs.buildWindows == '' }}
uses: actions/upload-artifact@v4
with:
name: windows-unity-build-zip
path: ${{ github.workspace }}/build/valkyrie-windows-${{ env.RELEASE_NAME }}.zip
- name: Archive windows 7zip build
if: ${{ github.event.inputs.buildWindows == 'true' || github.event.inputs.buildWindows == '' }}
uses: actions/upload-artifact@v4
with:
name: windows-unity-build-7zip
path: ${{ github.workspace }}/build/valkyrie-windows-${{ env.RELEASE_NAME }}.7z
- name: Archive windows installer exe build
if: ${{ github.event.inputs.buildWindows == 'true' || github.event.inputs.buildWindows == '' }}
uses: actions/upload-artifact@v4
with:
name: windows-unity-build-exe
path: ${{ github.workspace }}/build/valkyrie-windows-${{ env.RELEASE_NAME }}.exe
- name: Archive macos build
if: ${{ github.event.inputs.buildMac == 'true' || github.event.inputs.buildMac == '' }}
uses: actions/upload-artifact@v4
with:
name: macos-unity-build
path: ${{ github.workspace }}/build/valkyrie-macos-${{ env.RELEASE_NAME }}.tar.gz
- name: Archive linux build
if: ${{ github.event.inputs.buildLinux == 'true' || github.event.inputs.buildLinux == '' }}
uses: actions/upload-artifact@v4
with:
name: linux-unity-build
path: ${{ github.workspace }}/build/valkyrie-linux-${{ env.RELEASE_NAME }}.tar.gz
- name: Archive android build
if: ${{ github.event.inputs.buildAndroid == 'true' || github.event.inputs.buildAndroid == '' }}
uses: actions/upload-artifact@v4
with:
name: android-unity-build
path: ${{ github.workspace }}/build/Valkyrie-android-${{ env.RELEASE_NAME }}.apk
Release:
if: ${{ github.event.inputs.create_release == 'true' }}
needs: Build
runs-on: ubuntu-latest
steps:
- name: Get version from artifact
uses: actions/download-artifact@v4
with:
name: windows-unity-build-log
path: ./logs
- name: Download build version
uses: actions/download-artifact@v4
with:
name: build-version
- name: Set release name env
run: echo "RELEASE_NAME=$(cat build_version.txt)" >> $GITHUB_ENV
- name: Check if release exists
id: check_release
run: |
release_url=$(gh api -X GET /repos/${{ github.repository }}/releases/tags/${{ env.RELEASE_NAME }} --jq '.upload_url' 2>/dev/null || echo "")
if [ -n "$release_url" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "upload_url=$release_url" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release if not exists
if: steps.check_release.outputs.exists == 'false'
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_NAME }}
name: ${{ env.RELEASE_NAME }}
draft: ${{ github.event.inputs.DraftRelease }}
prerelease: ${{ github.event.inputs.PreRelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./all_artifacts
- name: Prepare release artifacts (exclude *-build-log*)
run: |
mkdir -p ./release_artifacts
find ./all_artifacts -type f ! -name "build_version.txt" ! -name "*.log" -exec cp {} ./release_artifacts/ \;
- name: List release artifacts to upload
run: |
echo "Files to be uploaded to the release:"
ls -lh ./release_artifacts
- name: Upload release artifacts
uses: softprops/action-gh-release@v2
with:
files: ./release_artifacts/*
tag_name: ${{ env.RELEASE_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}