Skip to content

chore: ci auto branch label 【support current repo】 #2687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 65 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,95 @@ on:
workflow_dispatch:

jobs:
label:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Determine label
id: determine_label
run: |
if [[ "${{ github.event.pull_request.base.ref }}" == "next" ]]; then
echo "label=2.x" >> $GITHUB_ENV
elif [[ "${{ github.event.pull_request.base.ref }}" == "V3.0" ]]; then
echo "label=3.x" >> $GITHUB_ENV
fi

- name: Add label to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.label }}
Comment on lines +15 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

需要改进自动标签工作流的健壮性

当前实现存在以下问题:

  1. 没有处理基础分支不是 'next' 或 'V3.0' 的情况
  2. 在 push 事件时也会运行,但此时没有 PR 上下文
  3. Shell 脚本中的变量引用需要加引号以提高安全性

建议应用以下修改:

  label:
    runs-on: ubuntu-latest
+   if: github.event_name == 'pull_request'
    steps:
      - name: Check out the repository
        uses: actions/checkout@v4

      - name: Determine label
        id: determine_label
        run: |
          if [[ "${{ github.event.pull_request.base.ref }}" == "next" ]]; then
-           echo "label=2.x" >> $GITHUB_ENV
+           echo "label=2.x" >> "$GITHUB_ENV"
          elif [[ "${{ github.event.pull_request.base.ref }}" == "V3.0" ]]; then
-           echo "label=3.x" >> $GITHUB_ENV
+           echo "label=3.x" >> "$GITHUB_ENV"
+         else
+           echo "label=pending-review" >> "$GITHUB_ENV"
          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
label:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Determine label
id: determine_label
run: |
if [[ "${{ github.event.pull_request.base.ref }}" == "next" ]]; then
echo "label=2.x" >> $GITHUB_ENV
elif [[ "${{ github.event.pull_request.base.ref }}" == "V3.0" ]]; then
echo "label=3.x" >> $GITHUB_ENV
fi
- name: Add label to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.label }}
label:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Determine label
id: determine_label
run: |
if [[ "${{ github.event.pull_request.base.ref }}" == "next" ]]; then
echo "label=2.x" >> "$GITHUB_ENV"
elif [[ "${{ github.event.pull_request.base.ref }}" == "V3.0" ]]; then
echo "label=3.x" >> "$GITHUB_ENV"
else
echo "label=pending-review" >> "$GITHUB_ENV"
fi
- name: Add label to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.label }}
🧰 Tools
🪛 actionlint

24-24: shellcheck reported issue in this script: SC2086:info:2:23: Double quote to prevent globbing and word splitting

(shellcheck)


24-24: shellcheck reported issue in this script: SC2086:info:4:23: Double quote to prevent globbing and word splitting

(shellcheck)

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Install pnpm
run: corepack enable pnpm
- name: Install pnpm
run: corepack enable pnpm

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Install dependencies
run: pnpm install

- name: Run linter
run: npm run lint
- name: Run linter
run: npm run lint
Comment on lines +39 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议优化缓存配置以提升 CI 性能

当前的缓存配置仅使用了基本的 pnpm 缓存。建议添加更多缓存策略以提升构建速度。

建议应用以下优化:

      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'pnpm'
+         cache-dependency-path: '**/pnpm-lock.yaml'

      - name: Install dependencies
        run: pnpm install
+       env:
+         HUSKY: '0'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/checkout@v4
- name: Install pnpm
run: corepack enable pnpm
- name: Install pnpm
run: corepack enable pnpm
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Install dependencies
run: pnpm install
- name: Run linter
run: npm run lint
- name: Run linter
run: npm run lint
- uses: actions/checkout@v4
- name: Install pnpm
run: corepack enable pnpm
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- name: Install dependencies
run: pnpm install
env:
HUSKY: '0'
- name: Run linter
run: npm run lint


test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Install pnpm
run: corepack enable pnpm
- name: Install pnpm
run: corepack enable pnpm

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Install dependencies
run: pnpm install

- name: Run test
run: npm run test
- name: Run test
run: npm run test

- name: Upload coverage reports to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Comment on lines +74 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议增强测试报告配置

当前的 Codecov 配置可以进一步优化以提供更好的测试覆盖率报告。

建议添加以下配置:

      - name: Upload coverage reports to Codecov
        if: ${{ always() }}
        uses: codecov/codecov-action@v4
+       with:
+         fail_ci_if_error: true
+         verbose: true
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Upload coverage reports to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}


build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Install pnpm
run: corepack enable pnpm
- name: Install pnpm
run: corepack enable pnpm

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Install dependencies
run: pnpm install

- name: Build NutUI-React
run: npm run build
- name: Build NutUI-React
run: npm run build

- name: Build NutUI-React-Taro
run: npm run build:taro
- name: Build NutUI-React-Taro
run: npm run build:taro

- name: Build NutUI-React Demo
run: npm run build:site
- name: Build NutUI-React Demo
run: npm run build:site

- name: Build NutUI-React Taro H5 Demo
run: npm run build:taro:site
- name: Build NutUI-React Taro H5 Demo
run: npm run build:taro:site
Loading