Skip to content

Commit d2eba37

Browse files
committed
123123
1 parent 5afe383 commit d2eba37

File tree

1 file changed

+109
-63
lines changed

1 file changed

+109
-63
lines changed

.github/workflows/build-assets-in-release.yml

Lines changed: 109 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,63 +39,85 @@ jobs:
3939
- name: Checkout code
4040
uses: actions/checkout@v4
4141

42-
# ============== 模拟构建步骤 (用于测试) ==============
43-
# 这部分只是为了模拟生成文件,实际使用时请替换为您的真实构建步骤
44-
- name: Create mock build files for testing (Windows)
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 }}
4562
if: runner.os == 'Windows'
4663
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
4780
$tag_version = "${{ github.ref_name }}"
4881
$archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
49-
New-Item -ItemType Directory -Path $archive_name -Force
82+
New-Item -ItemType Directory -Force -Path $archive_name
5083
51-
if ("${{ matrix.arch }}" -eq "amd64") {
52-
"Mock Windows binary for ${{ matrix.arch }}" | Out-File -FilePath "$archive_name/libopenimsdk-${{ matrix.arch }}.dll"
53-
} else {
54-
"Mock Windows binary for ${{ matrix.arch }}" | Out-File -FilePath "$archive_name/libopenimsdk-${{ matrix.arch }}.dll"
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
5587
}
56-
"Mock Windows header" | Out-File -FilePath "$archive_name/libopenimsdk.h"
57-
58-
Write-Host "Created mock files in $archive_name"
59-
Get-ChildItem -Path $archive_name
6088
61-
- name: Create mock build files for testing (Unix)
89+
- name: Setup and build on ${{ matrix.os }} ${{ matrix.arch }}
6290
if: runner.os != 'Windows'
6391
run: |
64-
tag_version="${{ github.ref_name }}"
65-
archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
66-
mkdir -p $archive_name
92+
sudo bash ./bootstrap_install_mage.sh
93+
export GOARCH=${{ matrix.arch }}
6794
68-
if [ "${{ matrix.os }}" = "macos-latest" ]; then
69-
echo "Mock macOS binary for ${{ matrix.arch }}" > $archive_name/libopenimsdk-${{ matrix.arch }}.dylib
70-
echo "Mock macOS header" > $archive_name/libopenimsdk.h
71-
else
72-
echo "Mock Linux binary for ${{ matrix.arch }}" > $archive_name/libopenimsdk-${{ matrix.arch }}.so
73-
echo "Mock Linux header" > $archive_name/libopenimsdk.h
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..."
74103
fi
75104
76-
echo "Created mock files in $archive_name"
77-
ls -la $archive_name
78-
# ============== 模拟构建步骤结束 ==============
79-
- name: List built files (Windows)
80-
if: runner.os == 'Windows'
81-
run: |
82-
$tag_version = "${{ github.ref_name }}"
83-
$archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
84-
Write-Host "Checking directory: $archive_name"
85-
if (Test-Path $archive_name) {
86-
Get-ChildItem -Path $archive_name -Recurse
87-
} else {
88-
Write-Host "Directory $archive_name not found"
89-
}
105+
# Run the build
106+
sudo -E mage ${{ matrix.build }}
90107
91-
- name: List built files (Unix)
92-
if: runner.os != 'Windows'
93-
run: |
108+
# Create assets directory with proper naming
94109
tag_version="${{ github.ref_name }}"
95110
archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
96-
echo "Checking directory: $archive_name"
97-
ls -la $archive_name || echo "Directory $archive_name not found"
98-
find $archive_name -type f || echo "No files found in $archive_name"
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
99121
100122
- name: Create archive (Windows)
101123
if: runner.os == 'Windows'
@@ -150,11 +172,6 @@ jobs:
150172
tag_version="${{ github.ref_name }}"
151173
repo="${{ github.repository }}"
152174
153-
release_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
154-
"https://api.github.com/repos/$repo/releases/tags/$tag_version")
155-
156-
mkdir -p downloads
157-
158175
declare -A asset_mapping
159176
asset_mapping["ubuntu-amd64-$tag_version-assets.zip"]="linux_x64"
160177
asset_mapping["ubuntu-arm64-$tag_version-assets.zip"]="linux_arm64"
@@ -163,30 +180,59 @@ jobs:
163180
asset_mapping["windows-amd64-$tag_version-assets.zip"]="win_x64"
164181
asset_mapping["windows-386-$tag_version-assets.zip"]="win_ia32"
165182
166-
for asset in "${!asset_mapping[@]}"; do
167-
echo "Attempting to download: $asset"
168-
169-
download_url=$(echo "$release_info" | jq -r --arg name "$asset" \
170-
'.assets[] | select(.name == $name) | .browser_download_url')
183+
gh release download "$tag_version" --repo "$repo" --dir downloads || true
184+
185+
if [ ! "$(ls -A downloads 2>/dev/null)" ]; then
186+
echo "Falling back to API download method"
171187
172-
if [ "$download_url" != "null" ] && [ -n "$download_url" ]; then
173-
echo "Downloading $asset from $download_url"
174-
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
175-
-o "downloads/$asset" "$download_url"
188+
release_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
189+
"https://api.github.com/repos/$repo/releases/tags/$tag_version")
190+
191+
mkdir -p downloads
192+
193+
for asset in "${!asset_mapping[@]}"; do
194+
echo "Attempting to download: $asset"
176195
196+
asset_id=$(echo "$release_info" | jq -r --arg name "$asset" \
197+
'.assets[] | select(.name == $name) | .id')
198+
199+
if [ "$asset_id" != "null" ] && [ -n "$asset_id" ]; then
200+
echo "Downloading $asset (ID: $asset_id)"
201+
202+
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
203+
-H "Accept: application/octet-stream" \
204+
-o "downloads/$asset" \
205+
"https://api.github.com/repos/$repo/releases/assets/$asset_id"
206+
207+
if [ -f "downloads/$asset" ]; then
208+
if file "downloads/$asset" | grep -q "Zip archive"; then
209+
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
210+
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
211+
else
212+
echo "Downloaded file is not a valid ZIP archive: $asset"
213+
rm -f "downloads/$asset"
214+
fi
215+
else
216+
echo "Failed to download: $asset"
217+
fi
218+
else
219+
echo "Asset not found in release: $asset"
220+
fi
221+
done
222+
else
223+
echo "Successfully downloaded using gh CLI"
224+
225+
for asset in "${!asset_mapping[@]}"; do
177226
if [ -f "downloads/$asset" ]; then
178-
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
179227
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
180-
else
181-
echo "Failed to download: $asset"
182228
fi
183-
else
184-
echo "Asset not found in release: $asset"
185-
fi
186-
done
229+
done
230+
fi
187231
188232
echo "Downloaded files:"
189233
ls -la downloads/
234+
env:
235+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190236

191237
- name: Create combined archive
192238
run: |

0 commit comments

Comments
 (0)