From fd2fecc12a730ef0ca490dc32e38d7f78d5d5b58 Mon Sep 17 00:00:00 2001 From: Martin Marosi Date: Fri, 18 Oct 2024 09:30:19 +0200 Subject: [PATCH] chore: setup gh actions ci workflow --- .github/actions/cache/action.yaml | 16 +++++ .github/actions/cypress-cache/action.yaml | 11 +++ .github/workflows/ci.yaml | 86 +++++++++++++++++++++++ nx.json | 2 +- package.json | 2 +- tsconfig.base.json | 2 +- 6 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 .github/actions/cache/action.yaml create mode 100644 .github/actions/cypress-cache/action.yaml create mode 100644 .github/workflows/ci.yaml diff --git a/.github/actions/cache/action.yaml b/.github/actions/cache/action.yaml new file mode 100644 index 0000000000..1ff215d738 --- /dev/null +++ b/.github/actions/cache/action.yaml @@ -0,0 +1,16 @@ +name: Node modules cache +description: Retrieve and cache project node_modules +runs: + using: "composite" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + # cache node modules for all jobs to use + - uses: actions/cache@v4 + id: node_modules-cache + with: + path: | + **/node_modules + key: install-cache-${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} diff --git a/.github/actions/cypress-cache/action.yaml b/.github/actions/cypress-cache/action.yaml new file mode 100644 index 0000000000..510737222b --- /dev/null +++ b/.github/actions/cypress-cache/action.yaml @@ -0,0 +1,11 @@ +name: Cypress runner cache +description: Retrieve and cache the cypress runner +runs: + using: "composite" + steps: + # cache cypress runner + - uses: actions/cache@v4 + id: cypress-cache + with: + path: ~/.cache/Cypress + key: cypress-runner-cache-${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000000..619c4c8399 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,86 @@ +name: Frontend components CI pipeline +on: + pull_request: + branches: + - master + - nx + push: + branches: + - master + - nx + +jobs: + install: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: nrwl/nx-set-shas@v4 + - uses: './.github/actions/cache' + - uses: './.github/actions/cypress-cache' + - name: Install dependencies + run: npm i + build: + runs-on: ubuntu-latest + needs: install + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Use Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20.x + - uses: nrwl/nx-set-shas@v4 + - uses: './.github/actions/cache' + - name: Build + run: npx nx run-many -t build --exclude=demo,@redhat-cloud-services/frontend-components-pdf-generator,@redhat-cloud-services/frontend-components-charts + unit-test: + runs-on: ubuntu-latest + needs: [install, build] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Use Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20.x + - uses: nrwl/nx-set-shas@v4 + - uses: './.github/actions/cache' + - name: Run unit tests + run: npm run test:unit + component-test: + runs-on: ubuntu-latest + needs: install + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: nrwl/nx-set-shas@v4 + - uses: './.github/actions/cache' + - uses: './.github/actions/cypress-cache' + - name: Install deps + shell: bash + run: npm i + - name: Run component tests + uses: cypress-io/github-action@v6 + with: + command: npx nx affected -t test:component --exclude=demo --configuration=ci --parallel=1 + lint: + runs-on: ubuntu-latest + needs: install + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: nrwl/nx-set-shas@v4 + - uses: './.github/actions/cache' + - name: Lint + run: npx nx affected -t test:lint --exclude=demo diff --git a/nx.json b/nx.json index b071933583..c46366b9ac 100644 --- a/nx.json +++ b/nx.json @@ -19,7 +19,7 @@ "cache": true } }, - "defaultBase": "master", + "defaultBase": "origin/nx", "plugins": [ { "plugin": "@nx/eslint/plugin", diff --git a/package.json b/package.json index 6c82bfbba9..4fb37f9f60 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,7 @@ "lint": "nx run-many -t lint --exclude=@redhat-cloud-services/frontend-components-pdf-generator,@redhat-cloud-services/frontend-components-charts", "serve:demo": "nx run demo:serve", "test:unit": "nx run-many -t test:unit --exclude=demo", - "test:component": "nx run-many -t test:component --exclude=demo ----parallel=1" + "test:component": "nx run-many -t test:component --exclude=demo --parallel=1" }, "description": "Components for Red Hat Cloud Services", "repository": { diff --git a/tsconfig.base.json b/tsconfig.base.json index c53d3a07f9..153b383564 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -4,7 +4,7 @@ "target": "es5", "module": "commonjs", "lib": ["es2020", "dom"], - "allowJs": false, + "allowJs": true, "jsx": "react-jsx", "declaration": true, "sourceMap": true,