Skip to content

Build SFA PuerNya

Build SFA PuerNya #58

Workflow file for this run

name: Build SFA PuerNya
on:
workflow_dispatch: # 只保留手动触发选项
schedule:
- cron: '0 22,12 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sing-box repository
uses: actions/[email protected]
with:
path: sing-box
repository: PuerNya/sing-box
ref: building
fetch-depth: 0
- uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('sing-box/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup latest stable Go
uses: actions/[email protected]
with:
go-version: 'stable'
- name: Get latest commit message
id: get_commit_message
run: |
cd sing-box
echo "commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT
- name: Setup Java
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: '22'
- name: Setup ndk
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26b
add-to-path: false
- name: Get latest build tools version
id: sdk
run: echo version=$(ls $ANDROID_HOME/build-tools | tail -n 1) >> $GITHUB_OUTPUT
- name: Get sing-box version
id: sing-box
run: |
cd sing-box
git remote add sekai https://github.com/SagerNet/sing-box
git fetch --tags sekai
version=$(CGO_ENABLED=0 go run ./cmd/internal/read_tag)
echo version=$version >> $GITHUB_OUTPUT
- name: Build libbox
env:
CC: ${{steps.setup-ndk.outputs.ndk-path}}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang
TAGS: with_quic,with_dhcp,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_clash_api,with_gvisor
VERSION: ${{steps.sing-box.outputs.version}}
CGO_ENABLED: '0'
GOMAXPROCS: 4
run: |
cd sing-box
go mod tidy
make lib_install
gomobile bind -v -a -trimpath -androidapi 21 -javapkg=io.nekohasekai -libname=box -tags ${TAGS} -ldflags "-X github.com/sagernet/sing-box/constant.Version=${VERSION} -s -w -buildid=" -gcflags=all="-l -B" ./experimental/libbox
- name: Checkout app repository
uses: actions/[email protected]
with:
path: sfa
repository: LQ2002/sing-box-for-android
submodules: recursive
- name: Setup Android SDK and Gradle/caches
uses: android-actions/setup-android@v3
with:
cmdline-tools-version: 'latest'
- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Install latest necessary SDK components
run: |
BUILD_TOOLS_VERSION=$(sdkmanager --list | grep "build-tools;" | sort -rV | head -n 1 | awk '{print $1}')
PLATFORM_VERSION=$(sdkmanager --list | grep "platforms;android-" | sort -rV | head -n 1 | awk '{print $1}')
sdkmanager --install "${BUILD_TOOLS_VERSION}" "${PLATFORM_VERSION}" "platform-tools"
shell: bash
- name: Debug Keystore
run: |
ls -l sfa/app/
file sfa/app/release.keystore
echo "KEYSTORE_PASSWORD length: ${#KEYSTORE_PASSWORD}"
echo "KEY_ALIAS length: ${#KEY_ALIAS}"
echo "KEY_PASSWORD length: ${#KEY_PASSWORD}"
- name: Setup build env && build app
env:
VERSION: ${{steps.sing-box.outputs.version}}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
mkdir -p sfa/app/libs/
cp ./sing-box/libbox.aar sfa/app/libs/
cd sfa
echo "" >> gradle.properties
echo "org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 -XX:+UseParallelGC" >> gradle.properties
echo "org.gradle.caching=true" >> gradle.properties
echo "org.gradle.parallel=true" >> gradle.properties
echo "VERSION_NAME=${VERSION}" > local.properties
echo "VERSION_CODE=$(date +%Y%m%d%H)" >> local.properties
chmod +x ./gradlew
./gradlew assembleRelease --parallel --daemon --max-workers=4 \
-Dorg.gradle.caching=true \
-Dorg.gradle.configureondemand=true \
-Dkotlin.incremental=false \
-Dkotlin.compiler.execution.strategy=in-process \
-Pandroid.injected.signing.store.file=$PWD/app/release.keystore \
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \
-Pandroid.injected.signing.key.alias=$KEY_ALIAS \
-Pandroid.injected.signing.key.password=$KEY_PASSWORD \
-Pandroid.injected.signing.v1-signing-enabled=true \
-Pandroid.injected.signing.v2-signing-enabled=true \
-Pandroid.injected.signing.v3-signing-enabled=true \
-Pandroid.injected.signing.v4-signing-enabled=true
- name: List build output directory
run: |
echo "Listing APK files in build output directory:"
find sfa/app/build/outputs -name "*.apk"
- name: Verify APK signatures
run: |
APKSIGNER="$ANDROID_HOME/build-tools/$(ls $ANDROID_HOME/build-tools | sort -V | tail -n 1)/apksigner"
for apk in sfa/app/build/outputs/apk/other/release/*.apk; do
"$APKSIGNER" verify --verbose "$apk"
done
for apk in sfa/app/build/outputs/apk/play/release/*.apk; do
"$APKSIGNER" verify --verbose "$apk"
done
shell: bash
- name: Upload APKs
uses: actions/[email protected]
env:
version: ${{steps.sing-box.outputs.version}}
with:
name: SFA-PuerNya-${{env.version}}
path: sfa/app/build/outputs/apk/**/*.apk
compression-level: 9
#- name: 创建发布标签
#run: |
#echo "RELEASE_TAG=v${{steps.sing-box.outputs.version}}" >> $GITHUB_ENV
#- name: 创建发布
#uses: softprops/action-gh-release@v2
#env:
#GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#with:
#tag_name: ${{ env.RELEASE_TAG }}
#name: Release ${{ env.RELEASE_TAG }}
#body: ${{ steps.get_commit_message.outputs.commit_message }}
#draft: false
#prerelease: false
#files: |
#sfa/app/build/outputs/apk/other/release/*.apk