Skip to content

ci: 更新CI/CD工作流配置并移除旧的工作流 #9

ci: 更新CI/CD工作流配置并移除旧的工作流

ci: 更新CI/CD工作流配置并移除旧的工作流 #9

Workflow file for this run

name: Frontend CI
# Trigger: PR to main/develop branches, only when frontend files change
# 🚧 TEMPORARY: paths filter disabled for testing
on:
pull_request:
branches:
- main
- develop
# paths:
# - 'himarket-web/himarket-frontend/**'
# - 'himarket-web/himarket-admin/**'
# - '.github/workflows/frontend-ci.yml'
# Avoid duplicate runs: new commits to the same PR will cancel previous runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Limit workflow permissions (security best practice)
permissions:
contents: read
pull-requests: write
checks: write
jobs:
# Detect which parts of the codebase changed
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
admin: ${{ steps.filter.outputs.admin }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for file changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
frontend:
- 'himarket-web/himarket-frontend/**'
admin:
- 'himarket-web/himarket-admin/**'
# Job 1: HiMarket Frontend - Lint Check
himarket-frontend-lint:
name: Frontend - Lint Check
runs-on: ubuntu-latest
needs: changes
# 🚧 TEMPORARY: condition disabled for testing
# if: needs.changes.outputs.frontend == 'true'
defaults:
run:
working-directory: himarket-web/himarket-frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-frontend/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Run ESLint
id: eslint
run: npm run lint || echo "ESLINT_FAILED=true" >> $GITHUB_ENV
continue-on-error: true # ⚠️ TEMPORARY: Allow lint errors for now
- name: Run TypeScript type check
id: typecheck
run: npm run type-check || echo "TYPECHECK_FAILED=true" >> $GITHUB_ENV
continue-on-error: true # ⚠️ TEMPORARY: Allow type errors for now
- name: Create check summary
if: always()
run: |
if [ "${ESLINT_FAILED}" == "true" ] || [ "${TYPECHECK_FAILED}" == "true" ]; then
echo "## ⚠️ Frontend Lint Check Has Issues" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> **Note:** Lint errors are currently allowed to pass (temporary setting)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Your frontend code has ESLint or TypeScript type errors that should be fixed." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔧 How to check:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Navigate to the frontend directory:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo 'cd himarket-web/himarket-frontend' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "2. Run lint check to see specific errors:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo 'npm run lint' >> $GITHUB_STEP_SUMMARY
echo 'npm run type-check' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "3. Fix the errors when ready (not blocking PR for now)" >> $GITHUB_STEP_SUMMARY
else
echo "## ✅ Frontend Lint Check Passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "ESLint and TypeScript checks completed successfully!" >> $GITHUB_STEP_SUMMARY
fi
# Job 2: HiMarket Frontend - Build Check
himarket-frontend-build:
name: Frontend - Build Check
runs-on: ubuntu-latest
needs: [changes, himarket-frontend-lint]
# 🚧 TEMPORARY: condition disabled for testing
# if: needs.changes.outputs.frontend == 'true'
defaults:
run:
working-directory: himarket-web/himarket-frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-frontend/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Build project
run: npm run build
env:
NODE_ENV: production
- name: Verify build artifacts
run: |
if [ ! -d "dist" ]; then
echo "❌ Build failed: dist directory does not exist"
exit 1
fi
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed: dist/index.html does not exist"
exit 1
fi
echo "✅ Build artifacts verified"
- name: Upload build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: himarket-frontend-build
path: himarket-web/himarket-frontend/dist/
retention-days: 7
# Job 3: HiMarket Admin - Lint Check
himarket-admin-lint:
name: Admin - Lint Check
runs-on: ubuntu-latest
needs: changes
# 🚧 TEMPORARY: condition disabled for testing
# if: needs.changes.outputs.admin == 'true'
defaults:
run:
working-directory: himarket-web/himarket-admin
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-admin/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Run ESLint
id: eslint
run: npm run lint || echo "ADMIN_ESLINT_FAILED=true" >> $GITHUB_ENV
continue-on-error: true # ⚠️ TEMPORARY: Allow lint errors for now
- name: Create check summary
if: always()
run: |
if [ "${ADMIN_ESLINT_FAILED}" == "true" ]; then
echo "## ⚠️ Admin Lint Check Has Issues" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> **Note:** Lint errors are currently allowed to pass (temporary setting)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Your admin console code has ESLint errors that should be fixed." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔧 How to check:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Navigate to the admin console directory:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo 'cd himarket-web/himarket-admin' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "2. Run lint check to see specific errors:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo 'npm run lint' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "3. Fix the errors when ready (not blocking PR for now)" >> $GITHUB_STEP_SUMMARY
else
echo "## ✅ Admin Lint Check Passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "ESLint check completed successfully!" >> $GITHUB_STEP_SUMMARY
fi
# Job 4: HiMarket Admin - Build Check
himarket-admin-build:
name: Admin - Build Check
runs-on: ubuntu-latest
needs: [changes, himarket-admin-lint]
# 🚧 TEMPORARY: condition disabled for testing
# if: needs.changes.outputs.admin == 'true'
defaults:
run:
working-directory: himarket-web/himarket-admin
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-admin/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Build project
run: npm run build
env:
NODE_ENV: production
- name: Verify build artifacts
run: |
if [ ! -d "dist" ]; then
echo "❌ Build failed: dist directory does not exist"
exit 1
fi
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed: dist/index.html does not exist"
exit 1
fi
echo "✅ Build artifacts verified"
- name: Upload build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: himarket-admin-build
path: himarket-web/himarket-admin/dist/
retention-days: 7
# Summary of all check results
frontend-ci-summary:
name: Frontend CI Summary
runs-on: ubuntu-latest
needs: [changes, himarket-frontend-lint, himarket-frontend-build, himarket-admin-lint, himarket-admin-build]
if: always()
steps:
- name: Check all task status
uses: actions/github-script@v7
with:
script: |
const jobs = [
{ name: 'Frontend - Lint Check', status: '${{ needs.himarket-frontend-lint.result }}' },
{ name: 'Frontend - Build Check', status: '${{ needs.himarket-frontend-build.result }}' },
{ name: 'Admin - Lint Check', status: '${{ needs.himarket-admin-lint.result }}' },
{ name: 'Admin - Build Check', status: '${{ needs.himarket-admin-build.result }}' }
];
let summary = '## 🎨 Frontend CI Check Summary\n\n';
let allPassed = true;
let hasSkipped = false;
jobs.forEach(job => {
if (job.status === 'success') {
summary += `✅ **${job.name}**: Passed\n`;
} else if (job.status === 'skipped') {
summary += `⏭️ **${job.name}**: Skipped (no related changes)\n`;
hasSkipped = true;
} else if (job.status === 'failure') {
summary += `❌ **${job.name}**: Failed\n`;
allPassed = false;
} else {
summary += `⚠️ **${job.name}**: ${job.status}\n`;
allPassed = false;
}
});
summary += '\n---\n\n';
if (allPassed) {
summary += '🎉 **All checks passed!** Your PR is ready for review.\n';
} else {
summary += '⚠️ **Some checks failed**. Please review the failed tasks above and fix the issues.\n';
if (hasSkipped) {
summary += '\n📝 _Note: Some checks were skipped because no related files were changed._\n';
}
}
await core.summary
.addRaw(summary)
.write();
console.log(summary);
// Fail the workflow if any check failed, regardless of skipped jobs
if (!allPassed) {
core.setFailed('Some frontend CI checks failed');
}