feat: 实现分片构建支持,优化CI并行处理逻辑;更新release脚本以支持分片索引
This commit is contained in:
1 parent
c22a32bc3a
commit
d487cf497a
3 files changed
+63
-24
No files matched your search
@@ -4,8 +4,15 @@ on:
|
||||
tags:
|
||||
- 'v*'
|
||||
jobs:
|
||||
release-bins:
|
||||
release-bins-sharded:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
shard_index: [0, 1, 2, 3, 4]
|
||||
env:
|
||||
SHARD_TOTAL: 5
|
||||
SHARD_INDEX: ${{ matrix.shard_index }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
|
||||
@@ -45,16 +52,41 @@ jobs:
|
||||
node-modules-${{ env.IMAGE_OS }}-${{ env.NODE_VERSION }}-${{ env.NODE_ARCH }}-
|
||||
- name: Build Web Page
|
||||
run: make build-web
|
||||
- name: Build go binaries
|
||||
- name: Build go binaries (shard ${{ matrix.shard_index }}/5)
|
||||
run: make release
|
||||
- uses: softprops/action-gh-release@v1
|
||||
- name: Upload packaged artifacts only
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
files: 'bin/*'
|
||||
name: bililive-bins-shard-${{ matrix.shard_index }}
|
||||
path: |
|
||||
bin/*.tar.gz
|
||||
bin/*.zip
|
||||
bin/*.7z
|
||||
if-no-files-found: ignore
|
||||
|
||||
publish-release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [release-bins-sharded]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
|
||||
- name: Download all shard artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: dist
|
||||
- name: Publish GitHub Release with all packaged files
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
dist/**/*.tar.gz
|
||||
dist/**/*.zip
|
||||
dist/**/*.7z
|
||||
prerelease: ${{ contains(env.GIT_TAG, 'rc') }}
|
||||
|
||||
release-docker-images:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- release-bins
|
||||
- publish-release
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
|
||||
@@ -63,8 +95,6 @@ jobs:
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Docker Setup Buildx
|
||||
uses: docker/setup-buildx-action@v1.5.1
|
||||
- name: Ensure empty bin directory exists for BuildKit bind mount
|
||||
run: mkdir -p bin
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ RUN mkdir -p $OUTPUT_DIR && \
|
||||
cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN set -eux; \
|
||||
RUN set -x; \
|
||||
case $(arch) in \
|
||||
aarch64) go_arch=arm64 ;; \
|
||||
arm*) go_arch=arm ;; \
|
||||
|
||||
+25
-16
@@ -30,30 +30,39 @@ package() {
|
||||
echo $BIN_PATH/$res
|
||||
}
|
||||
|
||||
# Build all targets in parallel on a single runner to speed up CI
|
||||
# Determine concurrency (fallback to 2 if detection fails)
|
||||
JOBS=${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)}
|
||||
# 串行构建,支持在 CI 通过“分片”并行(多个 Runner/Job 共同完成)
|
||||
# 可选环境变量:
|
||||
# SHARD_TOTAL 分片总数(默认 1)
|
||||
# SHARD_INDEX 当前分片索引(默认 0,范围 [0, SHARD_TOTAL))
|
||||
SHARD_TOTAL=${SHARD_TOTAL:-1}
|
||||
SHARD_INDEX=${SHARD_INDEX:-0}
|
||||
# 基本健壮性:非数字/越界回退到安全值
|
||||
case "$SHARD_TOTAL" in ''|*[!0-9]*) SHARD_TOTAL=1;; esac
|
||||
case "$SHARD_INDEX" in ''|*[!0-9]*) SHARD_INDEX=0;; esac
|
||||
if [ "$SHARD_TOTAL" -lt 1 ]; then SHARD_TOTAL=1; fi
|
||||
if [ "$SHARD_INDEX" -ge "$SHARD_TOTAL" ]; then SHARD_INDEX=$((SHARD_INDEX % SHARD_TOTAL)); fi
|
||||
|
||||
# 预热依赖缓存,减少后续下载
|
||||
echo "[deps] Warming Go module cache..."
|
||||
go mod download
|
||||
go mod download >/dev/null 2>&1 || true
|
||||
|
||||
# Generate target list and filter unsupported ones
|
||||
# 生成目标列表并过滤不支持的目标
|
||||
TARGETS=$(go tool dist list | awk '!/^(linux\/loong64|android\/|ios\/|js\/wasm)/')
|
||||
echo "[shard] TOTAL=${SHARD_TOTAL} INDEX=${SHARD_INDEX}"
|
||||
|
||||
# 说明:此前同时使用了 -n1/--max-args 与 -I/--replace,会触发 xargs 互斥参数 warning。
|
||||
# 这里去掉 -I,占位通过 sh -c 的参数传递完成,保留 -n1 和 -P 以保持一条记录一次执行且并行。
|
||||
printf "%s\n" "$TARGETS" | xargs -n1 -P "$JOBS" sh -c '
|
||||
dist="$1"
|
||||
case "$dist" in
|
||||
linux/loong64|android/*|ios/*|js/wasm)
|
||||
exit 0 ;; # filtered above, keep safe-guard
|
||||
*) ;;
|
||||
esac
|
||||
i=0
|
||||
printf "%s\n" "$TARGETS" | while IFS= read -r dist; do
|
||||
mod=$(( i % SHARD_TOTAL ))
|
||||
i=$((i+1))
|
||||
# 非本分片的目标直接跳过
|
||||
if [ "$mod" -ne "$SHARD_INDEX" ]; then
|
||||
continue
|
||||
fi
|
||||
platform="${dist%/*}"
|
||||
arch="${dist#*/}"
|
||||
echo "[build] PLATFORM=$platform ARCH=$arch"
|
||||
make PLATFORM="$platform" ARCH="$arch" bililive
|
||||
' _
|
||||
done
|
||||
|
||||
for file in $(ls $BIN_PATH); do
|
||||
case $file in
|
||||
@@ -69,4 +78,4 @@ for file in $(ls $BIN_PATH); do
|
||||
esac
|
||||
res=$(package $file $package_type)
|
||||
rm -f $BIN_PATH/$file
|
||||
done
|
||||
done
|
||||
Reference in new issue
Block a user