|
| 1 | +name: Build assets in release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ${{ matrix.os }} |
| 10 | + strategy: |
| 11 | + matrix: |
| 12 | + include: |
| 13 | + - os: ubuntu-latest |
| 14 | + arch: amd64 |
| 15 | + build: buildLinux |
| 16 | + os_name: ubuntu |
| 17 | + - os: ubuntu-latest |
| 18 | + arch: arm64 |
| 19 | + build: buildLinux |
| 20 | + os_name: ubuntu |
| 21 | + - os: macos-latest |
| 22 | + arch: amd64 |
| 23 | + build: buildIOS |
| 24 | + os_name: macos |
| 25 | + - os: macos-latest |
| 26 | + arch: arm64 |
| 27 | + build: buildIOS |
| 28 | + os_name: macos |
| 29 | + - os: windows-latest |
| 30 | + arch: amd64 |
| 31 | + build: buildWindows |
| 32 | + os_name: windows |
| 33 | + - os: windows-latest |
| 34 | + arch: 386 |
| 35 | + build: buildWindows |
| 36 | + os_name: windows |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Setup Go environment |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version: "1.22" |
| 46 | + |
| 47 | + - name: Install ARM64 cross-compilation toolchain |
| 48 | + if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest' |
| 49 | + run: | |
| 50 | + sudo apt-get update |
| 51 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 52 | + echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 53 | + echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Install MinGW-w64 using Chocolatey |
| 56 | + if: runner.os == 'Windows' && matrix.arch == '386' |
| 57 | + run: | |
| 58 | + curl -L -o mingw32.7z https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z/download |
| 59 | + 7z x mingw32.7z -oC:/mingw32 |
| 60 | +
|
| 61 | + - name: Setup and build on Windows ${{ matrix.arch }} |
| 62 | + if: runner.os == 'Windows' |
| 63 | + run: | |
| 64 | + ./bootstrap_install_mage.bat |
| 65 | + $env:GOARCH="${{ matrix.arch }}" |
| 66 | + if ($env:GOARCH -eq "386") { |
| 67 | + $env:PATH = "C:/mingw32/bin;$env:PATH" |
| 68 | + gcc --version |
| 69 | + $env:CC="gcc -m32" |
| 70 | + $env:CXX="g++ -m32" |
| 71 | + } |
| 72 | +
|
| 73 | + # Create shared directory structure if it doesn't exist |
| 74 | + New-Item -ItemType Directory -Force -Path "shared/ios", "shared/linux", "shared/windows", "shared/android" |
| 75 | +
|
| 76 | + # Run the build |
| 77 | + mage ${{ matrix.build }} |
| 78 | +
|
| 79 | + # Create assets directory with proper naming |
| 80 | + $tag_version = "${{ github.ref_name }}" |
| 81 | + $archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 82 | + New-Item -ItemType Directory -Force -Path $archive_name |
| 83 | +
|
| 84 | + # Copy built files to assets directory |
| 85 | + if (Test-Path "shared/windows" -PathType Container) { |
| 86 | + Copy-Item -Path "shared/windows/*" -Destination $archive_name -Recurse -ErrorAction SilentlyContinue |
| 87 | + } |
| 88 | +
|
| 89 | + - name: Setup and build on ${{ matrix.os }} ${{ matrix.arch }} |
| 90 | + if: runner.os != 'Windows' |
| 91 | + run: | |
| 92 | + sudo bash ./bootstrap_install_mage.sh |
| 93 | + export GOARCH=${{ matrix.arch }} |
| 94 | +
|
| 95 | + # Create shared directory structure if it doesn't exist |
| 96 | + mkdir -p shared/ios shared/linux shared/windows shared/android |
| 97 | +
|
| 98 | + # Additional setup for iOS ARM64 builds |
| 99 | + if [[ "${{ matrix.build }}" == "buildIOS" && "${{ matrix.arch }}" == "arm64" ]]; then |
| 100 | + # Ensure Xcode command line tools are available |
| 101 | + xcode-select --install 2>/dev/null || true |
| 102 | + echo "Building iOS library for ARM64..." |
| 103 | + fi |
| 104 | +
|
| 105 | + # Run the build |
| 106 | + sudo -E mage ${{ matrix.build }} |
| 107 | +
|
| 108 | + # Create assets directory with proper naming |
| 109 | + tag_version="${{ github.ref_name }}" |
| 110 | + archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 111 | + mkdir -p "$archive_name" |
| 112 | +
|
| 113 | + # Copy built files to assets directory |
| 114 | + if [[ "${{ matrix.build }}" == "buildIOS" ]]; then |
| 115 | + cp -r shared/ios/* "$archive_name/" 2>/dev/null || echo "No iOS files to copy" |
| 116 | + elif [[ "${{ matrix.build }}" == "buildLinux" ]]; then |
| 117 | + cp -r shared/linux/* "$archive_name/" 2>/dev/null || echo "No Linux files to copy" |
| 118 | + elif [[ "${{ matrix.build }}" == "buildWindows" ]]; then |
| 119 | + cp -r shared/windows/* "$archive_name/" 2>/dev/null || echo "No Windows files to copy" |
| 120 | + fi |
| 121 | +
|
| 122 | + # - name: List built files (Windows) |
| 123 | + # if: runner.os == 'Windows' |
| 124 | + # run: | |
| 125 | + # $tag_version = "${{ github.ref_name }}" |
| 126 | + # $archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 127 | + # Write-Host "Checking directory: $archive_name" |
| 128 | + # if (Test-Path $archive_name) { |
| 129 | + # Get-ChildItem -Path $archive_name -Recurse |
| 130 | + # } else { |
| 131 | + # Write-Host "Directory $archive_name not found" |
| 132 | + # } |
| 133 | + |
| 134 | + # - name: List built files (Unix) |
| 135 | + # if: runner.os != 'Windows' |
| 136 | + # run: | |
| 137 | + # tag_version="${{ github.ref_name }}" |
| 138 | + # archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 139 | + # echo "Checking directory: $archive_name" |
| 140 | + # ls -la $archive_name || echo "Directory $archive_name not found" |
| 141 | + # find $archive_name -type f || echo "No files found in $archive_name" |
| 142 | + |
| 143 | + - name: Create archive (Windows) |
| 144 | + if: runner.os == 'Windows' |
| 145 | + run: | |
| 146 | + $tag_version = "${{ github.ref_name }}" |
| 147 | + $archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 148 | +
|
| 149 | + if (Test-Path $archive_name) { |
| 150 | + $fileCount = (Get-ChildItem -Path $archive_name -File -Recurse).Count |
| 151 | + if ($fileCount -gt 0) { |
| 152 | + Compress-Archive -Path "$archive_name/*" -DestinationPath "$archive_name.zip" -Force |
| 153 | + Write-Host "Created archive: $archive_name.zip" |
| 154 | + Get-Item "$archive_name.zip" |
| 155 | + } else { |
| 156 | + Write-Host "No files found in $archive_name" |
| 157 | + exit 1 |
| 158 | + } |
| 159 | + } else { |
| 160 | + Write-Host "Directory $archive_name not found" |
| 161 | + exit 1 |
| 162 | + } |
| 163 | +
|
| 164 | + - name: Create archive (Unix) |
| 165 | + if: runner.os != 'Windows' |
| 166 | + run: | |
| 167 | + tag_version="${{ github.ref_name }}" |
| 168 | + archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets" |
| 169 | +
|
| 170 | + if [ -d "$archive_name" ] && [ "$(find $archive_name -type f | wc -l)" -gt 0 ]; then |
| 171 | + zip -r $archive_name.zip $archive_name/ |
| 172 | + echo "Created archive: $archive_name.zip" |
| 173 | + ls -la $archive_name.zip |
| 174 | + else |
| 175 | + echo "No files found in $archive_name" |
| 176 | + exit 1 |
| 177 | + fi |
| 178 | +
|
| 179 | + - name: Upload to release |
| 180 | + uses: softprops/action-gh-release@v2 |
| 181 | + with: |
| 182 | + files: ${{ matrix.os_name }}-${{ matrix.arch }}-${{ github.ref_name }}-assets.zip |
| 183 | + draft: false |
| 184 | + env: |
| 185 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments