Fix #268 #77
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: BitMono.Build | |
| on: | |
| create: | |
| tags: | |
| - "*" | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - '.github/workflows/BitMono.Build.yaml' | |
| - 'props/SharedPackages.props' | |
| - 'props/SharedProjectProps.props' | |
| - 'props/SharedTestProps.props' | |
| - 'src/**' | |
| - 'test/**' | |
| pull_request: | |
| paths: | |
| - '.github/workflows/BitMono.Build.yaml' | |
| - 'props/SharedPackages.props' | |
| - 'props/SharedProjectProps.props' | |
| - 'props/SharedTestProps.props' | |
| - 'src/**' | |
| - 'test/**' | |
| jobs: | |
| Build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| target-framework: [net10.0, net9.0, net8.0, net7.0, net6.0, net462, netstandard2.1, netstandard2.0] | |
| runtime: [linux-x64, win-x64, linux-arm64, win-arm64, osx-x64, osx-arm64, win-x86] | |
| exclude: | |
| # Exclude win-x86 builds for .NET Standard as they're architecture-independent | |
| - runtime: win-x86 | |
| target-framework: netstandard2.0 | |
| - runtime: win-x86 | |
| target-framework: netstandard2.1 | |
| outputs: | |
| version: ${{ steps.project-build.outputs.version }} | |
| is_prerelease: ${{ steps.project-build.outputs.is_prerelease }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| env: | |
| DOTNET_NOLOGO: true | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| with: | |
| dotnet-version: 10.x | |
| - name: Build Project | |
| uses: ./.github/actions/project-build | |
| id: project-build | |
| with: | |
| project_path: src/BitMono.CLI/BitMono.CLI.csproj | |
| nuget_push: false | |
| target_framework: ${{ matrix.target-framework }} | |
| runtime_version: ${{ matrix.runtime }} | |
| github_token: ${{ secrets.PAT }} | |
| - name: Install zip (for Linux/macOS) | |
| run: | | |
| if [[ "${{ matrix.runtime }}" =~ ^linux ]]; then | |
| sudo apt-get install -y zip | |
| elif [[ "${{ matrix.runtime }}" =~ ^osx ]]; then | |
| if ! command -v zip &> /dev/null; then | |
| echo "zip is not available on this macOS runner, and it should be pre-installed." | |
| exit 1 | |
| fi | |
| fi | |
| - name: Zip artifacts | |
| run: | | |
| cd ./src/BitMono.CLI/bin/Release/${{ matrix.target-framework }}/${{ matrix.runtime }} && \ | |
| zip -qq -r ./BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }}.zip * | |
| - name: Upload build | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }} | |
| path: "./src/BitMono.CLI/bin/Release/${{ matrix.target-framework }}/${{ matrix.runtime }}/BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }}.zip" | |
| if-no-files-found: error | |
| UnityPackage: | |
| runs-on: ubuntu-latest | |
| if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'create' && github.event.ref_type == 'tag') | |
| strategy: | |
| matrix: | |
| # Note: | |
| # GameCI currently has delays publishing some newer Unity versions to Docker Hub. | |
| # Newer tags (post-2024-05-16), e.g. 2022.3.50f1 and 6000.0.x (6.0/6.1/6.2), may be unavailable. | |
| # See GameCI announcement in Discord. Using last known published versions instead. | |
| unity-version: [ | |
| 2019.4.40f1, | |
| 2020.3.48f1, | |
| 2021.3.45f1, | |
| 2022.3.29f1, # replaced 2022.3.50f1 (not published) | |
| 6000.0.2f1 # replaced 6.0.0f1/6.1.0f1/6.2.0f1 (not published) | |
| # 2022.3.50f1, # not published on unityci/editor yet | |
| # 6.0.0f1, # not published on unityci/editor yet | |
| # 6.1.0f1, # not published on unityci/editor yet | |
| # 6.2.0f1 # not published on unityci/editor yet | |
| ] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Cache Unity Library | |
| uses: actions/cache@v5 | |
| with: | |
| path: test/BitMono.Unity.TestProject/Library | |
| key: Library-BitMono-Unity-${{ matrix.unity-version }} | |
| restore-keys: | | |
| Library-BitMono-Unity- | |
| Library- | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| env: | |
| DOTNET_NOLOGO: true | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| with: | |
| dotnet-version: 10.x | |
| - name: Build BitMono.CLI for Unity Package | |
| uses: ./.github/actions/project-build | |
| id: cli-build | |
| with: | |
| project_path: src/BitMono.CLI/BitMono.CLI.csproj | |
| nuget_push: false | |
| target_framework: net462 | |
| runtime_version: win-x64 | |
| github_token: ${{ secrets.PAT }} | |
| - name: Copy Unity files to test project | |
| run: | | |
| mkdir -p test/BitMono.Unity.TestProject/Assets/BitMono.Unity | |
| cp -R src/BitMono.Unity/* test/BitMono.Unity.TestProject/Assets/BitMono.Unity/ | |
| # Keep CLI inside Assets but we'll disable import via PluginImporter/meta | |
| mkdir -p test/BitMono.Unity.TestProject/Assets/BitMono.Unity/BitMono.CLI | |
| cp -R src/BitMono.CLI/bin/Release/net462/win-x64/* test/BitMono.Unity.TestProject/Assets/BitMono.Unity/BitMono.CLI/ | |
| # Copy BitMonoConfig.cs.meta if it exists to preserve GUID for ScriptableObject binding | |
| if [ -f src/BitMono.Unity/Editor/BitMonoConfig.cs.meta ]; then | |
| cp src/BitMono.Unity/Editor/BitMonoConfig.cs.meta test/BitMono.Unity.TestProject/Assets/BitMono.Unity/Editor/BitMonoConfig.cs.meta | |
| fi | |
| # Generate .meta files to disable Unity import for all CLI DLLs (prevents load on project open) | |
| CLI_DIR="test/BitMono.Unity.TestProject/Assets/BitMono.Unity/BitMono.CLI" | |
| if [ -d "$CLI_DIR" ]; then | |
| while IFS= read -r -d '' dll; do | |
| meta="${dll}.meta" | |
| name="$(basename "$dll")" | |
| base="${name%.*}" | |
| guid="${base}000000000000000000000000000000" | |
| printf "%s\n" \ | |
| "fileFormatVersion: 2" \ | |
| "guid: ${guid}" \ | |
| "PluginImporter:" \ | |
| " serializedVersion: 2" \ | |
| " isPreloaded: 0" \ | |
| " isOverridable: 0" \ | |
| " platformData:" \ | |
| " - first:" \ | |
| " Any:" \ | |
| " second:" \ | |
| " enabled: 0" \ | |
| " userData:" \ | |
| " assetBundleName:" \ | |
| " assetBundleVariant:" \ | |
| > "$meta" | |
| done < <(find "$CLI_DIR" -type f -name "*.dll" -print0) | |
| fi | |
| - name: Setup Unity for Package Export | |
| uses: game-ci/unity-builder@v4 | |
| env: | |
| PACKAGE_VERSION: ${{ steps.cli-build.outputs.version }} | |
| VERSION: ${{ steps.cli-build.outputs.version }} | |
| UNITY_VERSION: ${{ matrix.unity-version }} | |
| UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| with: | |
| unityVersion: ${{ matrix.unity-version }} | |
| targetPlatform: StandaloneLinux64 | |
| buildMethod: BitMono.Editor.PackageExporter.ExportPackage | |
| projectPath: test/BitMono.Unity.TestProject | |
| buildName: BitMono-Unity-Package | |
| allowDirtyBuild: true | |
| - name: Verify .unitypackage was created | |
| run: | | |
| set -e | |
| VERSION_NO_HASH='${{ steps.cli-build.outputs.version }}' | |
| # Strip any SemVer build metadata (e.g., +<commit-hash>) for filenames | |
| VERSION_NO_HASH="${VERSION_NO_HASH%%+*}" | |
| UNITY_VER='${{ matrix.unity-version }}' | |
| FILE="BitMono-Unity-v${VERSION_NO_HASH}-Unity${UNITY_VER}.unitypackage" | |
| if [ ! -f "$FILE" ]; then | |
| echo "Unity package not found at expected path: ./$FILE" >&2 | |
| echo "Available unitypackages:" >&2 | |
| find . -name "*.unitypackage" -print | |
| exit 1 | |
| fi | |
| echo "Unity package created: $FILE" | |
| size_bytes=$(stat -c%s -- "$FILE") | |
| size_mb=$(awk -v s="$size_bytes" 'BEGIN {printf "%.2f", s/1024/1024}') | |
| echo "File size: ${size_mb} MB" | |
| - name: Rename .unitypackage to include build metadata (if present) | |
| run: | | |
| VERSION_FULL='${{ steps.cli-build.outputs.version }}' | |
| UNITY_VER='${{ matrix.unity-version }}' | |
| BASE="BitMono-Unity-v${VERSION_FULL%%+*}-Unity${UNITY_VER}.unitypackage" | |
| if [[ "$VERSION_FULL" == *+* ]]; then | |
| TARGET="BitMono-Unity-v${VERSION_FULL}-Unity${UNITY_VER}.unitypackage" | |
| if [ -f "$BASE" ]; then | |
| echo "Renaming $BASE -> $TARGET" | |
| mv -f "$BASE" "$TARGET" | |
| else | |
| echo "Expected base package not found for rename: $BASE" >&2 | |
| fi | |
| else | |
| echo "No build metadata in version; keeping filename: $BASE" | |
| fi | |
| - name: Create Unity Package Directory | |
| run: | | |
| mkdir -p unity-package-temp/Editor | |
| - name: Copy Unity Package Files | |
| run: | | |
| cp src/BitMono.Unity/Editor/*.cs unity-package-temp/Editor/ | |
| cp src/BitMono.Unity/Editor/*.asmdef unity-package-temp/Editor/ || echo "No .asmdef files found" | |
| cp src/BitMono.Unity/package.json unity-package-temp/ | |
| # Ensure BitMonoConfig.asset is included in package content | |
| if [ -f src/BitMono.Unity/BitMonoConfig.asset ]; then | |
| cp src/BitMono.Unity/BitMonoConfig.asset unity-package-temp/ | |
| else | |
| echo "BitMonoConfig.asset not found in src/BitMono.Unity" >&2 | |
| fi | |
| mkdir -p unity-package-temp/BitMono.CLI | |
| cp -R src/BitMono.CLI/bin/Release/net462/win-x64/* unity-package-temp/BitMono.CLI/ | |
| - name: Update Package Version and Unity Version | |
| run: | | |
| sudo apt-get update && sudo apt-get install -y jq | |
| unityVersion='${{ matrix.unity-version }}' | |
| unityShort=$(echo "$unityVersion" | sed -E 's/^(\d+\.\d+)\..*/\1/') | |
| tmp=$(mktemp) | |
| jq \ | |
| --arg ver '${{ steps.cli-build.outputs.version }}' \ | |
| --arg unity "$unityShort" \ | |
| '.version=$ver | .unity=$unity' \ | |
| unity-package-temp/package.json > "$tmp" && mv "$tmp" unity-package-temp/package.json | |
| echo "Updated package.json:" | |
| echo " Version: ${{ steps.cli-build.outputs.version }}" | |
| echo " Unity: $unityShort" | |
| - name: Test Unity Package Compatibility | |
| run: | | |
| echo "Testing Unity version compatibility..." | |
| pkgUnity=$(jq -r '.unity' unity-package-temp/package.json) | |
| pkgUnityRelease=$(jq -r '.unityRelease // ""' unity-package-temp/package.json) | |
| echo "Package Unity version: $pkgUnity" | |
| echo "Package Unity release: $pkgUnityRelease" | |
| echo "Target Unity version: ${{ matrix.unity-version }}" | |
| - name: Create UPM Package (Modern Unity Package Manager) | |
| run: | | |
| # Create a proper UPM package structure (POSIX for Ubuntu runners) | |
| mkdir -p upm-package/Editor | |
| # Copy files to UPM structure | |
| cp unity-package-temp/Editor/*.cs upm-package/Editor/ 2>/dev/null || true | |
| cp unity-package-temp/Editor/*.asmdef upm-package/Editor/ 2>/dev/null || echo "No .asmdef files found" | |
| cp unity-package-temp/package.json upm-package/ | |
| # Prefer copying BitMonoConfig.asset from source; fallback to temp if needed | |
| if [ -f src/BitMono.Unity/BitMonoConfig.asset ]; then | |
| cp src/BitMono.Unity/BitMonoConfig.asset upm-package/ | |
| else | |
| cp unity-package-temp/BitMonoConfig.asset upm-package/ 2>/dev/null || echo "No BitMonoConfig.asset found" | |
| fi | |
| mkdir -p upm-package/BitMono.CLI | |
| cp -R unity-package-temp/BitMono.CLI/* upm-package/BitMono.CLI/ 2>/dev/null || true | |
| # Create UPM tarball using tar (better compatibility than .zip) | |
| cd upm-package | |
| tar -czf ../BitMono-Unity-UPM-v${{ steps.cli-build.outputs.version }}-Unity${{ matrix.unity-version }}.tgz * | |
| cd .. | |
| - name: Upload Unity Packages | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: BitMono-Unity-v${{ steps.cli-build.outputs.version }}-Unity${{ matrix.unity-version }} | |
| path: | | |
| BitMono-Unity-v*-Unity${{ matrix.unity-version }}.unitypackage | |
| BitMono-Unity-UPM-v*-Unity${{ matrix.unity-version }}.tgz | |
| if-no-files-found: error | |
| Release: | |
| if: github.event_name == 'create' && github.event.ref_type == 'tag' | |
| needs: [Build, UnityPackage] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| path: ./artifacts | |
| - name: List downloaded artifacts | |
| run: | | |
| echo "Downloaded artifacts:" | |
| find ./artifacts -type f -name "*.zip" -o -name "*.unitypackage" | |
| echo "" | |
| echo "Unity packages by version:" | |
| find ./artifacts -name "*Unity*.unitypackage" | sort | |
| - name: Create Release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| name: BitMono Release v${{ needs.Build.outputs.version }} | |
| tag: ${{ needs.Build.outputs.version }} | |
| artifacts: "./artifacts/**/*.zip,./artifacts/**/*.unitypackage,./artifacts/**/*.tgz" | |
| token: ${{ secrets.PAT }} | |
| prerelease: ${{ needs.Build.outputs.is_prerelease }} | |
| allowUpdates: true | |
| draft: true | |