From 4a1f8ee59d22c393c982441339ee12ec6ae2eb61 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:10:03 +0800 Subject: [PATCH 01/13] build: github actions --- .github/workflows/ci-cd.yml | 13 --------- .github/workflows/pull-request.yml | 47 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 13 deletions(-) delete mode 100644 .github/workflows/ci-cd.yml create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 480b09e1b0..0000000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: test-workflow -on: - pull_request: - branches: - - main - -jobs: - sample-job: - runs-on: ubuntu-latest - steps: - - uses: actions/hello-world-javascript-action@main - with: - who-to-greet: 'Deriv Team' \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000000..80281d9a34 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,47 @@ +name: SmartTrader Test Workflow + +on: pull_request + +jobs: + build_and_test: + name: Build and Test + runs-on: Runner_16cores_Deriv-app + steps: + # checkout the repository content to github runner + - name: Checkout + uses: actions/checkout@v3 + + # setup nodejs environment + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 18.x + + # cache the dependencies to speed up the build + - name: Cache dependencies + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + # install dependencies + - name: Install dependencies + run: npm i + + # build the react app + - name: Build + run: npm run build + + # run tests + - name: Run tests + run: npm run test + + # deploy the react app to github pages From f5f6dfdafc775a48284e264097705da8a642b7c2 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:12:24 +0800 Subject: [PATCH 02/13] fix: workflow runner --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 80281d9a34..722ef1e72c 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,7 +5,7 @@ on: pull_request jobs: build_and_test: name: Build and Test - runs-on: Runner_16cores_Deriv-app + runs-on: ubuntu-latest steps: # checkout the repository content to github runner - name: Checkout From 72f792493233aea25fd3a611520c3c943967d932 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:14:30 +0800 Subject: [PATCH 03/13] fix: build error --- src/utils/cookies.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/cookies.ts b/src/utils/cookies.ts index 084e64e520..09be6491ce 100644 --- a/src/utils/cookies.ts +++ b/src/utils/cookies.ts @@ -1,7 +1,7 @@ -export const getCookiesObject = (cookies) => {}; +export const getCookiesObject = () => {}; -export const getDataObjFromCookies = (cookies, fields) => {}; +export const getDataObjFromCookies = () => {}; -export const getDataLink = (data) => {}; +export const getDataLink = () => {}; export const getCookiesFields = () => []; From a7c1d3d32f0e95affca7123410e8dbb1e89ec3a9 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:31:53 +0800 Subject: [PATCH 04/13] fix: ci error --- .../common/loading/__test__/loading.test.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/components/common/loading/__test__/loading.test.tsx diff --git a/src/components/common/loading/__test__/loading.test.tsx b/src/components/common/loading/__test__/loading.test.tsx new file mode 100644 index 0000000000..83e4ee4712 --- /dev/null +++ b/src/components/common/loading/__test__/loading.test.tsx @@ -0,0 +1,10 @@ +// Test for passing the github actions +import { describe, expect, test } from "vitest"; +import { render, screen } from "@testing-library/react"; +import Loading from ".."; + +describe("Loading component", () => + test("should show loading text", () => { + render(); + expect(screen.getByText("loading")).toBeInTheDocument(); + })); From 8fc22b07b7cd0994fca73ef6a2c431ae88593bad Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:35:12 +0800 Subject: [PATCH 05/13] fix: cache issue --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 722ef1e72c..2318fe5bb4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -25,7 +25,7 @@ jobs: cache-name: cache-node-modules with: # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.node_modules + path: ~/.npm key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }} restore-keys: | ${{ runner.os }}-build-${{ env.cache-name }}- From 2c479efeb2a48a847dad63eb5288ab3faa194b85 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 12:36:59 +0800 Subject: [PATCH 06/13] build: rebuild --- src/components/common/loading/__test__/loading.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/common/loading/__test__/loading.test.tsx b/src/components/common/loading/__test__/loading.test.tsx index 83e4ee4712..8a076d170a 100644 --- a/src/components/common/loading/__test__/loading.test.tsx +++ b/src/components/common/loading/__test__/loading.test.tsx @@ -1,4 +1,5 @@ // Test for passing the github actions +// TODO should update this test later import { describe, expect, test } from "vitest"; import { render, screen } from "@testing-library/react"; import Loading from ".."; From 93092bfdd0522e0975d21ae57cb176a8cd428670 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 13:38:12 +0800 Subject: [PATCH 07/13] build: added the cache configs --- .github/actions/npm_install_from_cache.yml | 16 ++++++++++++ .github/actions/setup_node.yml | 9 +++++++ .github/workflows/pull-request.yml | 30 +++------------------- 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 .github/actions/npm_install_from_cache.yml create mode 100644 .github/actions/setup_node.yml diff --git a/.github/actions/npm_install_from_cache.yml b/.github/actions/npm_install_from_cache.yml new file mode 100644 index 0000000000..8948895602 --- /dev/null +++ b/.github/actions/npm_install_from_cache.yml @@ -0,0 +1,16 @@ +# cache the dependencies to speed up the build +name: npm_install_from_cache +description: Install npm packages from cache +runs: + using: composite + steps: + - name: Cache dependencies + id: cache-node-modules + uses: actions/cache/restore@v3 + with: + key: v1-deps-{{ checksum "package-lock.json" }} + path: node_modules + - name: Install npm dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm install + shell: bash diff --git a/.github/actions/setup_node.yml b/.github/actions/setup_node.yml new file mode 100644 index 0000000000..ca2791ec43 --- /dev/null +++ b/.github/actions/setup_node.yml @@ -0,0 +1,9 @@ +name: Setup Node +description: Setup Node.js environment +runs: + using: composite + steps: + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2318fe5bb4..504bf2fe5e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -9,39 +9,17 @@ jobs: steps: # checkout the repository content to github runner - name: Checkout - uses: actions/checkout@v3 - + uses: actions/checkout@v4 # setup nodejs environment - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: 18.x - - # cache the dependencies to speed up the build + uses: ./.github/actions/setup_node + # cache the dependencies to speed up the build and then install dependencies - name: Cache dependencies - id: cache-npm - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - # install dependencies - - name: Install dependencies - run: npm i - + uses: ./.github/actions/npm_install_from_cache # build the react app - name: Build run: npm run build - # run tests - name: Run tests run: npm run test - # deploy the react app to github pages From ce42c9b36eade0067545667f94a796e3abd7b32c Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 13:39:56 +0800 Subject: [PATCH 08/13] fix: actions path --- .github/workflows/pull-request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 504bf2fe5e..dc27a9da12 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -12,10 +12,10 @@ jobs: uses: actions/checkout@v4 # setup nodejs environment - name: Setup Node.js environment - uses: ./.github/actions/setup_node + uses: ./actions/setup_node # cache the dependencies to speed up the build and then install dependencies - name: Cache dependencies - uses: ./.github/actions/npm_install_from_cache + uses: ./actions/npm_install_from_cache # build the react app - name: Build run: npm run build From 2ba23cdd1d24350c053da870d8e5f399287f412d Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 13:41:52 +0800 Subject: [PATCH 09/13] fix: action path --- .../action.yml} | 0 .github/actions/{setup_node.yml => setup_node/action.yml} | 0 .github/workflows/pull-request.yml | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename .github/actions/{npm_install_from_cache.yml => npm_install_from_cache/action.yml} (100%) rename .github/actions/{setup_node.yml => setup_node/action.yml} (100%) diff --git a/.github/actions/npm_install_from_cache.yml b/.github/actions/npm_install_from_cache/action.yml similarity index 100% rename from .github/actions/npm_install_from_cache.yml rename to .github/actions/npm_install_from_cache/action.yml diff --git a/.github/actions/setup_node.yml b/.github/actions/setup_node/action.yml similarity index 100% rename from .github/actions/setup_node.yml rename to .github/actions/setup_node/action.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index dc27a9da12..504bf2fe5e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -12,10 +12,10 @@ jobs: uses: actions/checkout@v4 # setup nodejs environment - name: Setup Node.js environment - uses: ./actions/setup_node + uses: ./.github/actions/setup_node # cache the dependencies to speed up the build and then install dependencies - name: Cache dependencies - uses: ./actions/npm_install_from_cache + uses: ./.github/actions/npm_install_from_cache # build the react app - name: Build run: npm run build From 23f3c6425071e85d7f881f86e97b013537418bb7 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 13:43:14 +0800 Subject: [PATCH 10/13] fix: cacche --- .github/actions/npm_install_from_cache/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/npm_install_from_cache/action.yml b/.github/actions/npm_install_from_cache/action.yml index 8948895602..3b9b508728 100644 --- a/.github/actions/npm_install_from_cache/action.yml +++ b/.github/actions/npm_install_from_cache/action.yml @@ -1,4 +1,3 @@ -# cache the dependencies to speed up the build name: npm_install_from_cache description: Install npm packages from cache runs: From f6c8eba0fc9d1e6f79e4a992b8a4f89cc275a310 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 14:21:23 +0800 Subject: [PATCH 11/13] build: added an actin for handling the cache saving --- .github/actions/invalidate_master_cache/action.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/actions/invalidate_master_cache/action.yml diff --git a/.github/actions/invalidate_master_cache/action.yml b/.github/actions/invalidate_master_cache/action.yml new file mode 100644 index 0000000000..5a9dbcef3e --- /dev/null +++ b/.github/actions/invalidate_master_cache/action.yml @@ -0,0 +1,11 @@ +name: invalidate_npm_cache +description: Invalidate the Master NPM cache +runs: + using: composite + steps: + - name: save_cache + uses: actions/cache/save@v3 + with: + path: ./node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} + \ No newline at end of file From d8e55b8999016594162ff403853265a7f844c151 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 14:22:48 +0800 Subject: [PATCH 12/13] fix: empty line --- .github/actions/invalidate_master_cache/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/invalidate_master_cache/action.yml b/.github/actions/invalidate_master_cache/action.yml index 5a9dbcef3e..fc9861bb37 100644 --- a/.github/actions/invalidate_master_cache/action.yml +++ b/.github/actions/invalidate_master_cache/action.yml @@ -8,4 +8,3 @@ runs: with: path: ./node_modules key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} - \ No newline at end of file From 1d89c2a22b99eebcb933cde0a18f49fa82c45139 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Fri, 6 Oct 2023 14:26:00 +0800 Subject: [PATCH 13/13] fix: cache key --- .github/actions/invalidate_master_cache/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/invalidate_master_cache/action.yml b/.github/actions/invalidate_master_cache/action.yml index fc9861bb37..6317bdcac8 100644 --- a/.github/actions/invalidate_master_cache/action.yml +++ b/.github/actions/invalidate_master_cache/action.yml @@ -7,4 +7,4 @@ runs: uses: actions/cache/save@v3 with: path: ./node_modules - key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} + key: v1-deps-{{ checksum "package-lock.json" }}