Skip to content

Commit 47acba4

Browse files
authored
Refactor Android Lua build and release workflow
Updated the workflow to build and release Android Lua libraries for multiple architectures. Added caching for NDK and Lua source, improved artifact handling, and created a release archive with README.
1 parent 93296e6 commit 47acba4

1 file changed

Lines changed: 147 additions & 14 deletions

File tree

.github/workflows/build-android-lua.yml

Lines changed: 147 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
name: Build Android Lua for Multiple Architectures
1+
name: Build and Release Android Lua Libraries
22

33
on:
44
workflow_dispatch: # 允许手动触发
5+
push:
6+
tags:
7+
- 'android-lua-v*' # 当推送标签时自动触发发布
58

69
env:
710
LUA_VERSION: 5.4.8
811
ANDROID_NDK_VERSION: r26b
912
ANDROID_API_LEVEL: 21
13+
CACHE_VERSION: v1 # 缓存版本,当NDK或工具链更新时修改此值
1014

1115
jobs:
1216
build-android:
@@ -15,27 +19,45 @@ jobs:
1519
matrix:
1620
architecture: [armeabi-v7a, arm64-v8a, x86, x86_64]
1721

22+
outputs:
23+
output_dir: ${{ steps.set_outputs.outputs.output_dir }}
24+
1825
steps:
1926
- name: Checkout repository
2027
uses: actions/checkout@v4
2128

22-
- name: Set up environment
23-
run: |
24-
sudo apt-get update
25-
sudo apt-get install -y wget unzip make gcc
29+
- name: Cache Android NDK
30+
id: cache-ndk
31+
uses: actions/cache@v4
32+
with:
33+
path: android-ndk-${{ env.ANDROID_NDK_VERSION }}
34+
key: android-ndk-${{ env.ANDROID_NDK_VERSION }}-${{ env.CACHE_VERSION }}
2635

