Skip to content

Commit

Permalink
Use NX for more jobs in CI (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
shineli1984 authored Jul 24, 2024
1 parent edefb74 commit f0dbc07
Show file tree
Hide file tree
Showing 35 changed files with 66 additions and 8,447 deletions.
27 changes: 27 additions & 0 deletions .github/actions/pr-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "PR Setup"
description: "Do necessary setup for jobs in PR workflow"

runs:
using: "composite"
steps:
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: install depdenencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
shell: bash
run: yarn install --immutable
219 changes: 19 additions & 200 deletions .github/workflows/build-lint-typecheck-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,236 +12,55 @@ env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.TS_IMMUTABLE_SDK_NX_TOKEN }}

jobs:
build:
name: Build
runs-on: ubuntu-latest-4-cores
env:
NODE_OPTIONS: --max-old-space-size=14366
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

# this step will also try to cache the node_modules at the end of the workflow run
- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Check Single Package Version Policy
run: yarn syncpack:check

- name: Build
run: yarn build

- name: Cache build artifacts
uses: actions/cache@v4
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}

build-passport:
name: Build Passport Sample App
runs-on: ubuntu-latest-4-cores
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}

- name: Build passport sample app
run: yarn workspace @imtbl/passport-sdk-sample-app build

typecheck:
name: Typecheck
runs-on: ubuntu-latest-4-cores
needs: build
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: setup
uses: ./.github/actions/pr-setup

- name: Typecheck
run: yarn typecheck

test:
name: Test
runs-on: ubuntu-latest-8-cores
needs: build
env:
NODE_OPTIONS: --max-old-space-size=14366
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: setup
uses: ./.github/actions/pr-setup

- name: Test
run: yarn test

- name: Get reviewing teams
id: reviewer-teams
run: echo "teams=${{ join(github.event.pull_request.requested_teams.*.name, ', ') }}" >> $GITHUB_OUTPUT

- name: Checkout SDK test coverage
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets')}}
run: yarn test:checkout:sdk:coverage
run: yarn test --configuration=ci

- name: Upload Checkout SDK test coverage artifacts
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets')}}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: checkout-sdk-coverage-report
path: ./packages/checkout/sdk/coverage

cypress:
name: Cypress
runs-on: ubuntu-latest-4-cores
needs: build
env:
NODE_OPTIONS: --max-old-space-size=14366
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Get reviewing teams
id: reviewer-teams
run: echo "teams=${{ join(github.event.pull_request.requested_teams.*.name, ', ') }}" >> $GITHUB_OUTPUT

- name: Restore cached build artifacts
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets') && !contains(github.event.pull_request.title, 'SKIP-CY') }}
uses: actions/cache@v4
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}

- name: Checkout-widgets cypress tests
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets') && !contains(github.event.pull_request.title, 'SKIP-CY') }}
working-directory: ./packages/checkout/widgets-lib
run: yarn test:checkout:cypress

- name: Upload cypress videos artifacts
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets') && !contains(github.event.pull_request.title, 'SKIP-CY') }}
uses: actions/upload-artifact@v2
with:
name: checkout-widgets-cypress-videos
path: ./packages/checkout/widgets-lib/cypress/videos

- name: Upload cypress screenshots artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: checkout-widgets-cypress-screenshots
path: ./packages/checkout/widgets-lib/cypress/screenshots
name: coverages
path: ./packages/**/coverage/*

lint:
name: Lint
runs-on: ubuntu-latest-4-cores
needs: build
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: setup
uses: ./.github/actions/pr-setup

- name: Lint
run: yarn lint
32 changes: 16 additions & 16 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"targetDefaults": {
"d": {
"dependsOn": [
"^d"
],
"outputs": [
"{projectRoot}/dist"
],
"dependsOn": ["^d"],
"outputs": ["{projectRoot}/dist"],
"cache": true
},
"lint": {
"cache": true
},
"typecheck": {
"cache": true,
"dependsOn": ["build"]
},
"test": {
"cache": true,
"dependsOn": [
"build"
]
"dependsOn": ["build"],
"outputs": ["{projectRoot}/coverage"],
"configurations": {
"ci": {
"codeCoverage": true
}
}
},
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"{projectRoot}/dist"
],
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/dist"],
"cache": true
}
},
"defaultBase": "main",
"parallel": 5,
"nxCloudAccessToken": "Mzg3ZGY1MWUtYmYyNy00ZmE4LTkyNDAtYjYxZmJmYmE4NWQ3fHJlYWQ="
}
}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@
"dev": "./dev.sh",
"docs:build": "typedoc",
"docs:serve": "http-server ./docs --cors -p 8080 -c-1",
"lint": "nx run-many -t lint --parallel=5 --no-error-on-unmatched-pattern",
"lint": "nx affected -t lint --parallel=5 --no-error-on-unmatched-pattern",
"nx": "nx",
"postinstall": "husky install; ./.husky/install_gitleaks.sh",
"release": "release-it",
"scan:secrets": "./.husky/run_gitleaks.sh",
"syncpack:check": "yarn syncpack list-mismatches",
"syncpack:fix": "yarn syncpack fix-mismatches",
"syncpack:format": "yarn syncpack format",
"test": "nx run-many -t test --parallel=5",
"test:checkout:cypress": "wsrun -p @imtbl/checkout-widgets-lib --exclude-missing -e test:cypress",
"test:checkout:sdk:coverage": "wsrun -p @imtbl/checkout-sdk --exclude-missing -e test:coverage",
"test": "nx affected -t test --parallel=5",
"test:examples": "cd examples/ts-immutable-sample && yarn test && yarn test:e2e",
"test:vpn": "RUN_VPN_TESTS=1 wsrun --exclude-missing -e test",
"typecheck": "wsrun --exclude-missing typecheck"
"typecheck": "nx affected -t typecheck --parallel=5"
},
"workspaces": {
"packages": [
Expand Down
12 changes: 0 additions & 12 deletions packages/checkout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,6 @@ Running changed jest tests on save in watch mode:
yarn test:watch
```

Running cypress tests headless:

```bash
yarn test:cypress
```

Running cypress tests:

```bash
yarn test:cypress:open
```

Linting:

```bash
Expand Down
1 change: 0 additions & 1 deletion packages/checkout/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"start:dev": "CHECKOUT_DEV_MODE=true yarn start",
"start:local": "CHECKOUT_LOCAL_MODE=true yarn start",
"test": "jest test",
"test:coverage": "jest --coverage",
"test:watch": "jest test --watch",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/checkout/widgets-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
"lint:fix": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix",
"start": "yarn clean && NODE_ENV=development rollup --config rollup.config.js --watch",
"test": "jest test --passWithNoTests",
"test:cypress": "NODE_ENV=test cypress run --component --headless",
"test:cypress:open": "NODE_ENV=test cypress open --component --browser electron",
"test:watch": "jest test --passWithNoTests --watch",
"typecheck": "tsc --noEmit"
},
Expand Down
Loading

0 comments on commit f0dbc07

Please sign in to comment.