Skip to content

Commit

Permalink
test: use unified github action yml (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
Layouwen authored Aug 28, 2024
1 parent edb2ab7 commit 471c86b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 767 deletions.
119 changes: 5 additions & 114 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,115 +1,6 @@
name: CI

on: ['push', 'pull_request']

name: ✅ test
on: [push, pull_request]
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

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

- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts

- name: hack for singe file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci

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

- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: lint
run: npm run lint

needs: setup

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

- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: compile
run: npm run compile

needs: setup

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

- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: coverage
run: npm test -- --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

needs: setup
test:
uses: react-component/rc-test/.github/workflows/test.yml@main
secrets: inherit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ coverage/

# dumi
.dumi/tmp
.dumi/tmp-production
.dumi/tmp-production

bun.lockb
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install]
peer = false
6 changes: 3 additions & 3 deletions docs/examples/cellRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default () => {
{...sharedProps}
locale={zhCN}
picker="time"
cellRender={(current, info) =>
cellRender={(current: number | string, info) =>
React.cloneElement(
info.originNode,
{
Expand All @@ -173,13 +173,13 @@ export default () => {
allowClear
showTime
style={{ width: 580 }}
cellRender={(current: Moment, info) => {
cellRender={(current, info) => {
return (
<div
title={info.type}
style={{ background: info.type === 'time' ? 'green' : 'yellow' }}
>
{info.type === 'time' ? current : current.get('date')}
{info.type === 'time' ? (current as number) : (current as Moment).get('date')}
</div>
);
}}
Expand Down
34 changes: 1 addition & 33 deletions docs/examples/customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,9 @@ interface DateRangeState {
endOpen: boolean;
initValue: Moment;
}
type PanelMode = 'time' | 'datetime' | 'date' | 'week' | 'month' | 'year' | 'decade';

const now = moment();

function disabledDate(current: Moment) {
// Can not select days before today
return current && current < moment().subtract(1, 'days').endOf('day');
}
function changePanelCallBack(value: Moment, mode: PanelMode) {
console.log(value, mode);
}
class Customize extends React.Component<{}, DateRangeState> {
poupContainerRef: React.RefObject<HTMLDivElement>;

Expand Down Expand Up @@ -109,7 +101,7 @@ class Customize extends React.Component<{}, DateRangeState> {
);

render() {
const { startValue, endValue, endOpen, initValue } = this.state;
const { startValue, endValue, endOpen } = this.state;
console.log('->', endOpen);
return (
<div>
Expand Down Expand Up @@ -141,30 +133,6 @@ class Customize extends React.Component<{}, DateRangeState> {
/>
<div ref={this.poupContainerRef} />
</div>
<div>
<h3>renderExtraFooter</h3>
<PickerPanel
generateConfig={momentGenerateConfig}
locale={zhCN}
showToday
disabledDate={disabledDate}
onSelect={this.handleSelect}
value={initValue}
onPanelChange={changePanelCallBack}
renderExtraFooter={(mode: PanelMode) => <div>{mode} extra footer</div>}
/>
</div>
<div>
<h3>month picker</h3>
<PickerPanel
generateConfig={momentGenerateConfig}
locale={zhCN}
picker="month"
defaultValue={now}
onSelect={this.handleSelectMonth}
renderExtraFooter={() => <div>extra footer</div>}
/>
</div>
<div>
<h3>monthCellRender</h3>
<PickerPanel
Expand Down
14 changes: 10 additions & 4 deletions docs/examples/rtl.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import moment, { type Moment } from 'moment';
import React from 'react';
import '../../assets/index.less';
import type { PickerRef } from '../../src/';
import { Picker, PickerPanel, RangePicker } from '../../src/';
import momentGenerateConfig from '../../src/generate/moment';
import enUS from '../../src/locale/en_US';
import jaJP from '../../src/locale/ja_JP';
import zhCN from '../../src/locale/zh_CN';
import type { RangePickerRef } from '@/interface';
import type { NoUndefinedRangeValueType } from '@/PickerInput/RangePicker';

const defaultValue = moment();

Expand All @@ -16,13 +19,16 @@ function formatDate(date: Moment | null) {
export default () => {
const [value, setValue] = React.useState<Moment | null>(defaultValue);

const weekRef = React.useRef<Picker<Moment>>(null);
const weekRef = React.useRef<PickerRef>(null);

const onSelect = (newValue: Moment) => {
console.log('Select:', newValue);
};

const onChange = (newValue: Moment | null, formatString?: string) => {
const onChange = (
newValue: NoUndefinedRangeValueType<Moment>,
formatString?: string | [string, string],
) => {
const lastValue = Array.isArray(newValue) ? newValue[1] : newValue;
console.log('Change:', lastValue, newValue, formatString);
setValue(lastValue);
Expand All @@ -33,10 +39,10 @@ export default () => {
value,
onSelect,
onChange,
direction: 'rtl',
direction: 'rtl' as const,
};

const rangePickerRef = React.useRef<RangePicker<Moment>>(null);
const rangePickerRef = React.useRef<RangePickerRef>(null);

return (
<div dir="rtl">
Expand Down
Loading

0 comments on commit 471c86b

Please sign in to comment.