27-
- name: Download and extract Android NDK
36+
- name: Download and extract Android NDK (if not cached)
37+
if: steps.cache-ndk.outputs.cache-hit != 'true'
2838
run: |
29-
wget https://dl.google.com/android/repository/android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
39+
wget -q https://dl.google.com/android/repository/android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
3040
unzip -q android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
41+
rm android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
42+
43+
- name: Set NDK environment
44+
run: |
3145
export ANDROID_NDK_HOME=$PWD/android-ndk-${{ env.ANDROID_NDK_VERSION }}
3246
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
3347
34-
- name: Download Lua source code
48+
- name: Cache Lua source code
49+
id: cache-lua
50+
uses: actions/cache@v4
51+
with:
52+
path: lua-${{ env.LUA_VERSION }}
53+
key: lua-source-${{ env.LUA_VERSION }}
54+
55+
- name: Download Lua source code (if not cached)
56+
if: steps.cache-lua.outputs.cache-hit != 'true'
3557
run: |
36-
wget https://www.lua.org/ftp/lua-${{ env.LUA_VERSION }}.tar.gz
58+
wget -q https://www.lua.org/ftp/lua-${{ env.LUA_VERSION }}.tar.gz
3759
tar -xzf lua-${{ env.LUA_VERSION }}.tar.gz
38-
cd lua-${{ env.LUA_VERSION }}
60+
rm lua-${{ env.LUA_VERSION }}.tar.gz
3961
4062
- name: Setup toolchain
4163
id: set_toolchain
@@ -44,22 +66,27 @@ jobs:
4466
"armeabi-v7a")
4567
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi${{ env.ANDROID_API_LEVEL }}-clang
4668
export ARCH=arm
69+
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
4770
;;
4871
"arm64-v8a")
4972
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
5073
export ARCH=aarch64
74+
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
5175
;;
5276
"x86")
5377
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android${{ env.ANDROID_API_LEVEL }}-clang
5478
export ARCH=i686
79+
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
5580
;;
5681
"x86_64")
5782
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
5883
export ARCH=x86_64
84+
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
5985
;;
6086
esac
6187
echo "TOOLCHAIN=$TOOLCHAIN" >> $GITHUB_ENV
6288
echo "ARCH=$ARCH" >> $GITHUB_ENV
89+
echo "STRIP=$STRIP" >> $GITHUB_ENV
6390
6491
- name: Build Lua for Android
6592
run: |
@@ -71,6 +98,7 @@ jobs:
7198
CC=${{ env.TOOLCHAIN }}
7299
AR=${{ env.TOOLCHAIN }}ar
73100
RANLIB=${{ env.TOOLCHAIN }}ranlib
101+
STRIP=${{ env.STRIP }}
74102
MYCFLAGS=-fPIC -O2 -I$(LUA_INC) -DLUA_USE_DLOPEN
75103
MYLDFLAGS=-shared
76104
PLAT= generic
@@ -96,6 +124,7 @@ jobs:
96124
97125
$(LUA_T): $(CORE_O) $(LIB_O)
98126
$(CC) -o $@ $(MYLDFLAGS) $(CORE_O) $(LIB_O) $(MYLIBS)
127+
$(STRIP) --strip-unneeded $@
99128
100129
$(LUAC_T): $(LUAC_O) $(LIB_O)
101130
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LIB_O) $(CORE_O) $(MYLIBS)
@@ -110,12 +139,116 @@ jobs:
110139
# Build Lua
111140
make -C src -f Makefile.android
112141
113-
# Create output directory
142+
# Create output directory with version in name
143+
OUTPUT_NAME=liblua-${{ env.LUA_VERSION }}-android-${{ matrix.architecture }}.so
114144
mkdir -p ../output/android/${{ matrix.architecture }}
115-
cp src/liblua.so ../output/android/${{ matrix.architecture }}/
145+
cp src/liblua.so ../output/android/${{ matrix.architecture }}/$OUTPUT_NAME
146+
147+
# Also keep the original name for compatibility
148+
cp src/liblua.so ../output/android/${{ matrix.architecture }}/liblua.so
149+
150+
echo "Built: $OUTPUT_NAME"
151+
152+
- name: Set output variables
153+
id: set_outputs
154+
run: |
155+
echo "output_dir=output" >> $GITHUB_OUTPUT
116156
117157
- name: Upload artifacts
118158
uses: actions/upload-artifact@v4
119159
with:
120-
name: lua-android-${{ matrix.architecture }}
121-
path: output/android/${{ matrix.architecture }}/liblua.so
160+
name: lua-${{ env.LUA_VERSION }}-android-${{ matrix.architecture }}
161+
path: output/android/${{ matrix.architecture }}/
162+
retention-days: 7
163+
164+
create-release:
165+
runs-on: ubuntu-latest
166+
needs: build-android
167+
if: startsWith(github.ref, 'refs/tags/')
168+
169+
steps:
170+
- name: Checkout repository
171+
uses: actions/checkout@v4
172+
173+
- name: Download all artifacts
174+
uses: actions/download-artifact@v4
175+
with:
176+
path: artifacts
177+
pattern: lua-*-android-*
178+
merge-multiple: true
179+
180+
- name: Create release archive
181+
run: |
182+
# Create a zip file containing all architectures
183+
RELEASE_NAME="lua-android-${{ env.LUA_VERSION }}"
184+
mkdir -p $RELEASE_NAME
185+
186+
# Copy all architecture files
187+
for arch in armeabi-v7a arm64-v8a x86 x86_64; do
188+
if [ -d "artifacts/lua-${{ env.LUA_VERSION }}-android-$arch" ]; then
189+
mkdir -p "$RELEASE_NAME/$arch"
190+
cp artifacts/lua-${{ env.LUA_VERSION }}-android-$arch/*.so "$RELEASE_NAME/$arch/"
191+
fi
192+
done
193+
194+
# Create README file
195+
cat > $RELEASE_NAME/README.md << EOF
196+
# Lua ${{ env.LUA_VERSION }} for Android
197+
198+
Prebuilt Lua ${{ env.LUA_VERSION }} shared libraries for Android.
199+
200+
## Architectures
201+
202+
- armeabi-v7a
203+
- arm64-v8a
204+
- x86
205+
- x86_64
206+
207+
## Files
208+
209+
Each directory contains:
210+
- \`liblua-${{ env.LUA_VERSION }}-android-<arch>.so\` - Versioned library name
211+
- \`liblua.so\` - Generic library name for compatibility
212+
213+
## Usage
214+
215+
Copy the appropriate \`.so\` file to your Android project's \`jniLibs\` directory.
216+
217+
## Build Info
218+
219+
- Built with Android NDK ${{ env.ANDROID_NDK_VERSION }}
220+
- Minimum API Level: ${{ env.ANDROID_API_LEVEL }}
221+
- Build Date: $(date -u +"%Y-%m-%d")
222+
EOF
223+
224+
# Create zip archive
225+
zip -r $RELEASE_NAME.zip $RELEASE_NAME/
226+
227+
# Create individual architecture archives
228+
for arch in armeabi-v7a arm64-v8a x86 x86_64; do
229+
if [ -d "$RELEASE_NAME/$arch" ]; then
230+
cd $RELEASE_NAME/$arch
231+
zip ../../lua-${{ env.LUA_VERSION }}-android-$arch.zip *.so
232+
cd ../..
233+
fi
234+
done
235+
236+
echo "ASSET_NAME=$RELEASE_NAME.zip" >> $GITHUB_ENV
237+
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
238+
239+
- name: Create Release
240+
uses: softprops/action-gh-release@v1
241+
with:
242+
name: Lua ${{ env.LUA_VERSION }} for Android
243+
tag_name: Lua ${{ env.LUA_VERSION }} for Android
244+
files: |
245+
${{ env.ASSET_NAME }}
246+
lua-${{ env.LUA_VERSION }}-android-armeabi-v7a.zip
247+
lua-${{ env.LUA_VERSION }}-android-arm64-v8a.zip
248+
lua-${{ env.LUA_VERSION }}-android-x86.zip
249+
lua-${{ env.LUA_VERSION }}-android-x86_64.zip
250+
generate_release_notes: true
251+
draft: false
252+
prerelease: false
253+
env:
254+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)