This commit is contained in:
shanshanzhong 2025-09-25 09:29:54 -07:00
parent 330a8c128b
commit 6524911c31

View File

@ -1,146 +1,84 @@
name: Publish Release Assets
run-name: Build and publish web assets and Docker images
name: CI
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "apps/**"
- "packages/**"
- "package.json"
- "turbo.json"
- ".gitea/workflows/*.yml"
- cicd
pull_request:
types: [opened, synchronize, reopened]
paths:
- "apps/**"
- "packages/**"
- "package.json"
- "turbo.json"
- ".gitea/workflows/*.yml"
release:
types: [published]
branches:
- cicd
env:
# Gitea
GIT_USERNAME: ${{ vars.GIT_USERNAME }}
GIT_PASSWORD: ${{ vars.GIT_PASSWORD }}
# Docker Hub
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
# Host SSH (用于上传构建产物)
SSH_HOST: ${{ vars.SSH_HOST }}
SSH_PORT: ${{ vars.SSH_PORT }}
SSH_USER: ${{ vars.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOMAIN_URL: git.kxsw.us #*修改为你12
REPO: ${{ vars.REPO }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
DOCKER_REGISTRY: registry.kxsw.us
jobs:
publish:
name: Publish Release Assets
runs-on: ubuntu-latest
build:
runs-on: ppanel-web02
container:
image: node:20
strategy:
matrix:
# 只有node支持版本号别名
node: ['20.15.1']
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Checkout code
uses: https://gitea.cn/actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'
- 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: Cache Bun dependencies
uses: actions/cache@v3
with:
path: |
~/.bun
key: ${{ runner.os }}-bun-cache-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-cache-
- 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: Install deps
run: bun install --cache
- 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: Build
- name: Install dependencies (bun)
run: bun install
- name: Run Build Project (turbo via bun)
run: bun run build
- name: Run publish script
run: |
chmod +x scripts/publish.sh
./scripts/publish.sh
- name: Run Build Docker
run: make build
- name: Upload tar.gz file to release
if: ${{ gitea.event_name == 'release' }}
uses: softprops/action-gh-release@v2
- name: Push Docker Images
run: make push
- name: Notify success to Telegram
uses: chapvic/telegram-notify@master
if: success()
with:
files: |
out/ppanel-admin-web.tar.gz
out/ppanel-user-web.tar.gz
token: ${{ secrets.GITEA_TOKEN }}
token: ${{ env.TELEGRAM_BOT_TOKEN }}
chat: ${{ env.TELEGRAM_CHAT_ID }}
status: ${{ job.status }}
title: ✅ 构建成功
message: ${{ github.repository }} 构建成功 · 分支: ${{ github.ref }} · 提1交: ${{ github.sha }}
footer: 触发者: ${{ github.actor }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install jq
run: sudo apt-get install -y jq
- name: Extract version from package.json
id: version
run: echo "PPANEL_VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Build and push Docker image for ppanel-admin-web
uses: docker/build-push-action@v6
- name: Notify failure to Telegram
uses: chapvic/telegram-notify@master
if: failure()
with:
context: .
file: ./docker/ppanel-admin-web/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.DOCKER_USERNAME }}/ppanel-admin-web:latest
${{ env.DOCKER_USERNAME }}/ppanel-admin-web:${{ env.PPANEL_VERSION }}
- name: Build and push Docker image for ppanel-user-web
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/ppanel-user-web/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.DOCKER_USERNAME }}/ppanel-user-web:latest
${{ env.DOCKER_USERNAME }}/ppanel-user-web:${{ env.PPANEL_VERSION }}
- name: Upload to SSH server (if configured)
if: ${{ env.SSH_HOST != '' }}
uses: appleboy/ssh-action@v1
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
port: ${{ env.SSH_PORT }}
script: |
mkdir -p ~/releases/${{ gitea.ref_name || 'latest' }}
- name: Upload files via SCP (if SSH configured)
if: ${{ env.SSH_HOST != '' }}
uses: appleboy/scp-action@v1
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
port: ${{ env.SSH_PORT }}
source: "out/*.tar.gz"
target: "~/releases/${{ gitea.ref_name || 'latest' }}/"
- name: Upload artifacts to Gitea
uses: actions/upload-artifact@v3
with:
name: ppanel-web-assets
path: |
out/ppanel-admin-web.tar.gz
out/ppanel-user-web.tar.gz
token: ${{ env.TELEGRAM_BOT_TOKEN }}
chat: ${{ env.TELEGRAM_CHAT_ID }}
status: ${{ job.status }}
title: ❌ 构建失败
message: ${{ github.repository }} 构建失败 · 分支: ${{ github.ref }} · 提交: ${{ github.sha }}
footer: 触发者: ${{ github.actor }}