mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 06:33:37 +08:00
112 lines
3.4 KiB
YAML
112 lines
3.4 KiB
YAML
name: "完整CI/CD流程"
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: docker-registry.bjxgj.com
|
|
NODE_VERSION: "18"
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
name: "代码测试"
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置Node.js环境
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- name: 安装依赖
|
|
uses: actions/xgj/npm-install@main
|
|
with:
|
|
package-manager: "npm"
|
|
|
|
- name: 代码检查
|
|
run: |
|
|
npm run lint
|
|
npm run type-check
|
|
|
|
- name: 运行测试
|
|
run: npm run test:ci
|
|
|
|
- name: 构建项目
|
|
run: npm run build
|
|
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
name: "发布构建"
|
|
needs: test
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: 设置构建环境
|
|
uses: actions/xgj/setup-env@main
|
|
with:
|
|
docker-registry: ${{ env.REGISTRY }}
|
|
docker-password: ${{ secrets.DOCKER_PASSWORD }}
|
|
kube-config: ${{ secrets.KUBE_CONFIG }}
|
|
|
|
- name: 安装依赖
|
|
uses: actions/xgj/npm-install@main
|
|
with:
|
|
package-manager: "npm"
|
|
cache-prefix: "release"
|
|
|
|
- name: 发布构建
|
|
id: release
|
|
uses: actions/xgj/release-web@main
|
|
with:
|
|
gitea-token: ${{ secrets.GITEA_TOKEN }}
|
|
app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'develop' }}
|
|
sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
sentry-dsn: ${{ vars.SENTRY_DSN }}
|
|
enable-sentry: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}
|
|
docker-registry: ${{ env.REGISTRY }}
|
|
dockerfile-path: "./Dockerfile"
|
|
docker-tags: |
|
|
${{ github.sha }}
|
|
${{ github.ref_name }}
|
|
${{ github.ref == 'refs/heads/main' && 'stable' || 'unstable' }}
|
|
|
|
- name: 部署到Kubernetes (生产环境)
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
echo "🚀 部署到生产环境..."
|
|
kubectl set image deployment/web-app \
|
|
web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \
|
|
-n production
|
|
kubectl rollout status deployment/web-app -n production
|
|
|
|
- name: 部署到Kubernetes (开发环境)
|
|
if: github.ref == 'refs/heads/develop'
|
|
run: |
|
|
echo "🧪 部署到开发环境..."
|
|
kubectl set image deployment/web-app-dev \
|
|
web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \
|
|
-n development
|
|
kubectl rollout status deployment/web-app-dev -n development
|
|
|
|
- name: 通知发布结果
|
|
run: |
|
|
echo "🎉 发布完成!"
|
|
echo "📦 版本: ${{ steps.release.outputs.version }}"
|
|
echo "🌍 环境: ${{ github.ref == 'refs/heads/main' && '生产环境' || '开发环境' }}"
|
|
echo "🐳 Docker镜像: ${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }}"
|