Skip to content

Commit a1d97bc

Browse files
committed
feat(ci): Enhance CI workflows for OpenWrt and package management
- Added OpenWrt package build workflow to create .ipk artifacts for ustb-cli. - Introduced a workflow to calculate and update PKG_MIRROR_HASH before releases. - Updated build.yml to support OpenSSL caching and improved architecture handling. - Refined build steps for aarch64 architecture and removed ARM32 dependencies. - Configured GitHub release uploads for both standard and OpenWrt builds.
1 parent cd7b640 commit a1d97bc

4 files changed

Lines changed: 182 additions & 21 deletions

File tree

.github/workflows/build.yml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
release:
9+
types: [ published ]
810

911
jobs:
1012
build:
1113
name: Build (${{ matrix.architecture }}, ${{ matrix.build_type }})
12-
runs-on: ubuntu-latest
14+
# aarch64 交叉编译固定用 22.04,避免 Noble 的 arm64 源 404
15+
runs-on: ${{ matrix.architecture == 'aarch64' ? 'ubuntu-22.04' : 'ubuntu-latest' }}
1316

1417
strategy:
1518
fail-fast: false
1619
matrix:
17-
architecture: [ x86_64, ARM64, ARM32 ]
20+
architecture: [ x86_64, aarch64 ]
1821
build_type: [ Debug, Release ]
1922

2023
steps:
@@ -25,19 +28,16 @@ jobs:
2528
run: git submodule update --init --recursive
2629

2730
- name: Install dependencies
28-
run: sudo apt-get update && sudo apt-get install -y cmake make g++ ninja-build
31+
run: sudo apt-get update && sudo apt-get install -y cmake make libssl-dev
2932

