Skip to content

ci: test ninja2 sharebuild #16

ci: test ninja2 sharebuild

ci: test ninja2 sharebuild #16

Workflow file for this run

name: ninja2-CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main
jobs:
build:
runs-on: ubuntu-22.04
# services:
# redis:
# image: redis
# ports:
# - 6379:6379
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 3
steps:
# 1. 检出代码
- name: Checkout repository
uses: actions/checkout@v3
# 2. 配置 apt 使用更快的镜像源(可选,根据地域选择)
- name: Configure apt to use faster mirrors
run: |
sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sudo apt-get update
# 3. 缓存 apt 包
# - name: Cache apt packages
# id: apt-cache
# uses: actions/cache@v3
# with:
# path: |
# /var/cache/apt
# /var/lib/apt
# key: ${{ runner.os }}-apt-${{ hashFiles('**/build.sh') }}
# restore-keys: |
# ${{ runner.os }}-apt-
# 4. 安装依赖
- name: Install dependencies
# if: steps.apt-cache.outputs.cache-hit != 'true' (仅在缓存未命中时)
run: |
sudo apt-get update
sudo apt-get install -y git cmake g++ gcc googletest libgmock-dev libssl-dev pkg-config uuid-dev grpc++ libprotobuf-dev protobuf-compiler-grpc ninja-build libyaml-cpp-dev
# # 5. 缓存 CMake 和构建产物(可选)
# - name: Cache CMake and build
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache
# build
# key: ${{ runner.os }}-cmake-${{ hashFiles('**/CMakeLists.txt') }}
# restore-keys: |
# ${{ runner.os }}-cmake-
# 6. 运行构建脚本
- name: Build ninja2
run: |
chmod +x build.sh
./build.sh build
# 7. 安装构建好的 ninja2
- name: Install ninja2
run: |
sudo ./build.sh install
# 8. 验证 ninja2 安装
- name: Verify ninja2 installation
run: |
ninja --version
# 9. 运行 Ninja 单元测试套件
- name: Run Ninja unit-test suite
run: |
cd build/bin
ctest --output-on-failure
# 10. 克隆 re2 项目
- name: Clone re2 repository
run: |
wget https://github.com/google/re2/archive/refs/tags/2021-11-01.tar.gz
tar -zxvf 2021-11-01.tar.gz
mv re2-2021-11-01 re2
# 11. 使用 ninja2 构建 re2 项目 (re2 项目较小,快速验证效果)
- name: Local Build re2 with ninja2
run: |
cd re2
mkdir -p build
cd build
cmake -G Ninja ..
ninja
# 12. 运行 re2 测试
- name: Test re2 build
run: |
cd re2/build
./re2_test
# ctest --output-on-failure
## 分布式构建 re2 项目
# 13. 启动 scheduler
- name: start scheduler
run: |
# 设置环境变量
SCHEDULER_HOST=localhost
REDIS_HOST=localhost
REDIS_PORT=6379
# 安装依赖
# sudo apt-get update
sudo apt-get install -y nfs-kernel-server redis-server
# 配置并启动 Redis
sudo systemctl enable redis-server
sudo systemctl restart redis-server
# 创建必要的文件夹
mkdir -p ~/sharebuild-bin/
wget https://github.com/chanfun-ren/ninja2/releases/download/ninja2_ci_test/scheduler
chmod +x ./scheduler
cp ./scheduler ~/sharebuild-bin
# 配置 Scheduler
sudo mkdir -p /etc/scheduler
cat <<EOF | sudo tee /etc/scheduler/config.yaml > /dev/null
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ''
db: 0
taskServer:
port: 8002
license:
code: ShareBuild1234
VerifyService:
host: 106.54.183.229
port: 8004
EOF
# 启动 Scheduler
# ~/sharebuild-bin/scheduler -config /etc/scheduler/config.yaml &
nohup ~/sharebuild-bin/scheduler -config /etc/scheduler/config.yaml > scheduler.log 2>&1 &
# 14. 启动 executor
- name: start executor
run: |
# 环境变量配置
REDIS_HOST=localhost
REDIS_PORT=6379
SCHEDULER_HOST=localhost
mkdir -p ~/sharebuild-bin
wget https://github.com/chanfun-ren/ninja2/releases/download/ninja2_ci_test/executor
chmod +x ./executor
cp ./executor ~/sharebuild-bin
# 配置 Executor
sudo mkdir -p /etc/executor
cat <<EOF | sudo tee /etc/executor/config.yaml > /dev/null
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ''
db: 0
taskServer:
port: 8003
user: $(whoami)
schedulerRegisterServer:
host: ${SCHEDULER_HOST}
port: 8002
EOF
# 启动 Executor
# ~/sharebuild-bin/executor -config /etc/executor/config.yaml &
sudo nohup ~/sharebuild-bin/executor -config /etc/executor/config.yaml > executor.log 2>&1 &
# 15. ninja2 分布式 sharebuild 模式编译 re2
- name: sharebuild re2
run: |
# 环境变量配置
SCHEDULER_HOST=localhost
# 安装依赖
sudo apt-get install -y nfs-kernel-server
# 配置 NFS
echo "/home *(rw,no_root_squash,anonuid=1000,anongid=1000,insecure,async,no_subtree_check)" | sudo tee -a /etc/exports
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
# # 下载测试项目 re2
# wget https://github.com/google/re2/archive/refs/tags/2021-11-01.tar.gz
# tar -zxvf 2021-11-01.tar.gz
# mv re2-2021-11-01 re2
# 分布式测试编译 re2
cd re2
rm -rf build
mkdir -p build
cd build
cmake -G Ninja ..
ninja -s ${SCHEDULER_HOST}:8002 -r "$(realpath ../)"
# 显示日志文件内容
- name: Show executor logs
run: cat executor.log
- name: Show scheduler logs
run: cat scheduler.log
# debug
- name: debug network
run: |
netstat -tuln | grep 8003
curl -v --connect-timeout 5 http://localhost:8003