132 lines
4.6 KiB
YAML
132 lines
4.6 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- cicd
|
|
pull_request:
|
|
branches:
|
|
- cicd
|
|
|
|
env:
|
|
DOMAIN_URL: git.kxsw.us #*修改为你12
|
|
REPO: ${{ vars.REPO }}
|
|
TELEGRAM_BOT_TOKEN: 8114337882:AAHkEx03HSu7RxN4IHBJJEnsK9aPPzNLIk0
|
|
TELEGRAM_CHAT_ID: 4940243803
|
|
DOCKER_REGISTRY: registry.kxsw.us
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ppanel-web02
|
|
container:
|
|
image: node:20
|
|
strategy:
|
|
matrix:
|
|
# 只有node支持版本号别名
|
|
node: ['20.15.1']
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: https://gitea.cn/actions/checkout@v4
|
|
|
|
- name: Install system tools (jq, docker, curl)
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y jq curl ca-certificates docker.io
|
|
docker --version
|
|
jq --version
|
|
curl --version
|
|
|
|
- name: Install Bun
|
|
run: |
|
|
curl -fsSL https://bun.sh/install | bash
|
|
echo "BUN_INSTALL=/root/.bun" >> $GITHUB_ENV
|
|
echo "PATH=/root/.bun/bin:${PATH}" >> $GITHUB_ENV
|
|
/root/.bun/bin/bun --version
|
|
|
|
- name: Configure npm registry (npmmirror) and canvas mirror
|
|
run: |
|
|
echo "registry=https://registry.npmmirror.com" >> .npmrc
|
|
echo "canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas" >> .npmrc
|
|
|
|
- name: Install dependencies (bun)
|
|
run: bun install
|
|
|
|
- name: Decide build target (admin/user/both)
|
|
run: |
|
|
set -e
|
|
COMMIT_MSG="${{ github.event.head_commit.message }}"
|
|
BUILD_TARGET="both"
|
|
if echo "$COMMIT_MSG" | grep -qi "\[admin-only\]"; then
|
|
BUILD_TARGET="admin"
|
|
elif echo "$COMMIT_MSG" | grep -qi "\[user-only\]"; then
|
|
BUILD_TARGET="user"
|
|
else
|
|
if git rev-parse HEAD^ >/dev/null 2>&1; then
|
|
RANGE="HEAD^..HEAD"
|
|
else
|
|
RANGE="$(git rev-list --max-parents=0 HEAD)..HEAD"
|
|
fi
|
|
CHANGED=$(git diff --name-only $RANGE || true)
|
|
ADMIN_MATCH=$(echo "$CHANGED" | grep -E '^(apps/admin/|docker/ppanel-admin-web/)' || true)
|
|
USER_MATCH=$(echo "$CHANGED" | grep -E '^(apps/user/|docker/ppanel-user-web/)' || true)
|
|
PACKAGE_MATCH=$(echo "$CHANGED" | grep -E '^(packages/|turbo.json|package.json|bun.lock)' || true)
|
|
if [ -n "$PACKAGE_MATCH" ]; then
|
|
BUILD_TARGET="both"
|
|
else
|
|
if [ -n "$ADMIN_MATCH" ] && [ -z "$USER_MATCH" ]; then BUILD_TARGET="admin"; fi
|
|
if [ -n "$USER_MATCH" ] && [ -z "$ADMIN_MATCH" ]; then BUILD_TARGET="user"; fi
|
|
if [ -n "$ADMIN_MATCH" ] && [ -n "$USER_MATCH" ]; then BUILD_TARGET="both"; fi
|
|
fi
|
|
fi
|
|
echo "BUILD_TARGET=$BUILD_TARGET" >> $GITHUB_ENV
|
|
echo "Decided BUILD_TARGET=$BUILD_TARGET"
|
|
|
|
- name: Build Admin (turbo via bun)
|
|
if: env.BUILD_TARGET == 'admin' || env.BUILD_TARGET == 'both'
|
|
run: bun run build --filter=ppanel-admin-web
|
|
|
|
- name: Build User (turbo via bun)
|
|
if: env.BUILD_TARGET == 'user' || env.BUILD_TARGET == 'both'
|
|
run: bun run build --filter=ppanel-user-web
|
|
|
|
- name: Build Docker (admin)
|
|
if: env.BUILD_TARGET == 'admin' || env.BUILD_TARGET == 'both'
|
|
run: make build-admin
|
|
|
|
- name: Build Docker (user)
|
|
if: env.BUILD_TARGET == 'user' || env.BUILD_TARGET == 'both'
|
|
run: make build-user
|
|
|
|
- name: Login to Docker Registry
|
|
env:
|
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
run: |
|
|
echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
|
|
|
|
- name: Push Docker Images
|
|
run: make push
|
|
|
|
- name: Notify success to Telegram
|
|
uses: chapvic/telegram-notify@master
|
|
if: success()
|
|
with:
|
|
token: ${{ env.TELEGRAM_BOT_TOKEN }}
|
|
chat: ${{ env.TELEGRAM_CHAT_ID }}
|
|
status: ${{ job.status }}
|
|
title: ✅ 构建成功
|
|
message: "${{ gitea.repository }} 构建成功 · 分支: ${{ gitea.ref }} · 提交: ${{ gitea.sha }}"
|
|
footer: "触发者: ${{ gitea.actor }}"
|
|
|
|
- name: Notify failure to Telegram
|
|
uses: chapvic/telegram-notify@master
|
|
if: failure()
|
|
with:
|
|
token: ${{ env.TELEGRAM_BOT_TOKEN }}
|
|
chat: ${{ env.TELEGRAM_CHAT_ID }}
|
|
status: ${{ job.status }}
|
|
title: ❌ 构建失败
|
|
message: "${{ gitea.repository }} 构建失败 · 分支: ${{ gitea.ref }} · 提交: ${{ gitea.sha }}"
|
|
footer: "触发者: ${{ gitea.actor }}"
|