30-
# ARM64 工具链(aarch64)
31-
- name: Install ARM64 cross-build dependencies
32-
if: matrix.architecture == 'ARM64'
33-
run: sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
34-
35-
# ARM32 工具链(armhf)
36-
- name: Install ARM32 cross-build dependencies
37-
if: matrix.architecture == 'ARM32'
38-
run: sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross
33+
- name: Install aarch64 cross-build dependencies
34+
if: matrix.architecture == 'aarch64'
35+
run: |
36+
sudo dpkg --add-architecture arm64
37+
sudo apt-get update
38+
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross libssl-dev:arm64
3939
40-
- name: Configure (CMake)
40+
- name: CMake Configure
4141
run: |
4242
mkdir -p build
4343
cd build
@@ -47,22 +47,44 @@ jobs:
4747
echo "🔧 Native x86_64 build"
4848
cmake .. \
4949
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
50+
-DWITH_BALANCE=on \
51+
-DWITH_ACCOUNT=on \
52+
-DWITH_SPEEDTEST=on \
53+
-DWITH_COMPLETION=on \
54+
-DGB2312_DECODER=iconv \
55+
-DUSE_INTERACTIVE=on \
56+
-DUSE_THREADS=on \
57+
-DWITH_COLOR=on
5058
;;
51-
ARM64)
52-
echo "🔧 Cross-compiling for ARM64"
59+
aarch64)
60+
echo "🔧 Cross-compiling for aarch64"
5361
cmake .. \
5462
-DCMAKE_TOOLCHAIN_FILE=../aarch64-toolchain.cmake \
5563
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
56-
;;
57-
ARM32)
58-
echo "🔧 Cross-compiling for ARM32"
59-
cmake .. \
60-
-DCMAKE_TOOLCHAIN_FILE=../armhf-toolchain.cmake \
61-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
64+
-DWITH_BALANCE=on \
65+
-DWITH_ACCOUNT=on \
66+
-DWITH_SPEEDTEST=on \
67+
-DWITH_COMPLETION=on \
68+
-DGB2312_DECODER=iconv \
69+
-DUSE_INTERACTIVE=on \
70+
-DUSE_THREADS=on \
71+
-DWITH_COLOR=on
6272
;;
6373
esac
6474
6575
- name: Build
6676
run: |
6777
cd build
6878
make -j$(nproc)
79+
openssl_version=$(openssl version | awk '{print $2}' | tr '.' '_')
80+
echo "OPENSSL_VERSION=$openssl_version" >> $GITHUB_ENV
81+
mv ustb-cli ustb-cli-${{ matrix.architecture }}-${{ matrix.build_type }}-openssl-${openssl_version}
82+
83+
- name: Upload to GitHub Release
84+
if: github.event_name == 'release' && matrix.build_type == 'Release'
85+
uses: softprops/action-gh-release@v2
86+
with:
87+
tag_name: ${{ github.event.release.tag_name }}
88+
files: build/ustb-cli-${{ matrix.architecture }}-${{ matrix.build_type }}-openssl-${{ env.OPENSSL_VERSION }}
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 使用 OpenWrt 官方 SDK 构建 ustb-cli 的 .ipk 包
2+
# 依赖 openwrt/gh-action-sdk,将当前仓库作为 feed,仅构建 package/ustb-cli
3+
4+
name: OpenWrt Package Build
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
release:
12+
types: [ published ]
13+
14+
jobs:
15+
openwrt-build:
16+
name: rockchip-armv8 ${{ matrix.version }}
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
version: [ "24.10" ]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
submodules: recursive
31+
32+
- name: Build OpenWrt package
33+
uses: immortalwrt/gh-action-sdk@master
34+
env:
35+
ARCH: rockchip-armv8-openwrt-${{ matrix.version }}
36+
FEEDNAME: ustb_cli_c
37+
PACKAGES: ustb-cli
38+
39+
- name: Upload .ipk artifacts
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: openwrt-rockchip-armv8-${{ matrix.version }}-packages
43+
path: bin/packages/*/packages/*.ipk
44+
45+
- name: Upload to GitHub Release
46+
if: github.event_name == 'release'
47+
uses: softprops/action-gh-release@v2
48+
with:
49+
tag_name: ${{ github.event.release.tag_name }}
50+
files: bin/packages/*/packages/*.ipk
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 使用 openwrt-package-mirror-hash-calculator 计算 PKG_MIRROR_HASH 并提交
2+
# 发布新版本前手动运行此 workflow,更新 package/ustb-cli/Makefile 中的 PKG_MIRROR_HASH
3+
4+
name: Update PKG_MIRROR_HASH
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
target_version:
10+
description: 'OpenWrt version (e.g. 24.10). Empty for simple mode.'
11+
required: false
12+
type: string
13+
14+
jobs:
15+
update-hash:
16+
name: Calculate and commit PKG_MIRROR_HASH
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.ref_name }}
26+
fetch-depth: 0
27+
submodules: recursive
28+
29+
- name: Calculate PKG_MIRROR_HASH
30+
uses: muink/openwrt-package-mirror-hash-calculator@main
31+
env:
32+
COMMIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
MAKEFILE: package/ustb-cli/Makefile
34+
TARGET_VERSION: ${{ inputs.target_version }}

package/ustb-cli/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PKG_NAME:=ustb-cli
4+
PKG_VERSION:=1.3.9
5+
PKG_RELEASE:=1
6+
7+
PKG_SOURCE_PROTO:=git
8+
PKG_SOURCE_URL:=https://github.com/Jason23347/ustb-cli-c.git
9+
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
10+
# 启用 submodule:github_archive 不支持,会 fallback 到 rawgit;rawgit 打包时会包含这些 submodule
11+
PKG_SOURCE_SUBMODULES:=external/cargs external/linenoise
12+
PKG_MIRROR_HASH:=7307a33b130c66c19fce6b5347247c3cb8857675cf10ff7083c245ef445bb6cb
13+
# 跳过 mirror 下载,直接从 git clone(镜像站无此包时会卡住)
14+
PKG_SOURCE_MIRROR:=1
15+
PKG_MIRROR:=0
16+
17+
PKG_MAINTAINER:=Shuaicheng Zhu <jason23347@163.com>
18+
PKG_LICENSE:=MIT
19+
PKG_LICENSE_FILES:=LICENSE
20+
21+
include $(INCLUDE_DIR)/package.mk
22+
include $(INCLUDE_DIR)/cmake.mk
23+
24+
define Package/ustb-cli
25+
SECTION:=net
26+
CATEGORY:=Network
27+
TITLE:=USTB campus network CLI
28+
DEPENDS:=+libopenssl
29+
URL:=https://github.com/Jason23347/ustb-cli-c
30+
endef
31+
32+
define Package/ustb-cli/description
33+
USTB campus network command-line client (login, balance, speedtest, etc.)
34+
endef
35+
36+
CMAKE_OPTIONS += \
37+
-DWITH_BALANCE=on \
38+
-DWITH_ACCOUNT=on \
39+
-DWITH_SPEEDTEST=on \
40+
-DWITH_COMPLETION=off \
41+
-DGB2312_DECODER=disabled \
42+
-DUSE_INTERACTIVE=off \
43+
-DUSE_THREADS=on \
44+
-DWITH_COLOR=on
45+
46+
# 不覆盖 Build/Prepare:rawgit 打包时已包含 submodule,解压后无 .git 无法再执行 git submodule
47+
48+
define Package/ustb-cli/install
49+
$(INSTALL_DIR) $(1)/usr/bin
50+
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ustb-cli $(1)/usr/bin/
51+
endef
52+
53+
$(eval $(call BuildPackage,ustb-cli))

0 commit comments

Comments
 (0)