diff --git a/.github/actions/cache/action.yaml b/.github/actions/cache/action.yaml new file mode 100644 index 000000000..1ff215d73 --- /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 000000000..510737222 --- /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 000000000..a79fabbe6 --- /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: npm run build + unit-test: + 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: 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 b07193358..c46366b9a 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 6c82bfbba..4fb37f9f6 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/packages/components/tsconfig.spec.json b/packages/components/tsconfig.spec.json index 9b2a121d1..f668f992f 100644 --- a/packages/components/tsconfig.spec.json +++ b/packages/components/tsconfig.spec.json @@ -3,7 +3,11 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["jest", "node"] + "types": ["jest", "node"], + "paths": { + "@redhat-cloud-services/frontend-components-utilities": ["packages/utils/src"], + "@redhat-cloud-services/frontend-components-utilities/*": ["packages/utils/src/*"] + } }, "include": [ "jest.config.ts", diff --git a/packages/notifications/tsconfig.spec.json b/packages/notifications/tsconfig.spec.json index 9b2a121d1..40f1b7c08 100644 --- a/packages/notifications/tsconfig.spec.json +++ b/packages/notifications/tsconfig.spec.json @@ -3,7 +3,13 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["jest", "node"] + "types": ["jest", "node"], + "paths": { + "@redhat-cloud-services/frontend-components-utilities": ["packages/utils/src"], + "@redhat-cloud-services/frontend-components-utilities/*": ["packages/utils/src/*"], + "@redhat-cloud-services/frontend-components": ["packages/components/src"], + "@redhat-cloud-services/frontend-components/*": ["packages/components/src/*"] + } }, "include": [ "jest.config.ts", diff --git a/tsconfig.base.json b/tsconfig.base.json index c53d3a07f..153b38356 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,