From bff56ffd0fe9e7002d921dbf3b607308964efac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E7=A7=8B?= Date: Tue, 9 Jan 2024 19:00:11 +0800 Subject: [PATCH] ci: add `android` target to release build (#5844) * build: build android Signed-off-by: lateautumn233 * ci: add `android` target to release build Signed-off-by: lateautumn233 --------- Signed-off-by: lateautumn233 --- .github/workflows/release_android.yml | 34 +++++++++++++++++++++++++++ build.sh | 29 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 .github/workflows/release_android.yml diff --git a/.github/workflows/release_android.yml b/.github/workflows/release_android.yml new file mode 100644 index 00000000000..c696ddb743a --- /dev/null +++ b/.github/workflows/release_android.yml @@ -0,0 +1,34 @@ +name: release_android + +on: + release: + types: [ published ] + +jobs: + release_android: + strategy: + matrix: + platform: [ ubuntu-latest ] + go-version: [ '1.21' ] + name: Release + runs-on: ${{ matrix.platform }} + steps: + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build + run: | + bash build.sh release android + + - name: Upload assets + uses: softprops/action-gh-release@v1 + with: + files: build/compress/* diff --git a/build.sh b/build.sh index 7f56e5b2e9a..f036d714efa 100644 --- a/build.sh +++ b/build.sh @@ -211,6 +211,27 @@ BuildReleaseLinuxMuslArm() { done } +BuildReleaseAndroid() { + rm -rf .git/ + mkdir -p "build" + wget https://dl.google.com/android/repository/android-ndk-r26b-linux.zip + unzip android-ndk-r26b-linux.zip + rm android-ndk-r26b-linux.zip + OS_ARCHES=(amd64 arm64 386 arm) + CGO_ARGS=(x86_64-linux-android24-clang aarch64-linux-android24-clang i686-linux-android24-clang armv7a-linux-androideabi24-clang) + for i in "${!OS_ARCHES[@]}"; do + os_arch=${OS_ARCHES[$i]} + cgo_cc=$(realpath android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/${CGO_ARGS[$i]}) + echo building for android-${os_arch} + export GOOS=android + export GOARCH=${os_arch##*-} + export CC=${cgo_cc} + export CGO_ENABLED=1 + go build -o ./build/$appName-android-$os_arch -ldflags="$ldflags" -tags=jsoniter . + android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip ./build/$appName-android-$os_arch + done +} + MakeRelease() { cd build mkdir compress @@ -218,6 +239,11 @@ MakeRelease() { cp "$i" alist tar -czvf compress/"$i".tar.gz alist rm -f alist + done + for i in $(find . -type f -name "$appName-android-*"); do + cp "$i" alist + tar -czvf compress/"$i".tar.gz alist + rm -f alist done for i in $(find . -type f -name "$appName-darwin-*"); do cp "$i" alist @@ -256,6 +282,9 @@ elif [ "$1" = "release" ]; then elif [ "$2" = "linux_musl" ]; then BuildReleaseLinuxMusl MakeRelease "md5-linux-musl.txt" + elif [ "$2" = "android" ]; then + BuildReleaseAndroid + MakeRelease "md5-android.txt" else BuildRelease MakeRelease "md5.txt"