From c1896ec2b2a7f25910c1f79a1b9050f442f2b443 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Thu, 31 Mar 2022 15:53:31 +0700 Subject: [PATCH 01/39] [#28] Add the Github Actions test workflow template for React projects --- template.json | 4 +++- template/.github/workflows/test.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 template/.github/workflows/test.yml diff --git a/template.json b/template.json index bb1e541..eb8fc41 100644 --- a/template.json +++ b/template.json @@ -49,6 +49,7 @@ "stylelint:fix": "stylelint '**/*.scss' --fix", "codebase:lint": "yarn lint && yarn stylelint", "codebase:fix": "yarn lint:fix && yarn stylelint:fix", + "cypress": "start-server-and-test start 3000 cypress:run", "cypress:run": "cypress run", "cypress:open": "cypress open" }, @@ -62,7 +63,8 @@ "excludeAfterRemap": true }, "devDependencies": { - "@cypress/instrument-cra": "1.4.0" + "@cypress/instrument-cra": "1.4.0", + "start-server-and-test": "1.14.0" } } } diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml new file mode 100644 index 0000000..75b95fa --- /dev/null +++ b/template/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test + +on: push + +jobs: + test: + name: Run linters and tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup node and restore cached dependencies + uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run linter + run: npm run lint + + - name: Run unit tests + run: npm test + + - name: Run integration tests + run: npm run cypress From a20aaf17d163c2916b220a097c7b2d0030b1777b Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Mon, 4 Apr 2022 12:45:37 +0700 Subject: [PATCH 02/39] [#50] Add .gitlab folder with merge request templates --- .../merge_request_templates/Default.md | 20 +++++++++++++++++ .../merge_request_templates/Release.md | 22 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 template/.gitlab/merge_request_templates/Default.md create mode 100644 template/.gitlab/merge_request_templates/Release.md diff --git a/template/.gitlab/merge_request_templates/Default.md b/template/.gitlab/merge_request_templates/Default.md new file mode 100644 index 0000000..feb41aa --- /dev/null +++ b/template/.gitlab/merge_request_templates/Default.md @@ -0,0 +1,20 @@ +{COPY THE TASK URL HERE} + +## What happened đź‘€ + +Describe the big picture of your changes here to communicate to the team why we should accept this pull request. + +## Insight đź“ť + +Describe in detail how to test the changes, which solution you tried but did not go with, referenced documentation is welcome as well. + +## Proof Of Work đź“ą + +Show us the implementation: screenshots, GIFs, etc. + +## Reviewers âś… + +Mention the reviewers here once the merge request is ready for review. + + +/label ~"status : wip" diff --git a/template/.gitlab/merge_request_templates/Release.md b/template/.gitlab/merge_request_templates/Release.md new file mode 100644 index 0000000..fbc43e3 --- /dev/null +++ b/template/.gitlab/merge_request_templates/Release.md @@ -0,0 +1,22 @@ +## Features + +Provide the ID and title of each issue in the section for each type (feature, chore and bug). The link is optional. + +- [{ISSUE ID}] {ISSUE TITLE} +or +- [[{ISSUE ID}]]({ISSUE LINK})] {ISSUE TITLE} + +## Chores + +- Same structure as in ## Feature + +## Bugs + +- Same structure as in ## Feature + +## Reviewers âś… + +Mention the reviewers here once the merge request is ready for review. + + +/label ~"type : release" From 75ec842679dde396d922d96c393b2bfee3274f36 Mon Sep 17 00:00:00 2001 From: Carryall Date: Mon, 4 Apr 2022 15:07:22 +0700 Subject: [PATCH 03/39] [#52] Replace node sass with dart sass --- template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.json b/template.json index eb8fc41..3052e60 100644 --- a/template.json +++ b/template.json @@ -29,9 +29,9 @@ "i18next": "21.6.14", "i18next-browser-languagedetector": "6.1.3", "i18next-http-backend": "1.4.0", - "node-sass": "7.0.1", "prettier": "2.6.0", "react-i18next": "11.16.1", + "sass": "1.49.11", "stylelint": "14.6.0", "stylelint-config-property-sort-order-smacss": "9.0.0", "stylelint-config-sass-guidelines": "9.0.1", From 2cdbf2e9cc096a456bec01023c6a1c6b3b57becf Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Mon, 4 Apr 2022 16:24:11 +0700 Subject: [PATCH 04/39] [#53] Add react-router to the template --- template.json | 1 + template/src/App.tsx | 19 +++++-------------- template/src/index.tsx | 5 ++++- template/src/routes/index.tsx | 13 +++++++++++++ template/src/screens/.keep | 0 template/src/screens/Home.tsx | 22 ++++++++++++++++++++++ 6 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 template/src/routes/index.tsx delete mode 100644 template/src/screens/.keep create mode 100644 template/src/screens/Home.tsx diff --git a/template.json b/template.json index 3052e60..582ab3b 100644 --- a/template.json +++ b/template.json @@ -31,6 +31,7 @@ "i18next-http-backend": "1.4.0", "prettier": "2.6.0", "react-i18next": "11.16.1", + "react-router-dom": "6.3.0", "sass": "1.49.11", "stylelint": "14.6.0", "stylelint-config-property-sort-order-smacss": "9.0.0", diff --git a/template/src/App.tsx b/template/src/App.tsx index e83b49b..126623e 100644 --- a/template/src/App.tsx +++ b/template/src/App.tsx @@ -1,24 +1,15 @@ import React from 'react'; -import { useTranslation } from 'react-i18next'; +import { useRoutes } from 'react-router-dom'; -import logo from './assets/images/logo.svg'; import './dummy.scss'; import './assets/stylesheets/application.scss'; +import routes from './routes'; + const App = (): JSX.Element => { - const { t } = useTranslation(); + const appRoutes = useRoutes(routes); - return ( -
-
- logo -

{t('sample_page.message', { codeSample: 'src/App.tsx' })}

- - {t('sample_page.learn_react')} - -
-
- ); + return <>{appRoutes}; }; export default App; diff --git a/template/src/index.tsx b/template/src/index.tsx index 5742c3d..1e7e4d5 100644 --- a/template/src/index.tsx +++ b/template/src/index.tsx @@ -1,5 +1,6 @@ import React, { Suspense } from 'react'; import ReactDOM from 'react-dom'; +import { BrowserRouter } from 'react-router-dom'; import App from './App'; import configureI18n from './i18n'; @@ -10,7 +11,9 @@ configureI18n(); ReactDOM.render( - + + + , document.getElementById('root') diff --git a/template/src/routes/index.tsx b/template/src/routes/index.tsx new file mode 100644 index 0000000..1e1f533 --- /dev/null +++ b/template/src/routes/index.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { RouteObject } from 'react-router-dom'; + +import HomeScreen from '../screens/Home'; + +const routes: RouteObject[] = [ + { + path: '/', + element: , + }, +]; + +export default routes; diff --git a/template/src/screens/.keep b/template/src/screens/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/template/src/screens/Home.tsx b/template/src/screens/Home.tsx new file mode 100644 index 0000000..f2ef468 --- /dev/null +++ b/template/src/screens/Home.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +import logo from '../assets/images/logo.svg'; + +const HomeScreen = (): JSX.Element => { + const { t } = useTranslation(); + + return ( +
+
+ logo +

{t('sample_page.message', { codeSample: 'src/App.tsx' })}

+ + {t('sample_page.learn_react')} + +
+
+ ); +}; + +export default HomeScreen; From 554fa2d31d3ff9250b6334b920e1455f2fd033c6 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Mon, 4 Apr 2022 16:37:34 +0700 Subject: [PATCH 05/39] [#53] Add default tsconfig --- template/src/App.tsx | 6 +++--- template/src/routes/index.tsx | 2 +- template/src/screens/Home.tsx | 2 +- template/tsconfig.json | 5 +++++ 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 template/tsconfig.json diff --git a/template/src/App.tsx b/template/src/App.tsx index 126623e..c2ad7fe 100644 --- a/template/src/App.tsx +++ b/template/src/App.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { useRoutes } from 'react-router-dom'; -import './dummy.scss'; -import './assets/stylesheets/application.scss'; +import 'dummy.scss'; +import 'assets/stylesheets/application.scss'; -import routes from './routes'; +import routes from 'routes'; const App = (): JSX.Element => { const appRoutes = useRoutes(routes); diff --git a/template/src/routes/index.tsx b/template/src/routes/index.tsx index 1e1f533..2e5b21a 100644 --- a/template/src/routes/index.tsx +++ b/template/src/routes/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { RouteObject } from 'react-router-dom'; -import HomeScreen from '../screens/Home'; +import HomeScreen from 'screens/Home'; const routes: RouteObject[] = [ { diff --git a/template/src/screens/Home.tsx b/template/src/screens/Home.tsx index f2ef468..472866a 100644 --- a/template/src/screens/Home.tsx +++ b/template/src/screens/Home.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; -import logo from '../assets/images/logo.svg'; +import logo from 'assets/images/logo.svg'; const HomeScreen = (): JSX.Element => { const { t } = useTranslation(); diff --git a/template/tsconfig.json b/template/tsconfig.json new file mode 100644 index 0000000..a74041b --- /dev/null +++ b/template/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "baseUrl": "src", + } +} From 1429eb859297303706c80e3de11c78c6d2da4a98 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Tue, 5 Apr 2022 14:59:27 +0700 Subject: [PATCH 06/39] [#53] Move HomeScreen test into screen folder --- template/src/{App.test.tsx => screens/Home.test.tsx} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename template/src/{App.test.tsx => screens/Home.test.tsx} (77%) diff --git a/template/src/App.test.tsx b/template/src/screens/Home.test.tsx similarity index 77% rename from template/src/App.test.tsx rename to template/src/screens/Home.test.tsx index 7551bb7..3a3202e 100644 --- a/template/src/App.test.tsx +++ b/template/src/screens/Home.test.tsx @@ -2,11 +2,11 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import App from './App'; +import HomeScreen from './Home'; -describe('App', () => { +describe('HomeScreen', () => { it('renders learn react link', () => { - render(); + render(); const linkElement = screen.getByTestId('app-link'); From fa912b900075ae2688e834727b8023ab8b4e6e88 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 10:21:09 +0700 Subject: [PATCH 07/39] Add .tool-versions file in the template folder --- template/.tool-versions | 1 + 1 file changed, 1 insertion(+) create mode 100644 template/.tool-versions diff --git a/template/.tool-versions b/template/.tool-versions new file mode 100644 index 0000000..0094556 --- /dev/null +++ b/template/.tool-versions @@ -0,0 +1 @@ +nodejs 16.14.2 From 56220ec7e30359674b723c72bd782461252b5ca2 Mon Sep 17 00:00:00 2001 From: Carryall Date: Tue, 5 Apr 2022 17:53:28 +0700 Subject: [PATCH 08/39] [#67] Add team lead to team member --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f894c59..f269729 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,7 +2,7 @@ * @carryall # Team Members -* @bterone @hanam1ni @hoangmirs @malparty @rosle @tyrro +* @carryall @bterone @hanam1ni @hoangmirs @malparty @rosle @tyrro # Engineering Leads CODEOWNERS @nimblehq/engineering-leads From 36b9e7b975ed470bcf030068b6548daf64274dfd Mon Sep 17 00:00:00 2001 From: Carryall Date: Tue, 5 Apr 2022 18:16:56 +0700 Subject: [PATCH 09/39] [#67] Merge team members --- .github/CODEOWNERS | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f269729..f9ff945 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,7 +1,5 @@ -# Team Lead -* @carryall - -# Team Members +# Team +# @carryall is the Team Lead and the others are team members * @carryall @bterone @hanam1ni @hoangmirs @malparty @rosle @tyrro # Engineering Leads From b6ea46c6836a528a0fb52f324dec385954607d9f Mon Sep 17 00:00:00 2001 From: Carryall Date: Wed, 6 Apr 2022 11:35:19 +0700 Subject: [PATCH 10/39] [#13] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9f11b75..68729d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +.DS_Store \ No newline at end of file From 70a6ff7d9beb5167dad20e28c4cba3c3d60f64de Mon Sep 17 00:00:00 2001 From: Carryall Date: Wed, 6 Apr 2022 11:42:55 +0700 Subject: [PATCH 11/39] [#13] Add test workflow --- .github/workflows/test.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a4c5b6a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Test + +on: push + +jobs: + test: + name: Run linters and tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup node and restore cached dependencies + uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + + - name: Bootstrap React App + run: npx create-react-app test-app + + - name: Run test + working-directory: ./test-app + run: npm run lint + + - name: Run unit tests + working-directory: ./test-app + run: npm test + + - name: Run integration tests + working-directory: ./test-app + run: npm run cypress From 9c8101313e362c216cc0245a0ea026ba841a2e92 Mon Sep 17 00:00:00 2001 From: Carryall Date: Wed, 6 Apr 2022 11:55:04 +0700 Subject: [PATCH 12/39] [#13] Update gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 68729d6..db1db1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +# dependencies +/node_modules + +# misc .idea/ -.DS_Store \ No newline at end of file +.DS_Store From 902bcd675da4d7d6d474f1cba8771f4a839b975a Mon Sep 17 00:00:00 2001 From: Carryall Date: Wed, 6 Apr 2022 11:55:21 +0700 Subject: [PATCH 13/39] [#13] Add yarn lock --- yarn.lock | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 yarn.lock diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From fea2d2fec06bd25dd133ffa1c2474a56985c0228 Mon Sep 17 00:00:00 2001 From: Carryall Date: Wed, 6 Apr 2022 12:30:18 +0700 Subject: [PATCH 14/39] [#13] Bootstrap from local template --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4c5b6a..40ab994 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: push jobs: test: - name: Run linters and tests + name: Bootstrap app, run linters and tests runs-on: ubuntu-latest steps: - name: Checkout @@ -17,7 +17,7 @@ jobs: cache: 'npm' - name: Bootstrap React App - run: npx create-react-app test-app + run: npx create-react-app test-app --template file:./ - name: Run test working-directory: ./test-app From 60631ab2047ee63d27c6102f71843fe506f7ca9a Mon Sep 17 00:00:00 2001 From: Carryall Date: Thu, 7 Apr 2022 11:01:03 +0700 Subject: [PATCH 15/39] [#13] Ignore yarn lock --- .gitignore | 1 + yarn.lock | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index db1db1b..1cea1cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # dependencies /node_modules +yarn.lock # misc .idea/ diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index fb57ccd..0000000 --- a/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - From 10c4706fd5e2e2e9b27f20072d9a38db9e6c1b8d Mon Sep 17 00:00:00 2001 From: Carryall Date: Thu, 7 Apr 2022 11:08:39 +0700 Subject: [PATCH 16/39] [#13] Use build metrix --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40ab994..0cda82e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,9 @@ jobs: test: name: Bootstrap app, run linters and tests runs-on: ubuntu-latest + strategy: + matrix: + node: [14, 16] steps: - name: Checkout uses: actions/checkout@v2 @@ -13,7 +16,7 @@ jobs: - name: Setup node and restore cached dependencies uses: actions/setup-node@v2 with: - node-version: '16' + node-version: ${{ matrix.node }} cache: 'npm' - name: Bootstrap React App From b650ea6d2d1846437cb7fa507c1938ba2572dc81 Mon Sep 17 00:00:00 2001 From: Carryall Date: Thu, 7 Apr 2022 11:15:08 +0700 Subject: [PATCH 17/39] [#13] Bring back lock --- .gitignore | 1 - package-lock.json | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 1cea1cb..db1db1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # dependencies /node_modules -yarn.lock # misc .idea/ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..5326de6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,16 @@ +{ + "name": "cra-template-nimble", + "version": "2.1.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "cra-template-nimble", + "version": "2.1.0", + "license": "MIT", + "engines": { + "node": "^14.18.2 || ^16 || ^17" + } + } + } +} From 68b3c28e1c22643eb3c7d09c72079c907dea3c8a Mon Sep 17 00:00:00 2001 From: Carryall Date: Fri, 8 Apr 2022 11:09:44 +0700 Subject: [PATCH 18/39] [#13] Update workflows --- .github/workflows/test.yml | 11 ++++++++--- template/.github/workflows/test.yml | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cda82e..f429cee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,12 +4,17 @@ on: push jobs: test: - name: Bootstrap app, run linters and tests + name: Bootstrap app, run linters and tests with Node ${{ matrix.node }} runs-on: ubuntu-latest strategy: matrix: node: [14, 16] steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - name: Checkout uses: actions/checkout@v2 @@ -22,13 +27,13 @@ jobs: - name: Bootstrap React App run: npx create-react-app test-app --template file:./ - - name: Run test + - name: Run linters working-directory: ./test-app run: npm run lint - name: Run unit tests working-directory: ./test-app - run: npm test + run: npm run test - name: Run integration tests working-directory: ./test-app diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index 75b95fa..b11f3ae 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -7,6 +7,11 @@ jobs: name: Run linters and tests runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - name: Checkout uses: actions/checkout@v2 @@ -23,7 +28,7 @@ jobs: run: npm run lint - name: Run unit tests - run: npm test + run: npm run test - name: Run integration tests run: npm run cypress From 13f754260b321c5351aa889650254d2ecf42fcb7 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Mon, 4 Apr 2022 17:13:49 +0700 Subject: [PATCH 19/39] Add Netlify preview and improve test workflows --- .../.github/workflows/integration-test.yml | 16 ++++++++++ template/.github/workflows/preview.yml | 31 +++++++++++++++++++ template/.github/workflows/test-coverage.yml | 19 ++++++++++++ template/.github/workflows/test.yml | 10 ++---- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 template/.github/workflows/integration-test.yml create mode 100644 template/.github/workflows/preview.yml create mode 100644 template/.github/workflows/test-coverage.yml diff --git a/template/.github/workflows/integration-test.yml b/template/.github/workflows/integration-test.yml new file mode 100644 index 0000000..06fa6f4 --- /dev/null +++ b/template/.github/workflows/integration-test.yml @@ -0,0 +1,16 @@ +name: Cypress Integration Test + +on: [push] + +jobs: + cypress-run: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Cypress run + uses: cypress-io/github-action@v2 + with: + build: yarn build + start: yarn start diff --git a/template/.github/workflows/preview.yml b/template/.github/workflows/preview.yml new file mode 100644 index 0000000..1e7c78b --- /dev/null +++ b/template/.github/workflows/preview.yml @@ -0,0 +1,31 @@ +name: 'Netlify Preview Deploy' + +on: + push: + branches-ignore: ['main', 'master'] + +jobs: + deploy: + name: 'Deploy' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + # Sets the branch name as environment variable + - uses: nelonoel/branch-name@v1.0.1 + - uses: jsmrcaga/action-netlify-deploy@master + with: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + deploy_alias: ${{ env.BRANCH_NAME }} + install_command: yarn + build_command: yarn build + + # Creates a status check with link to preview + - name: Status check + uses: Sibz/github-status-action@v1.1.1 + with: + authToken: ${{ secrets.GITHUB_TOKEN }} + context: Netlify preview + state: success + target_url: https://${{ env.BRANCH_NAME }}--my-site.netlify.app \ No newline at end of file diff --git a/template/.github/workflows/test-coverage.yml b/template/.github/workflows/test-coverage.yml new file mode 100644 index 0000000..fd516b8 --- /dev/null +++ b/template/.github/workflows/test-coverage.yml @@ -0,0 +1,19 @@ +name: Test Coverage + +on: push + +jobs: + coverage: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Jest Coverage report + uses: artiomtr/jest-coverage-report-action@v2.0.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + package-manager: yarn + test-script: yarn test + threshold: 80 # prevent PR merge under 80% coverage diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index b11f3ae..37790c8 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -3,8 +3,7 @@ name: Test on: push jobs: - test: - name: Run linters and tests + build: runs-on: ubuntu-latest steps: - name: Cancel Previous Runs @@ -15,11 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Setup node and restore cached dependencies - uses: actions/setup-node@v2 - with: - node-version: '16' - cache: 'npm' + - name: Install modules + run: yarn - name: Install dependencies run: npm ci From ad243f9297875d233b1219151115bd9173c4d16f Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 5 Apr 2022 13:46:20 +0700 Subject: [PATCH 20/39] Add deploy to netlify action --- template/.github/workflows/release.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 template/.github/workflows/release.yml diff --git a/template/.github/workflows/release.yml b/template/.github/workflows/release.yml new file mode 100644 index 0000000..20b8ef9 --- /dev/null +++ b/template/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: 'Netlify Deploy' + +on: + push: + branches: ['main', 'master'] + +jobs: + deploy: + name: 'Deploy' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - uses: jsmrcaga/action-netlify-deploy@master + with: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_DEPLOY_MESSAGE: "Prod deploy v${{ github.ref }}" + NETLIFY_DEPLOY_TO_PROD: true + install_command: yarn + build_command: yarn build From 4bfbcbe95771b7bda065ba0254d8434888fa10c0 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 5 Apr 2022 14:19:00 +0700 Subject: [PATCH 21/39] Add deploy GitHub Action instructions --- template/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/template/README.md b/template/README.md index 63ea4b0..fcb6c21 100644 --- a/template/README.md +++ b/template/README.md @@ -55,6 +55,23 @@ To change the default fallback language - Either edit the value of the environment variable `REACT_APP_DEFAULT_LANGUAGE` (cf. the `env.example` file) - Either directly edit the const `DEFAULT_FALLBACK_LANGUAGE` in `src/i18n.ts` +## Deployment + +### GitHub Actions for Netlify + +The `.github/workflow` folder already includes GitHub Actions to deploy previews and releases of your app in Netlify. + +How to use it? + +1. Create a new empty application in Netlify (use Drag&Drop and drop their demo project) +2. Configure the following action secrets in the Github repository: + - `NETLIFY_SITE_ID` available in the `Site settings` tab. + - `NETLIFY_AUTH_TOKEN`: created under `User settings, Applications, Personal access tokens` +3. Push your code to the repository. + +Any push under `main` or `master` triggers a release in production. +Any push under another branch triggers a preview deployment in `{branch-name}.{site-url}` + ## Learn More You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). From 98cb38acb2be71bec369e75ea005e876386c4a6c Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 5 Apr 2022 14:29:14 +0700 Subject: [PATCH 22/39] Fix npx command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb0bff1..d8254e6 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To use this template, add `--template nimble` when creating a new app from the ` ```sh -npx create-react-app my-app --template nimble +npx create-react-app@latest my-app --template nimble # or From bf65f936162edbf01887f98b90217214de3cc8b6 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 5 Apr 2022 15:30:04 +0700 Subject: [PATCH 23/39] Use another GitHub Action image for Netlify Deploy --- template/.github/workflows/preview.yml | 40 ++++++++++++-------------- template/.github/workflows/release.yml | 33 ++++++++++++--------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/template/.github/workflows/preview.yml b/template/.github/workflows/preview.yml index 1e7c78b..40184e3 100644 --- a/template/.github/workflows/preview.yml +++ b/template/.github/workflows/preview.yml @@ -1,31 +1,27 @@ -name: 'Netlify Preview Deploy' - +name: Netlify Preview on: push: branches-ignore: ['main', 'master'] - jobs: - deploy: - name: 'Deploy' - runs-on: ubuntu-latest + build: + runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 + + + - name: Install modules + run: yarn - # Sets the branch name as environment variable - - uses: nelonoel/branch-name@v1.0.1 - - uses: jsmrcaga/action-netlify-deploy@master + - name: Build + run: yarn build + + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v1.2 with: + publish-dir: './build' + deploy-message: "Preview deployed from GitHub Actions" + github-token: ${{ secrets.GITHUB_TOKEN }} + env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - deploy_alias: ${{ env.BRANCH_NAME }} - install_command: yarn - build_command: yarn build - - # Creates a status check with link to preview - - name: Status check - uses: Sibz/github-status-action@v1.1.1 - with: - authToken: ${{ secrets.GITHUB_TOKEN }} - context: Netlify preview - state: success - target_url: https://${{ env.BRANCH_NAME }}--my-site.netlify.app \ No newline at end of file + timeout-minutes: 1 diff --git a/template/.github/workflows/release.yml b/template/.github/workflows/release.yml index 20b8ef9..cea1e3e 100644 --- a/template/.github/workflows/release.yml +++ b/template/.github/workflows/release.yml @@ -1,21 +1,28 @@ -name: 'Netlify Deploy' - +name: Netlify Release on: push: branches: ['main', 'master'] - jobs: - deploy: - name: 'Deploy' - runs-on: ubuntu-latest - + build: + runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v1 - - uses: jsmrcaga/action-netlify-deploy@master + - uses: actions/checkout@v2 + + + - name: Install modules + run: yarn + + - name: Build + run: yarn build + + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v1.2 with: + publish-dir: './build' + deploy-message: "Deploy from GitHub Actions" + production-deploy: true + github-token: ${{ secrets.GITHUB_TOKEN }} + env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - NETLIFY_DEPLOY_MESSAGE: "Prod deploy v${{ github.ref }}" - NETLIFY_DEPLOY_TO_PROD: true - install_command: yarn - build_command: yarn build + timeout-minutes: 1 From 0193e1b136187e48f80a213d4b0ee764b03d046b Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 10:03:47 +0700 Subject: [PATCH 24/39] Remove test workflow from this branch --- .../.github/workflows/integration-test.yml | 16 ---------------- template/.github/workflows/test-coverage.yml | 19 ------------------- template/.github/workflows/test.yml | 10 +++++++--- 3 files changed, 7 insertions(+), 38 deletions(-) delete mode 100644 template/.github/workflows/integration-test.yml delete mode 100644 template/.github/workflows/test-coverage.yml diff --git a/template/.github/workflows/integration-test.yml b/template/.github/workflows/integration-test.yml deleted file mode 100644 index 06fa6f4..0000000 --- a/template/.github/workflows/integration-test.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Cypress Integration Test - -on: [push] - -jobs: - cypress-run: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Cypress run - uses: cypress-io/github-action@v2 - with: - build: yarn build - start: yarn start diff --git a/template/.github/workflows/test-coverage.yml b/template/.github/workflows/test-coverage.yml deleted file mode 100644 index fd516b8..0000000 --- a/template/.github/workflows/test-coverage.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Test Coverage - -on: push - -jobs: - coverage: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[skip ci]')" - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Jest Coverage report - uses: artiomtr/jest-coverage-report-action@v2.0.3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - package-manager: yarn - test-script: yarn test - threshold: 80 # prevent PR merge under 80% coverage diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index 37790c8..b11f3ae 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -3,7 +3,8 @@ name: Test on: push jobs: - build: + test: + name: Run linters and tests runs-on: ubuntu-latest steps: - name: Cancel Previous Runs @@ -14,8 +15,11 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Install modules - run: yarn + - name: Setup node and restore cached dependencies + uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' - name: Install dependencies run: npm ci From fceea2c2a773e641f9be9fa4a402351be2ffd2c9 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 10:07:17 +0700 Subject: [PATCH 25/39] Update README to match new preview URL --- template/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template/README.md b/template/README.md index fcb6c21..e452a6f 100644 --- a/template/README.md +++ b/template/README.md @@ -70,7 +70,8 @@ How to use it? 3. Push your code to the repository. Any push under `main` or `master` triggers a release in production. -Any push under another branch triggers a preview deployment in `{branch-name}.{site-url}` +Any push under another branch triggers a preview deployment. +Once a preview is deployed, the Preview URL is displayed in the Pull Request thread. ## Learn More From 3ca72602e2fea5314e8589babc5b5cd4972f9ac4 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 10:11:20 +0700 Subject: [PATCH 26/39] Remove @latest to bring it in the right PR --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8254e6..fb0bff1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To use this template, add `--template nimble` when creating a new app from the ` ```sh -npx create-react-app@latest my-app --template nimble +npx create-react-app my-app --template nimble # or From bf2ad93b656efe7e0a0593d762ffafdeb9f27de7 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 14:32:11 +0700 Subject: [PATCH 27/39] Fix many typos and format --- template/.github/workflows/{release.yml => deploy.yml} | 7 ++++--- .../.github/workflows/{preview.yml => deploy_preview.yml} | 5 +++-- template/README.md | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) rename template/.github/workflows/{release.yml => deploy.yml} (94%) rename template/.github/workflows/{preview.yml => deploy_preview.yml} (95%) diff --git a/template/.github/workflows/release.yml b/template/.github/workflows/deploy.yml similarity index 94% rename from template/.github/workflows/release.yml rename to template/.github/workflows/deploy.yml index cea1e3e..d830816 100644 --- a/template/.github/workflows/release.yml +++ b/template/.github/workflows/deploy.yml @@ -1,14 +1,15 @@ -name: Netlify Release +name: Deploy to Netlify + on: push: branches: ['main', 'master'] + jobs: - build: + deploy: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: Install modules run: yarn diff --git a/template/.github/workflows/preview.yml b/template/.github/workflows/deploy_preview.yml similarity index 95% rename from template/.github/workflows/preview.yml rename to template/.github/workflows/deploy_preview.yml index 40184e3..71cd687 100644 --- a/template/.github/workflows/preview.yml +++ b/template/.github/workflows/deploy_preview.yml @@ -1,14 +1,15 @@ -name: Netlify Preview +name: Deploy Netlify Preview + on: push: branches-ignore: ['main', 'master'] + jobs: build: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: Install modules run: yarn diff --git a/template/README.md b/template/README.md index e452a6f..03a7b06 100644 --- a/template/README.md +++ b/template/README.md @@ -59,7 +59,7 @@ To change the default fallback language ### GitHub Actions for Netlify -The `.github/workflow` folder already includes GitHub Actions to deploy previews and releases of your app in Netlify. +The `.github/workflows` folder already includes GitHub Actions to deploy previews and releases of your app in Netlify. How to use it? From a4b95faae453d8ee274fafc28b8c9a34de00afdb Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 14:34:37 +0700 Subject: [PATCH 28/39] Fix preview typos --- template/.github/workflows/deploy_preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/.github/workflows/deploy_preview.yml b/template/.github/workflows/deploy_preview.yml index 71cd687..89d03c2 100644 --- a/template/.github/workflows/deploy_preview.yml +++ b/template/.github/workflows/deploy_preview.yml @@ -1,11 +1,11 @@ -name: Deploy Netlify Preview +name: Deploy Preview to Netlify on: push: branches-ignore: ['main', 'master'] jobs: - build: + deploy-preview: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 From 3f26f884683f22ddba9c17955763998ce66d776c Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Thu, 7 Apr 2022 14:23:05 +0700 Subject: [PATCH 29/39] Updated preview deploy message with PR number and title --- template/.github/workflows/deploy_preview.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/template/.github/workflows/deploy_preview.yml b/template/.github/workflows/deploy_preview.yml index 89d03c2..1f4dcbb 100644 --- a/template/.github/workflows/deploy_preview.yml +++ b/template/.github/workflows/deploy_preview.yml @@ -1,8 +1,6 @@ name: Deploy Preview to Netlify -on: - push: - branches-ignore: ['main', 'master'] +on: [pull_request, workflow_dispatch] jobs: deploy-preview: @@ -20,7 +18,7 @@ jobs: uses: nwtgck/actions-netlify@v1.2 with: publish-dir: './build' - deploy-message: "Preview deployed from GitHub Actions" + deploy-message: '#${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}' github-token: ${{ secrets.GITHUB_TOKEN }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} From 8c874e841f89dd76c9a84e91901504c2a3f7280e Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Thu, 7 Apr 2022 15:06:51 +0700 Subject: [PATCH 30/39] Fix workflow_dispatch input --- template/.github/workflows/deploy.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/template/.github/workflows/deploy.yml b/template/.github/workflows/deploy.yml index d830816..f107d1a 100644 --- a/template/.github/workflows/deploy.yml +++ b/template/.github/workflows/deploy.yml @@ -1,8 +1,12 @@ -name: Deploy to Netlify - +name: Netlify Release on: push: branches: ['main', 'master'] + workflow_dispatch: + inputs: + deploy-msg: + description: 'Deploy Message (visible in Netlify)' + required: true jobs: deploy: @@ -20,7 +24,7 @@ jobs: uses: nwtgck/actions-netlify@v1.2 with: publish-dir: './build' - deploy-message: "Deploy from GitHub Actions" + deploy-message: "Deploy from GitHub Actions. ${{ github.event.inputs.deploy-msg }}" production-deploy: true github-token: ${{ secrets.GITHUB_TOKEN }} env: From a7baaec31bc13176db13cec8698d1f06d3757d12 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 12 Apr 2022 09:57:17 +0700 Subject: [PATCH 31/39] Fix typos, add missing names and add the cancel-job initial step --- template/.github/workflows/deploy.yml | 11 +++++++++-- template/.github/workflows/deploy_preview.yml | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/template/.github/workflows/deploy.yml b/template/.github/workflows/deploy.yml index f107d1a..8a62a84 100644 --- a/template/.github/workflows/deploy.yml +++ b/template/.github/workflows/deploy.yml @@ -1,4 +1,5 @@ -name: Netlify Release +name: Deploy to Netlify + on: push: branches: ['main', 'master'] @@ -10,8 +11,14 @@ on: jobs: deploy: + name: Build and Deploy to Netlify runs-on: ubuntu-18.04 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 - name: Install modules @@ -24,7 +31,7 @@ jobs: uses: nwtgck/actions-netlify@v1.2 with: publish-dir: './build' - deploy-message: "Deploy from GitHub Actions. ${{ github.event.inputs.deploy-msg }}" + deploy-message: "Deploy from GitHub Actions: ${{ github.event.inputs.deploy-msg }}" production-deploy: true github-token: ${{ secrets.GITHUB_TOKEN }} env: diff --git a/template/.github/workflows/deploy_preview.yml b/template/.github/workflows/deploy_preview.yml index 1f4dcbb..b3276c0 100644 --- a/template/.github/workflows/deploy_preview.yml +++ b/template/.github/workflows/deploy_preview.yml @@ -4,8 +4,14 @@ on: [pull_request, workflow_dispatch] jobs: deploy-preview: + name: Build and Deploy preview on Netlify runs-on: ubuntu-18.04 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 - name: Install modules From f52d07cc7f654417e976f8117416e8da0f0f64ba Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 13 Apr 2022 10:31:56 +0700 Subject: [PATCH 32/39] [#66] Use npm only, remove yarn from scripts and documentation --- README.md | 8 ------ template.json | 6 ++--- template/.github/workflows/deploy.yml | 4 +-- template/.github/workflows/deploy_preview.yml | 4 +-- template/README.md | 26 +++++++++---------- template/gitignore | 2 -- template/public/index.html | 4 +-- 7 files changed, 22 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index fb0bff1..77bdda0 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,6 @@ To use this template, add `--template nimble` when creating a new app from the ` ```sh npx create-react-app my-app --template nimble - -# or - -yarn create react-app my-app --template nimble ``` For more information about `create-react-app`, please refer to: @@ -67,10 +63,6 @@ To test the template locally, simply run the template install command with the p ```sh npx create-react-app my-app --template file:{../path/to/your/local/template/repo} - -# or - -yarn create react-app my-app --template file:{../path/to/your/local/template/repo} ``` ## License diff --git a/template.json b/template.json index 582ab3b..54cfdf6 100644 --- a/template.json +++ b/template.json @@ -43,13 +43,13 @@ }, "scripts": { "start": "react-scripts -r @cypress/instrument-cra start", - "test:coverage": "react-scripts test --coverage --watchAll=false && yarn cypress:run && node ./scripts/coverage-merge.js && nyc report", + "test:coverage": "react-scripts test --coverage --watchAll=false && npm run cypress:run && node ./scripts/coverage-merge.js && nyc report", "lint": "eslint ./src ./cypress --ext .ts,.tsx", "lint:fix": "eslint ./src ./cypress --ext .ts,.tsx --fix", "stylelint": "stylelint '**/*.scss'", "stylelint:fix": "stylelint '**/*.scss' --fix", - "codebase:lint": "yarn lint && yarn stylelint", - "codebase:fix": "yarn lint:fix && yarn stylelint:fix", + "codebase:lint": "npm run lint && npm run stylelint", + "codebase:fix": "npm run lint:fix && npm run stylelint:fix", "cypress": "start-server-and-test start 3000 cypress:run", "cypress:run": "cypress run", "cypress:open": "cypress open" diff --git a/template/.github/workflows/deploy.yml b/template/.github/workflows/deploy.yml index 8a62a84..185b30b 100644 --- a/template/.github/workflows/deploy.yml +++ b/template/.github/workflows/deploy.yml @@ -22,10 +22,10 @@ jobs: - uses: actions/checkout@v2 - name: Install modules - run: yarn + run: npm ci - name: Build - run: yarn build + run: npm run build - name: Deploy to Netlify uses: nwtgck/actions-netlify@v1.2 diff --git a/template/.github/workflows/deploy_preview.yml b/template/.github/workflows/deploy_preview.yml index b3276c0..fa61929 100644 --- a/template/.github/workflows/deploy_preview.yml +++ b/template/.github/workflows/deploy_preview.yml @@ -15,10 +15,10 @@ jobs: - uses: actions/checkout@v2 - name: Install modules - run: yarn + run: npm ci - name: Build - run: yarn build + run: npm run build - name: Deploy to Netlify uses: nwtgck/actions-netlify@v1.2 diff --git a/template/README.md b/template/README.md index 03a7b06..c217219 100644 --- a/template/README.md +++ b/template/README.md @@ -6,40 +6,40 @@ This project was bootstrapped with [Nimble React template](https://github.com/ni In the project directory, you can run: -`yarn start`: Runs the app in the development mode. Open [http://localhost:3000](http://localhost:3000) to view it in the browser. +`npm start`: Runs the app in the development mode. Open [http://localhost:3000](http://localhost:3000) to view it in the browser. -`yarn test`: Launches the test runner in the interactive watch mode. See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. +`npm test`: Launches the test runner in the interactive watch mode. See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. -`yarn test:coverage`: Both Unit Tests (Jest) and UI Tests (cypress) generate test coverage analytics. The below command runs all tests and merges both coverage files into a single report. +`npm run test:coverage`: Both Unit Tests (Jest) and UI Tests (cypress) generate test coverage analytics. The below command runs all tests and merges both coverage files into a single report. > Use the `.nyc_output/out.json` artefact in your CI/CD pipeline to reuse the code coverage data. -`yarn build`: Builds the app for production to the `build` folder. It correctly bundles React in production mode and +`npm run build`: Builds the app for production to the `build` folder. It correctly bundles React in production mode and optimizes the build for the best performance. The build is minified and the filenames include the hashes. Your app is ready to be deployed! See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -`yarn eject`: If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This +`npm run eject`: If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. **Note: this is a one-way operation. Once you `eject`, you can’t go back!** -`yarn lint`: Run ESLint in the project. +`npm run lint`: Run ESLint in the project. -`yarn lint:fix`: Fix auto-correctable ESLint errors in the project. +`npm run lint:fix`: Fix auto-correctable ESLint errors in the project. -`yarn stylelint`: Run Stylelint in the project. +`npm run stylelint`: Run Stylelint in the project. -`yarn stylelint:fix`: Fix auto-correctable Stylelint errors in the project. +`npm run stylelint:fix`: Fix auto-correctable Stylelint errors in the project. -`yarn codebase:lint`: Run ESLint and Stylelint together in the project. +`npm run codebase:lint`: Run ESLint and Stylelint together in the project. -`yarn codebase:fix`: Fix auto-correctable ESLint and Stylelint errors together in the project. +`npm run codebase:fix`: Fix auto-correctable ESLint and Stylelint errors together in the project. -`yarn cypress:run`: Runs Cypress tests to completion. By default, cypress run will run all tests headlessly in the Electron browser. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-run) +`npm run cypress:run`: Runs Cypress tests to completion. By default, cypress run will run all tests headlessly in the Electron browser. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-run) -`yarn cypress:open`: Opens the Cypress Test Runner. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-open) +`npm run cypress:open`: Opens the Cypress Test Runner. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-open) ## Localization diff --git a/template/gitignore b/template/gitignore index 8f34940..e223f6b 100644 --- a/template/gitignore +++ b/template/gitignore @@ -22,8 +22,6 @@ .env.production.local npm-debug.log* -yarn-debug.log* -yarn-error.log* # editors .vscode diff --git a/template/public/index.html b/template/public/index.html index aa069f2..7e9a060 100644 --- a/template/public/index.html +++ b/template/public/index.html @@ -36,8 +36,8 @@ You can add webfonts, meta tags, or analytics to this file. The build step will place the bundled scripts into the tag. - To begin the development, run `npm start` or `yarn start`. - To create a production bundle, use `npm run build` or `yarn build`. + To begin the development, run `npm start`. + To create a production bundle, use `npm run build`. --> From f36be105f3b7c942f7c3745dafd37cc4afac55de Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 6 Apr 2022 10:01:11 +0700 Subject: [PATCH 33/39] [#69] WIP - Add code coverage in the Test GitHub Action --- template/.github/workflows/test.yml | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index b11f3ae..adcdd5c 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -30,5 +30,31 @@ jobs: - name: Run unit tests run: npm run test - - name: Run integration tests - run: npm run cypress + cypress-run: + name: Run Integration Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Cypress run + uses: cypress-io/github-action@v2 + with: + build: npm run build + start: npm start + + coverage: + name: Merge coverage data + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Jest Coverage report + uses: artiomtr/jest-coverage-report-action@v2.0.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + package-manager: npm + test-script: npm run test + threshold: 80 # prevent PR merge under 80% coverage From c226b671bcdbb8584e5274b79cec504c2ca178f8 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Wed, 20 Apr 2022 15:02:49 +0700 Subject: [PATCH 34/39] [#69] Apply danger-plugin-istanbul-coverage following vote --- template.json | 5 ++++ template/.github/workflows/test.yml | 38 ++++++++-------------------- template/dangerfile.ts | 39 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 template/dangerfile.ts diff --git a/template.json b/template.json index 54cfdf6..45e3486 100644 --- a/template.json +++ b/template.json @@ -44,6 +44,7 @@ "scripts": { "start": "react-scripts -r @cypress/instrument-cra start", "test:coverage": "react-scripts test --coverage --watchAll=false && npm run cypress:run && node ./scripts/coverage-merge.js && nyc report", + "test:merge-coverage": "node ./scripts/coverage-merge.js", "lint": "eslint ./src ./cypress --ext .ts,.tsx", "lint:fix": "eslint ./src ./cypress --ext .ts,.tsx --fix", "stylelint": "stylelint '**/*.scss'", @@ -65,6 +66,10 @@ }, "devDependencies": { "@cypress/instrument-cra": "1.4.0", + "danger": "10.9.0", + "danger-plugin-code-coverage": "1.1.9", + "danger-plugin-istanbul-coverage": "1.6.2", + "danger-plugin-jest-codecov": "0.0.8", "start-server-and-test": "1.14.0" } } diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index adcdd5c..9109506 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Test -on: push +on: pull_request jobs: test: @@ -28,33 +28,15 @@ jobs: run: npm run lint - name: Run unit tests - run: npm run test + run: npm test -- --coverage - cypress-run: - name: Run Integration Tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Cypress run - uses: cypress-io/github-action@v2 - with: - build: npm run build - start: npm start + - name: Run integration tests + run: npm run cypress - coverage: - name: Merge coverage data - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[skip ci]')" - steps: - - name: Checkout - uses: actions/checkout@v1 + - name: Merge code coverage reports + run: npm run test:merge-coverage - - name: Jest Coverage report - uses: artiomtr/jest-coverage-report-action@v2.0.3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - package-manager: npm - test-script: npm run test - threshold: 80 # prevent PR merge under 80% coverage + - name: Danger + run: npx danger ci + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/template/dangerfile.ts b/template/dangerfile.ts new file mode 100644 index 0000000..caf6b5f --- /dev/null +++ b/template/dangerfile.ts @@ -0,0 +1,39 @@ +import { schedule } from 'danger'; +import { istanbulCoverage } from 'danger-plugin-istanbul-coverage'; + +schedule( + istanbulCoverage({ + // Set a custom success message + customSuccessMessage: 'Congrats, coverage is good', + + // Set a custom failure message + customFailureMessage: 'Coverage is a little low, take a look', + + // How to sort the entries in the table + entrySortMethod: 'least-coverage', // || 'alphabetically' || 'most-coverage' || 'largest-file-size' ||'smallest-file-size' || 'uncovered-lines' + + // Add a maximum number of entries to display + numberOfEntries: 15, + + // The location of the istanbul coverage file. + // coveragePath: './.nyc_output/out.json', // The merged JSON coverage data + // Alternatively, if you have multiple coverage summaries, you can merge them into one report + // coveragePaths: ["./coverage/reports/from-cypress.json", "./coverage/reports/from-jest.json"], + // You can also specify the format, instead of letting it be inferred from the file name + coveragePath: { path: './coverage/merged/lcov.info', type: 'lcov' /* || "json-summary" */ }, + + // Which set of files to summarise from the coverage file. + reportFileSet: 'all', // || "modified" || "created" || "createdOrModified" + + // What to do when the PR doesn't meet the minimum code coverage threshold + reportMode: 'message', // || "warn" || "fail" + + // Minimum coverage threshold percentages. Compared against the cumulative coverage of the reportFileSet. + threshold: { + statements: 80, + branches: 80, + functions: 80, + lines: 80, + }, + }) +); From 70b026396aa8b4a181d95737a8399c8f92085e5d Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Thu, 21 Apr 2022 15:15:28 +0700 Subject: [PATCH 35/39] [#65] Update template to use the new API in React 18 --- template.json | 6 +++--- template/src/index.tsx | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/template.json b/template.json index 45e3486..d321155 100644 --- a/template.json +++ b/template.json @@ -4,9 +4,9 @@ "@cypress/code-coverage": "3.9.12", "@nimblehq/eslint-config-nimble": "2.2.1", "@testing-library/cypress": "8.0.2", - "@testing-library/jest-dom": "5.11.4", - "@testing-library/react": "12.1.4", - "@testing-library/user-event": "13.5.0", + "@testing-library/jest-dom": "5.16.4", + "@testing-library/react": "13.1.1", + "@testing-library/user-event": "14.1.1", "@types/jest": "27.4.1", "@types/node": "17.0.21", "@types/react": "17.0.40", diff --git a/template/src/index.tsx b/template/src/index.tsx index 1e7e4d5..a1465c2 100644 --- a/template/src/index.tsx +++ b/template/src/index.tsx @@ -1,22 +1,24 @@ import React, { Suspense } from 'react'; -import ReactDOM from 'react-dom'; import { BrowserRouter } from 'react-router-dom'; +import { createRoot } from 'react-dom/client'; + import App from './App'; import configureI18n from './i18n'; import reportWebVitals from './reportWebVitals'; configureI18n(); -ReactDOM.render( +const container = document.getElementById('root') as HTMLElement; +const root = createRoot(container); +root.render( - , - document.getElementById('root') + ); // If you want to start measuring performance in your app, pass a function From 7410367b37b86bf28f37f24ed49b38d9eb8cc007 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Thu, 21 Apr 2022 17:28:36 +0700 Subject: [PATCH 36/39] [#74] Update ESLint/stylelint configurations to use Nimble shared configurations --- template.json | 31 +++++------- template/.eslintrc.js | 95 +----------------------------------- template/stylelint.config.js | 12 +---- 3 files changed, 16 insertions(+), 122 deletions(-) diff --git a/template.json b/template.json index d321155..d9c2a19 100644 --- a/template.json +++ b/template.json @@ -2,7 +2,8 @@ "package": { "dependencies": { "@cypress/code-coverage": "3.9.12", - "@nimblehq/eslint-config-nimble": "2.2.1", + "@nimblehq/eslint-config-nimble-react": "^1.0.0", + "@nimblehq/stylelint-config-nimble": "^1.0.0", "@testing-library/cypress": "8.0.2", "@testing-library/jest-dom": "5.16.4", "@testing-library/react": "13.1.1", @@ -11,21 +12,10 @@ "@types/node": "17.0.21", "@types/react": "17.0.40", "@types/react-dom": "17.0.13", - "@typescript-eslint/eslint-plugin": "5.15.0", - "@typescript-eslint/parser": "5.15.0", "axios": "0.21.1", "cypress": "9.5.2", "cypress-react-selector": "2.3.16", "eslint": "8.11.0", - "eslint-config-prettier": "8.5.0", - "eslint-import-resolver-typescript": "2.5.0", - "eslint-plugin-cypress": "2.12.1", - "eslint-plugin-import": "2.25.4", - "eslint-plugin-jest": "26.1.1", - "eslint-plugin-jsx-a11y": "6.5.1", - "eslint-plugin-prettier": "4.0.0", - "eslint-plugin-react": "7.29.4", - "eslint-plugin-react-hooks": "4.3.0", "i18next": "21.6.14", "i18next-browser-languagedetector": "6.1.3", "i18next-http-backend": "1.4.0", @@ -34,10 +24,6 @@ "react-router-dom": "6.3.0", "sass": "1.49.11", "stylelint": "14.6.0", - "stylelint-config-property-sort-order-smacss": "9.0.0", - "stylelint-config-sass-guidelines": "9.0.1", - "stylelint-order": "5.0.0", - "stylelint-scss": "4.2.0", "typescript": "4.6.2", "web-vitals": "2.1.4" }, @@ -56,12 +42,19 @@ "cypress:open": "cypress open" }, "jest": { - "collectCoverageFrom": ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"], - "coverageReporters": ["json"] + "collectCoverageFrom": [ + "src/**/*.{js,jsx,ts,tsx}", + "!src/**/*.d.ts" + ], + "coverageReporters": [ + "json" + ] }, "nyc": { "report-dir": "coverage/cypress", - "exclude": ["src/reportWebVitals.ts"], + "exclude": [ + "src/reportWebVitals.ts" + ], "excludeAfterRemap": true }, "devDependencies": { diff --git a/template/.eslintrc.js b/template/.eslintrc.js index 47df027..af73112 100644 --- a/template/.eslintrc.js +++ b/template/.eslintrc.js @@ -1,94 +1,3 @@ module.exports = { - env: { - es6: true, - browser: true, - node: true, - jest: true, - }, - extends: [ - '@nimblehq/eslint-config-nimble', - 'plugin:react/recommended', - 'plugin:react-hooks/recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:jsx-a11y/recommended', - 'plugin:import/errors', - 'plugin:prettier/recommended', - ], - overrides: [ - { - files: 'src/tests/**/*.test.ts', - extends: ['plugin:jest/recommended', 'plugin:jest/style'], - }, - { - files: 'cypress/**/*.ts', - extends: ['plugin:cypress/recommended'], - }, - ], - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { - jsx: true, - }, - }, - rules: { - 'react-hooks/rules-of-hooks': 'error', - 'react-hooks/exhaustive-deps': 'warn', - 'react/jsx-filename-extension': [2, { extensions: ['.tsx'] }], - 'import/order': [ - 'error', - { - groups: ['builtin', 'external', 'internal'], - pathGroups: [ - { - pattern: 'react*', - group: 'external', - position: 'before', - }, - { - pattern: 'css/*|*.scss|*.svg|.png', - group: 'internal', - position: 'after', - }, - ], - pathGroupsExcludedImportTypes: ['react'], - 'newlines-between': 'always', - alphabetize: { - order: 'asc', - caseInsensitive: true, - }, - }, - ], - 'import/extensions': [ - 'error', - 'never', - { - scss: 'always', - svg: 'always', - png: 'always', - json: 'always', - spec: 'always', - }, - ], - 'no-use-before-define': 'off', - 'no-unused-vars': 'off', - 'no-shadow': 'off', - '@typescript-eslint/no-shadow': 'error', - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], - '@typescript-eslint/no-use-before-define': ['error'], - 'prettier/prettier': ['error'], - }, - settings: { - react: { - version: 'detect', - }, - 'import/resolver': { - typescript: {}, - node: { - extensions: ['.js', '.jsx', '.ts', '.tsx'], - moduleDirectory: ['node_modules', 'src/'], - }, - }, - }, -} + extends: ['@nimblehq/eslint-config-nimble-react'], +}; diff --git a/template/stylelint.config.js b/template/stylelint.config.js index c3b2213..b5f47e8 100644 --- a/template/stylelint.config.js +++ b/template/stylelint.config.js @@ -1,11 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires -const sortOrderSmacss = require('stylelint-config-property-sort-order-smacss/generate') - module.exports = { - extends: ['stylelint-config-sass-guidelines'], - plugins: ['stylelint-scss', 'stylelint-order'], - rules: { - 'order/properties-alphabetical-order': null, - 'order/properties-order': [sortOrderSmacss({ emptyLineBefore: 'always' })] - } -} + extends: ['@nimblehq/stylelint-config-nimble'], +}; From 8167bf10031fc41fc6707081d2e8c320bee663d0 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Thu, 21 Apr 2022 17:37:15 +0700 Subject: [PATCH 37/39] [#74] Update workflows --- .github/workflows/test.yml | 4 ++-- template/.github/workflows/test.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f429cee..10ed800 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,8 +29,8 @@ jobs: - name: Run linters working-directory: ./test-app - run: npm run lint - + run: npm run codebase:lint + - name: Run unit tests working-directory: ./test-app run: npm run test diff --git a/template/.github/workflows/test.yml b/template/.github/workflows/test.yml index 9109506..2fdc703 100644 --- a/template/.github/workflows/test.yml +++ b/template/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: run: npm ci - name: Run linter - run: npm run lint + run: npm run codebase:lint - name: Run unit tests run: npm test -- --coverage From b306dc0896bf845989f724edca0c8678c9423c64 Mon Sep 17 00:00:00 2001 From: Hoang Mirs Date: Thu, 21 Apr 2022 17:45:53 +0700 Subject: [PATCH 38/39] [#74] Fix eslint warning --- template/src/types/react-i18next.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/template/src/types/react-i18next.d.ts b/template/src/types/react-i18next.d.ts index 4eea285..49f9877 100644 --- a/template/src/types/react-i18next.d.ts +++ b/template/src/types/react-i18next.d.ts @@ -1,4 +1,3 @@ -import 'react-i18next'; import { TFuncKey } from 'react-i18next'; import defaultRes from '../../public/locales/en/translation.json'; From c71c9170eb7baba3cfca07fa406317d84b86f78a Mon Sep 17 00:00:00 2001 From: Carryall Date: Fri, 29 Apr 2022 11:00:45 +0700 Subject: [PATCH 39/39] Update version to 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 315933a..5754d9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cra-template-nimble", - "version": "2.1.0", + "version": "2.2.0", "keywords": [ "react", "create-react-app",