From ea0c6e5f76c440e73998401c4279212c868e5f1f Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:11:34 +0100 Subject: [PATCH] Align CI task with i18next repo (#1727) --- .github/workflows/CI.yml | 105 ++++++++++++++++++ .github/workflows/lint_and_test.yml | 38 ------- README.md | 2 +- example/react_native_windows/.prettierrc.js | 6 - example/react_native_windows/.prettierrc.json | 7 ++ example/react_native_windows/App.js | 3 +- package.json | 10 +- vitest.config.mts | 6 + ...ace.mts => vitest.workspace.typescript.mts | 17 +-- 9 files changed, 128 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .github/workflows/lint_and_test.yml delete mode 100644 example/react_native_windows/.prettierrc.js create mode 100644 example/react_native_windows/.prettierrc.json rename vitest.workspace.mts => vitest.workspace.typescript.mts (83%) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..7db546e6 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,105 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + # types: [opened, synchronize, reopened, ready_for_review] + branches: + - '**' + +jobs: + codeQuality: + name: Check code quality (lint and format) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Format check + run: npm run format + + - name: Lint + run: npm run lint + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + test: + name: Test on node ${{ matrix.node }} and ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + node: [ '20.x', '18.x' ] + os: [ubuntu-latest] + # Collect coverage only for node 20 and ubuntu-latest, no need to run it twice + # @see https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations + include: + - collectCoverage: true + node: '20.x' + os: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Test + if: ${{ !matrix.collectCoverage }} + run: npm test + + - name: Test with coverage + if: ${{ matrix.collectCoverage }} + run: npm run test:coverage + + - name: Coveralls + if: ${{ matrix.collectCoverage }} + uses: coverallsapp/github-action@v2 + + testTypescript: + name: Test typescript + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Test + run: npm run test:typescript diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml deleted file mode 100644 index 2c0b3cdc..00000000 --- a/.github/workflows/lint_and_test.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Lint & Test - -on: - push: - branches: - - master - pull_request: - # types: [opened, synchronize, reopened, ready_for_review] - branches: - - '**' - -jobs: - test: - name: Lint & test on node ${{ matrix.node }} and ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - node: [ '20.x', '18.x' ] - # os: [ubuntu-latest, windows-latest, macOS-latest] - os: [ubuntu-latest] - steps: - - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node }} - - name: Install dependencies - run: npm install - # lint is included in pretest - # - name: Lint - # run: npm run lint - - name: Test - run: npm test - - name: Coverage - run: npm run test:coverage - # run: npm run test:coverage && cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose - - name: Coveralls - uses: coverallsapp/github-action@v2 diff --git a/README.md b/README.md index a2975d0b..a6b40873 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # react-i18next [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Awesome%20react-i18next%20for%20react.js%20based%20on%20i18next%20internationalization%20ecosystem%20&url=https://github.com/i18next/react-i18next&via=jamuhl&hashtags=i18n,reactjs,js,dev) -[![Lint & Test](https://github.com/i18next/react-i18next/actions/workflows/lint_and_test.yml/badge.svg)](https://github.com/i18next/react-i18next/actions/workflows/lint_and_test.yml) +[![CI](https://github.com/i18next/react-i18next/actions/workflows/CI.yml/badge.svg)](https://github.com/i18next/react-i18next/actions/workflows/CI.yml) [![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg)](https://codeclimate.com/github/i18next/react-i18next) [![Coverage Status](https://coveralls.io/repos/github/i18next/react-i18next/badge.svg)](https://coveralls.io/github/i18next/react-i18next) [![Quality][quality-badge]][quality-url] diff --git a/example/react_native_windows/.prettierrc.js b/example/react_native_windows/.prettierrc.js deleted file mode 100644 index 5c4de1a4..00000000 --- a/example/react_native_windows/.prettierrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - bracketSpacing: false, - jsxBracketSameLine: true, - singleQuote: true, - trailingComma: 'all', -}; diff --git a/example/react_native_windows/.prettierrc.json b/example/react_native_windows/.prettierrc.json new file mode 100644 index 00000000..61cedd3b --- /dev/null +++ b/example/react_native_windows/.prettierrc.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc.json", + "bracketSpacing": false, + "bracketSameLine": true, + "singleQuote": true, + "trailingComma": "all" +} diff --git a/example/react_native_windows/App.js b/example/react_native_windows/App.js index eed8bfc8..99532995 100644 --- a/example/react_native_windows/App.js +++ b/example/react_native_windows/App.js @@ -62,8 +62,7 @@ function Content() { + style={styles.scrollView}> {t('hello')} diff --git a/package.json b/package.json index 90292626..559b3ee8 100644 --- a/package.json +++ b/package.json @@ -134,6 +134,8 @@ "scripts": { "clean": "rimraf dist && mkdirp dist", "lint": "eslint ./src ./test", + "format": "prettier \"{,**/}*.{ts,tsx,mts,js,json,md}\" --check", + "format:fix": "prettier \"{,**/}*.{ts,tsx,mts,js,json,md}\" --write", "copy": "cp-cli ./dist/umd/react-i18next.min.js ./react-i18next.min.js && cp-cli ./dist/umd/react-i18next.js ./react-i18next.js && echo '{\"type\":\"module\"}' > dist/es/package.json", "build:es": "cross-env BABEL_ENV=jsnext babel src --out-dir dist/es", "build:cjs": "babel src --out-dir dist/commonjs", @@ -144,13 +146,11 @@ "fix_dist_package": "node -e 'console.log(`{\"type\":\"module\",\"version\":\"${process.env.npm_package_version}\"}`)' > dist/es/package.json", "preversion": "npm run build && git push", "postversion": "npm run fix_dist_package && git push && git push --tags", - "pretest": "npm run lint", - "test": "vitest run --typecheck --workspace vitest.workspace.mts", - "test:runtime": "npm run test -- --project runtime", - "test:coverage": "npm run test:runtime -- --coverage --run", + "test": "vitest", + "test:coverage": "npm run test -- --coverage --run", + "test:typescript": "vitest --workspace vitest.workspace.typescript.mts", "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", - "prettier": "prettier --write \"{,**/}*.{mts,ts,tsx,js,json,md}\"", "prepare": "husky install" }, "author": "Jan Mühlemann (https://github.com/jamuhl)", diff --git a/vitest.config.mts b/vitest.config.mts index c435dc96..a52447a9 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -2,6 +2,12 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { + name: 'runtime', + dir: './test', + exclude: ['**/typescript/**'], + environment: 'happy-dom', + setupFiles: ['./test/setup'], + coverage: { reporter: ['text', 'html', 'json', 'lcov'], include: ['**/src/*.{js,jsx}', '*.macro.js'], diff --git a/vitest.workspace.mts b/vitest.workspace.typescript.mts similarity index 83% rename from vitest.workspace.mts rename to vitest.workspace.typescript.mts index a8891e03..731fe4dd 100644 --- a/vitest.workspace.mts +++ b/vitest.workspace.typescript.mts @@ -2,23 +2,12 @@ import { readdirSync } from 'node:fs'; import { defineWorkspace } from 'vitest/config'; import type { UserProjectConfigExport } from 'vitest/config'; -export default defineWorkspace([ - { - test: { - name: 'runtime', - dir: './test', - exclude: ['**/typescript/**'], - environment: 'happy-dom', - - setupFiles: ['./test/setup'], - }, - }, - +export default defineWorkspace( /** * If you need to test multiple typescript configurations (like misc) simply create a file named tsconfig.{customName}.json * and this script will automatically create a new workspace named with the dirName followed by `customName` */ - ...readdirSync('./test/typescript', { withFileTypes: true }) + readdirSync('./test/typescript', { withFileTypes: true }) .filter((dir) => dir.isDirectory()) .reduce((workspaces, dir) => { const dirPath = `test/typescript/${dir.name}` as const; @@ -49,4 +38,4 @@ export default defineWorkspace([ return workspaces; }, []), -]); +);