|
| 1 | +name: Build Unity SpaceCraft |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + unityVersion: |
| 7 | + description: "Unity Editor version (e.g. 2022.3.45f1). Use 'auto' to detect from ProjectVersion.txt" |
| 8 | + required: false |
| 9 | + default: "auto" |
| 10 | + type: string |
| 11 | + projectPath: |
| 12 | + description: "Unity project path" |
| 13 | + required: false |
| 14 | + default: "Unity/SpaceCraft" |
| 15 | + type: string |
| 16 | + targetPlatform: |
| 17 | + description: "Unity target platform" |
| 18 | + required: false |
| 19 | + default: "WebGL" |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - WebGL |
| 23 | + buildProfile: |
| 24 | + description: "Build profile token (maps to a Unity build method)" |
| 25 | + required: false |
| 26 | + default: "WebGLProductionBuild" |
| 27 | + type: choice |
| 28 | + options: |
| 29 | + - WebGLProductionBuild |
| 30 | + - WebGLDevelopmentBuild |
| 31 | + buildMethod: |
| 32 | + description: "Explicit Unity build method (overrides buildProfile). Example: SpaceCraft.Editor.Builds.BuildWebGLProduction" |
| 33 | + required: false |
| 34 | + default: "" |
| 35 | + type: string |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + name: Build ${{ inputs.targetPlatform }} (${{ inputs.buildProfile }}) |
| 40 | + runs-on: ubuntu-latest |
| 41 | + |
| 42 | + env: |
| 43 | + PROJECT_PATH: ${{ inputs.projectPath }} |
| 44 | + TARGET_PLATFORM: ${{ inputs.targetPlatform }} |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Detect Unity version from ProjectVersion.txt |
| 51 | + id: detect |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + if [[ "${{ inputs.unityVersion }}" != "auto" && -n "${{ inputs.unityVersion }}" ]]; then |
| 56 | + echo "Using provided unityVersion: ${{ inputs.unityVersion }}" |
| 57 | + echo "version=${{ inputs.unityVersion }}" >> "$GITHUB_OUTPUT" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + FILE="${{ github.workspace }}/${{ inputs.projectPath }}/ProjectSettings/ProjectVersion.txt" |
| 61 | + if [[ ! -f "$FILE" ]]; then |
| 62 | + echo "ProjectVersion.txt not found at: $FILE" >&2 |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + VERSION=$(grep -E "^m_EditorVersion:\s*" "$FILE" | sed -E 's/^m_EditorVersion:\s*([^[:space:]]+).*/\1/') |
| 66 | + if [[ -z "$VERSION" ]]; then |
| 67 | + echo "Failed to parse Unity version from ProjectVersion.txt" >&2 |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + echo "Detected Unity version: $VERSION" |
| 71 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Compute build method |
| 74 | + id: compute |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + set -euo pipefail |
| 78 | + if [[ -n "${{ inputs.buildMethod }}" ]]; then |
| 79 | + METHOD="${{ inputs.buildMethod }}" |
| 80 | + else |
| 81 | + case "${{ inputs.buildProfile }}" in |
| 82 | + WebGLProductionBuild) |
| 83 | + METHOD="SpaceCraft.Editor.Builds.BuildWebGLProduction" |
| 84 | + ;; |
| 85 | + WebGLDevelopmentBuild) |
| 86 | + METHOD="SpaceCraft.Editor.Builds.BuildWebGLDevelopment" |
| 87 | + ;; |
| 88 | + *) |
| 89 | + echo "Unknown buildProfile: ${{ inputs.buildProfile }}" >&2 |
| 90 | + exit 1 |
| 91 | + ;; |
| 92 | + esac |
| 93 | + fi |
| 94 | + echo "buildMethod=$METHOD" >> "$GITHUB_OUTPUT" |
| 95 | +
|
| 96 | + - name: Unity - Builder |
| 97 | + uses: game-ci/unity-builder@v4 |
| 98 | + env: |
| 99 | + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} |
| 100 | + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} |
| 101 | + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} |
| 102 | + with: |
| 103 | + projectPath: ${{ inputs.projectPath }} |
| 104 | + targetPlatform: ${{ inputs.targetPlatform }} |
| 105 | + unityVersion: ${{ steps.detect.outputs.version }} |
| 106 | + buildMethod: ${{ steps.compute.outputs.buildMethod }} |
| 107 | + uses_custom_image: false |
| 108 | + # Optional: enable cache |
| 109 | + # cacheUnity: true |
| 110 | + # cacheVersioning: semantic |
| 111 | + |
| 112 | + - name: Upload build artifacts |
| 113 | + if: success() |
| 114 | + uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: SpaceCraft-${{ inputs.targetPlatform }}-${{ inputs.buildProfile }} |
| 117 | + path: | |
| 118 | + build |
| 119 | + ${{ inputs.projectPath }}/Build |
| 120 | +
|
0 commit comments