Skip to content

Build assets in release #2

Build assets in release

Build assets in release #2

name: Build assets in release
on:
release:
types: [created]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
arch: amd64
build: buildLinux
os_name: ubuntu
- os: ubuntu-latest
arch: arm64
build: buildLinux
os_name: ubuntu
- os: macos-latest
arch: amd64
build: buildIOS
os_name: macos
- os: macos-latest
arch: arm64
build: buildIOS
os_name: macos
- os: windows-latest
arch: amd64
build: buildWindows
os_name: windows
- os: windows-latest
arch: 386
build: buildWindows
os_name: windows
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Install ARM64 cross-compilation toolchain
if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV
- name: Install MinGW-w64 using Chocolatey
if: runner.os == 'Windows' && matrix.arch == '386'
run: |
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
7z x mingw32.7z -oC:/mingw32
- name: Setup and build on Windows ${{ matrix.arch }}
if: runner.os == 'Windows'
run: |
./bootstrap_install_mage.bat
$env:GOARCH="${{ matrix.arch }}"
if ($env:GOARCH -eq "386") {
$env:PATH = "C:/mingw32/bin;$env:PATH"
gcc --version
$env:CC="gcc -m32"
$env:CXX="g++ -m32"
}
# Create shared directory structure if it doesn't exist
New-Item -ItemType Directory -Force -Path "shared/ios", "shared/linux", "shared/windows", "shared/android"
# Run the build
mage ${{ matrix.build }}
# Create assets directory with proper naming
$tag_version = "${{ github.ref_name }}"
$archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
New-Item -ItemType Directory -Force -Path $archive_name
# Copy built files to assets directory
if (Test-Path "shared/windows" -PathType Container) {
Copy-Item -Path "shared/windows/*" -Destination $archive_name -Recurse -ErrorAction SilentlyContinue
}
- name: Setup and build on ${{ matrix.os }} ${{ matrix.arch }}
if: runner.os != 'Windows'
run: |
sudo bash ./bootstrap_install_mage.sh
export GOARCH=${{ matrix.arch }}
# Create shared directory structure if it doesn't exist
mkdir -p shared/ios shared/linux shared/windows shared/android
# Additional setup for iOS ARM64 builds
if [[ "${{ matrix.build }}" == "buildIOS" && "${{ matrix.arch }}" == "arm64" ]]; then
# Ensure Xcode command line tools are available
xcode-select --install 2>/dev/null || true
echo "Building iOS library for ARM64..."
fi
# Run the build
sudo -E mage ${{ matrix.build }}
# Create assets directory with proper naming
tag_version="${{ github.ref_name }}"
archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
mkdir -p "$archive_name"
# Copy built files to assets directory
if [[ "${{ matrix.build }}" == "buildIOS" ]]; then
cp -r shared/ios/* "$archive_name/" 2>/dev/null || echo "No iOS files to copy"
elif [[ "${{ matrix.build }}" == "buildLinux" ]]; then
cp -r shared/linux/* "$archive_name/" 2>/dev/null || echo "No Linux files to copy"
elif [[ "${{ matrix.build }}" == "buildWindows" ]]; then
cp -r shared/windows/* "$archive_name/" 2>/dev/null || echo "No Windows files to copy"
fi
- name: Create archive (Windows)
if: runner.os == 'Windows'
run: |
$tag_version = "${{ github.ref_name }}"
$archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
if (Test-Path $archive_name) {
$fileCount = (Get-ChildItem -Path $archive_name -File -Recurse).Count
if ($fileCount -gt 0) {
Compress-Archive -Path "$archive_name/*" -DestinationPath "$archive_name.zip" -Force
Write-Host "Created archive: $archive_name.zip"
Get-Item "$archive_name.zip"
} else {
Write-Host "No files found in $archive_name"
exit 1
}
} else {
Write-Host "Directory $archive_name not found"
exit 1
}
- name: Create archive (Unix)
if: runner.os != 'Windows'
run: |
tag_version="${{ github.ref_name }}"
archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
if [ -d "$archive_name" ] && [ "$(find $archive_name -type f | wc -l)" -gt 0 ]; then
zip -r $archive_name.zip $archive_name/
echo "Created archive: $archive_name.zip"
ls -la $archive_name.zip
else
echo "No files found in $archive_name"
exit 1
fi
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: ${{ matrix.os_name }}-${{ matrix.arch }}-${{ github.ref_name }}-assets.zip
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
combine-assets:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download release assets
run: |
tag_version="${{ github.ref_name }}"
repo="${{ github.repository }}"
release_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$repo/releases/tags/$tag_version")
mkdir -p downloads
declare -A asset_mapping
asset_mapping["ubuntu-amd64-$tag_version-assets.zip"]="linux_x64"
asset_mapping["ubuntu-arm64-$tag_version-assets.zip"]="linux_arm64"
asset_mapping["macos-amd64-$tag_version-assets.zip"]="mac_x64"
asset_mapping["macos-arm64-$tag_version-assets.zip"]="mac_arm64"
asset_mapping["windows-amd64-$tag_version-assets.zip"]="win_x64"
asset_mapping["windows-386-$tag_version-assets.zip"]="win_ia32"
for asset in "${!asset_mapping[@]}"; do
echo "Attempting to download: $asset"
download_url=$(echo "$release_info" | jq -r --arg name "$asset" \
'.assets[] | select(.name == $name) | .browser_download_url')
if [ "$download_url" != "null" ] && [ -n "$download_url" ]; then
echo "Downloading $asset from $download_url"
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o "downloads/$asset" "$download_url"
if [ -f "downloads/$asset" ]; then
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
else
echo "Failed to download: $asset"
fi
else
echo "Asset not found in release: $asset"
fi
done
echo "Downloaded files:"
ls -la downloads/
- name: Create combined archive
run: |
tag_version="${{ github.ref_name }}"
combined_name="all-platforms-$tag_version-assets"
mkdir -p "$combined_name/assets"
if [ -f "downloads/mapping.txt" ]; then
while IFS=':' read -r zip_file target_dir; do
if [ -f "downloads/$zip_file" ]; then
echo "Processing: $zip_file -> assets/$target_dir"
mkdir -p "$combined_name/assets/$target_dir"
temp_dir="temp_extract_$(basename "$zip_file" .zip)"
mkdir -p "$temp_dir"
unzip -q "downloads/$zip_file" -d "$temp_dir"
extracted_content=$(find "$temp_dir" -mindepth 1 -maxdepth 1 -type d)
if [ -n "$extracted_content" ] && [ $(echo "$extracted_content" | wc -l) -eq 1 ]; then
echo "Moving contents from: $extracted_content"
mv "$extracted_content"/* "$combined_name/assets/$target_dir/" 2>/dev/null || true
else
echo "Moving all extracted content"
mv "$temp_dir"/* "$combined_name/assets/$target_dir/" 2>/dev/null || true
fi
rm -rf "$temp_dir"
echo "Completed processing: $zip_file"
else
echo "File not found: downloads/$zip_file"
fi
done < downloads/mapping.txt
fi
echo "=== Combined archive structure ==="
echo "Directory tree:"
tree "$combined_name" 2>/dev/null || find "$combined_name" -type d | sed 's/[^/]*\//│ /g;s/│ \([^/]*\)$/├── \1/'
echo ""
echo "File count per platform:"
for platform_dir in "$combined_name/assets"/*/; do
if [ -d "$platform_dir" ]; then
file_count=$(find "$platform_dir" -type f | wc -l)
dir_name=$(basename "$platform_dir")
echo " $dir_name: $file_count files"
echo " Sample files:"
find "$platform_dir" -type f | head -3 | while read file; do
echo " $(basename "$file")"
done
fi
done
zip -r "$combined_name.zip" "$combined_name/"
echo ""
echo "=== Created combined archive ==="
ls -la "$combined_name.zip"
echo "Archive size: $(du -h "$combined_name.zip" | cut -f1)"
- name: Upload combined assets to release
uses: softprops/action-gh-release@v2
with:
files: all-platforms-${{ github.ref_name }}-assets.zip
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
############
# assets/
# ├── linux_arm64
# ├── linux_x64
# ├── mac_arm64
# ├── mac_x64
# ├── win_ia32
# └── win_x64