Skip to content

Build Pipeline (Github Action)

Quantumrunner edited this page Dec 29, 2024 · 10 revisions

Build pipeline

You can create installation files for all different operating systems locally on your computer using the build.bat file or instead you can also run it using a GitHub action.

How to run the Build-GitHub action

As a project contributor go to this page and hit Run workflow button. Afterwards select the branch you want to build for and click Run workflow (green button).

Run workflow button

The pipeline usually needs about 30 minutes to finish. Main reason why it is so slow is that one action is necessary to cleanup old android versions using PowerShell by using Get-ChildItem command.

Once the pipeline has finished you can find the installation files in the artifact section of your run:

Artifcats

Build pipeline yml file

The .yml file that defines the build process can be found here.

Action step description

This build.yml file is a GitHub Actions workflow configuration for building "Valkyrie". Here's a detailed breakdown of what each part of the file does:

  1. Checkout Repository: Uses the actions/checkout action to pull the repository's source code.
  2. Extract Build Version: Reads the version of the build from a file located in unity/Assets/Resources/version.txt and stores it in the Build_Version environment variable for later use.
  3. Set Up Java Development Kit (JDK): Installs JDK 8 using the actions/setup-java action with the Corretto distribution.
  4. Add MSBuild: Adds MSBuild to the system PATH using the microsoft/setup-msbuild action, which is essential for building Windows projects.
  5. Install Unity and Modules: Installs Unity version 2018.4.20f1 along with modules required for building applications on Linux, macOS, Android, and iOS using the kuler90/setup-unity action. Unity is later renamed to a location expected by the build script.
  6. Unity Activation: Activates Unity using credentials stored in GitHub Secrets (e.g., username, password, and an authenticator key).
  7. Clean Android SDK: Removes unnecessary Android SDK build tools and platform versions, retaining only specific versions required for the build.
  8. Run Build Script: Executes a batch script (build.bat) to compile the project.
    • ⚠️ This is the most complex and important step in the pipeline. If something goes wrong have a look at the build.bat file and try to understand in which step it fails.
  9. Log Archiving: Archives build logs for different platforms (Windows, macOS, Linux, Android) as artifacts for debugging and reference.
  10. Build Output Archiving: Archives build outputs (e.g., executables, compressed archives, and installation files) for various platforms, naming them appropriately based on the Build_Version.

Detailed step description

1. Check Out Repository

  • Action: actions/checkout@v4
  • Purpose: Retrieves the source code from the repository to the workflow environment.

2. Get Build Version

  • Command:
    echo "Build_Version=${${{ github.workspace }}/unity/Assets/Resources/version.txt}" | Out-File -FilePath $env:GITHUB_ENV -Append
  • Purpose:
    • Reads the version.txt file from unity/Assets/Resources/.
    • Stores the build version in the Build_Version environment variable for consistent artifact naming.
  • Output: Adds Build_Version to the GitHub environment variables.

3. Set Up JDK 8

  • Action: actions/setup-java@v3
  • Configuration:
    • java-version: '8'
    • distribution: 'corretto'
  • Purpose: Installs JDK 8, required for Unity's Android build pipeline.

4. Add MSBuild to PATH

  • Action: microsoft/[email protected]
  • Purpose: Adds MSBuild to the system PATH, ensuring it is available for building Windows projects.

5. Install Unity and Modules

  • Action: kuler90/[email protected]
  • Configurations:
    • Installs Unity version 2018.4.20f1.
    • Modules:
      • Linux Module: linux
      • Mac Module: mac-mono
      • Android Module: android
      • iOS Module: ios
    • Installation Path: C:/Program Files
  • Purpose: Sets up Unity for building applications on all supported platforms.

6. Activate Unity

  • Action: kuler90/activate-unity@v1
  • Configurations:
    • unity-username: (from GitHub Secrets)
    • unity-password: (from GitHub Secrets)
    • unity-authenticator-key: (from GitHub Secrets)
  • Purpose: Activates Unity using credentials stored in GitHub Secrets, enabling a valid license checkout.

Repository secrets

This step uses repository secrets to hand over the credential data. If there is problems with this step (e.g. HTTP 403) please contact the repostory owner Bruce in the Valkyrie Discord (channel #app-development).

grafik

7. Adjust Unity Installation Path

  • Command:
    Rename-Item "C:/Program Files/2018.4.20f1" Unity
  • Purpose: Renames Unity's installation directory to match the expected path for the custom build script.

8. Clean Android SDK

  • Commands:
    • Remove unused Android SDK build tools:
      Get-ChildItem -Path "C:/Android/android-sdk/build-tools" -Exclude 28.0.3,29.0.2 | Remove-Item -Recurse -Force
    • Remove unused Android SDK platforms:
      Get-ChildItem -Path "C:/Android/android-sdk/platforms" -Exclude android-29 | Remove-Item -Recurse -Force
  • Purpose: Cleans up pre-installed Android SDK components to retain only necessary versions.

9. Run Build Script

  • Command:
    ${{ github.workspace }}/build.bat
  • Purpose: Executes the custom batch script to compile the Unity project for all configured platforms.

Step details

This step runs the build.bat file. If anything went wrong in the previous steps (e.g. a system variable has not been set successfully) the script will fail.

10. Archive Build Logs

  • Action: actions/upload-artifact@v3
  • Configuration:
    • Uploads logs for each platform:
      • Windows: Editor_valkyrie-windows.log
      • macOS: Editor_valkyrie-macos.log
      • Linux: Editor_valkyrie-linux.log
      • Android: Editor_valkyrie-android.log
    • Purpose: Stores build logs as artifacts for later debugging and review.

11. Archive Build Outputs

  • Action: actions/upload-artifact@v3
  • Configurations:
    • Windows:
      • .zip: valkyrie-windows-${{ env.Build_Version }}.zip
      • .7z: valkyrie-windows-${{ env.Build_Version }}.7z
      • .exe: valkyrie-windows-${{ env.Build_Version }}.exe
    • macOS: valkyrie-macos-${{ env.Build_Version }}.tar.gz
    • Linux: valkyrie-linux-${{ env.Build_Version }}.tar.gz
    • Android: Valkyrie-android-${{ env.Build_Version }}.apk
  • Purpose: Archives build outputs for all platforms and uploads them as artifacts.
Clone this wiki locally