Skip to content
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

ci(pr): use pnpm #3405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
86 changes: 82 additions & 4 deletions .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,85 @@ on:
- completed

jobs:
call-preview:
uses: Tencent/tdesign/.github/workflows/preview.yml@main
secrets:
TDESIGN_SURGE_TOKEN: ${{ secrets.TDESIGN_SURGE_TOKEN }}
preview-success:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
- name: download _site artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: _site
- run: |
unzip _site.zip
- name: Upload surge service and generate preview URL
id: deploy
run: |
repository=${{github.repository}}
project_name=${repository#*/}
export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-$project_name.surge.sh
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
- name: update status comment
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
<a href="${{steps.deploy.outputs.url}}"><img height="96" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" /></a>
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

- run: |
rm -rf _site/
- name: The job failed
if: ${{ failure() }}
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

preview-failed:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
- name: The job failed
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
161 changes: 158 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 文件名建议统一为 pull-request.yml
# 文件名建议统一为 pull-request.yml
# 应用 test-build.yml 的 demo

name: MAIN_PULL_REQUEST
Expand All @@ -9,5 +9,160 @@ on:
types: [opened, synchronize, reopened]

jobs:
call-test-build:
uses: Tencent/tdesign/.github/workflows/test-build.yml@main
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: check_github_primary_email
run: |
log_emails=$(git log --pretty=format:"%ae %ce" -1)
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "默认邮箱 $log_emails 校验非法,可以去 https://github.com/settings/emails 更改"
exit 2;
else
echo "邮箱 $log_emails 校验通过";
fi
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: check_local_email
run: |
log_emails=$(git log --pretty=format:"%ae %ce" -1)
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "本地提交邮箱 $log_emails 校验非法,需要本地更改重新提交"
exit 2;
else
echo "邮箱 $log_emails 校验通过";
fi
test:
# needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version-file: .node-version

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install
- run: pnpm run lint
- run: pnpm run test
# upload report to codecov
- uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}

site:
runs-on: ubuntu-latest
# needs: test
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version-file: .node-version

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install

- name: Build site
run: pnpm site:preview

- run: |
zip -r _site.zip _site
- name: upload _site artifact
uses: actions/upload-artifact@v4
with:
name: _site
path: _site.zip
retention-days: 5

- name: Save PR number
if: ${{ always() }}
run: echo ${{ github.event.number }} > ./pr-id.txt

- name: Upload PR number
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: pr
path: ./pr-id.txt

build:
runs-on: ubuntu-latest
# needs: build
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install

- name: Build
run: pnpm run build
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "tdesign-react",
"packageManager": "pnpm@9.5.0",
"purename": "tdesign",
"version": "1.11.1",
"description": "TDesign Component for React",
Expand Down
20 changes: 16 additions & 4 deletions packages/components/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { debounce, DebounceSettings } from 'lodash-es';
import { debounce } from 'lodash-es';
import { useCallback, useEffect } from 'react';
import { usePersistFn } from './usePersistFn';

interface DebounceSettingsLeading extends DebounceSettings {
// https://tsdocs.dev/docs/lodash-es/4.17.21/interfaces/_internal_.DebounceSettingsLeading.html
interface DebounceSettingsLeading {
leading: true;
maxWait?: number;
trailing?: boolean;
}

const useDebounce = <T extends (...args: any) => any>(func: T, delay: number, options?: DebounceSettingsLeading) => {
// https://tsdocs.dev/docs/lodash-es/4.17.21/interfaces/_internal_.DebouncedFuncLeading.html
interface DebouncedFuncLeading<T extends (...args: unknown[]) => unknown> {
cancel(): void;
flush(): ReturnType<T>;
(...args): ReturnType<T>;
}
const useDebounce = <T extends (...args: unknown[]) => unknown>(
func: T,
delay: number,
options?: DebounceSettingsLeading,
): DebouncedFuncLeading<T> => {
const callback = usePersistFn(func);

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down