Skip to content

Dev

Dev #9

Workflow file for this run

# 工作流名称
name: Frontend CI
# 触发条件
on:
# 当代码 push 到 main/master 分支时自动执行
push:
branches: [ "main", "master" ]
# 当提交 Pull Request 到 main/master 时自动执行
pull_request:
branches: [ "main", "master" ]
jobs:
build:
# 运行环境:GitHub 提供的 Ubuntu 虚拟机
runs-on: ubuntu-latest
steps:
# 第一步:拉取 GitHub 仓库代码到 Runner
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
# 拉取完整 git 历史
# SonarCloud 分析代码变更时需要
fetch-depth: 0
# 第二步:安装 Node.js 环境
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
# 使用 Node.js 20 LTS 版本
node-version: 20
# 开启 npm 依赖缓存
# 加快后续 CI 构建速度
cache: npm
# 第三步:安装前端依赖
- name: Install dependencies
# npm ci:
# 严格按照 package-lock.json 安装依赖
# 比 npm install 更稳定、更适合 CI
run: npm ci
# 第四步:构建前端项目
- name: Build project
# 执行 package.json 中的 build 命令
# 一般对应:
# vue-tsc -b && vite build
#
# 包含:
# 1. TypeScript 类型检查
# 2. Vite 正式环境打包
run: npm run build
# 第五步:SonarCloud 代码质量扫描
- name: SonarCloud Scan
# 官方 SonarCloud GitHub Action
uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6
# 环境变量
env:
# 从 GitHub Secrets 中读取 SONAR_TOKEN
# 避免 Token 泄露
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
# SonarCloud 项目参数
args: >
-Dsonar.projectKey=huangkai12358_service-governance-frontend
-Dsonar.organization=huangkai12358
-Dsonar.projectName=service-governance-frontend
-Dsonar.sources=src
-Dsonar.exclusions=node_modules/**,dist/**
# 第六步:上传前端构建产物
- name: Upload build artifacts
# GitHub 官方 Artifact 上传 Action
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
# Artifact 名称
name: frontend-dist
# 上传 dist 打包目录
# 后续可以在 Actions 页面直接下载
path: dist/