feat(ci): parallel validation CI

This commit is contained in:
Nodonisko
2024-03-12 17:40:48 +01:00
committed by Vitalij Dovhanyc
parent 504109049f
commit bd18cefe6f
4 changed files with 157 additions and 50 deletions

View File

@@ -0,0 +1,40 @@
name: "Install Node and Yarn Dependencies without build"
description: >
Installs Node.js and dependencies in without building building most of dependencies which is significantly faster.
Only whitelisted in root package.json are builded. It's not recommended to use this actions for building production versions,
because it can produce some unwanted behavior, but it's enough for running validation checks, tests, etc.
runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Yarn Cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
restore-keys: |
yarn-cache-folder-
- name: Modify .yarnrc.yml to disable scripts
shell: bash
run: |
echo -e "\nenableScripts: false" >> .yarnrc.yml
# We don't need to run in hardened mode because it's enough to run hardened install only in "Setup and Cache Dependencies" step
- name: Modify .yarnrc.yml to disable hardened mode
shell: bash
run: |
echo -e "\nenableHardenedMode: false" >> .yarnrc.yml
- name: Install dependencies using Yarn
shell: bash
run: yarn --immutable

16
.github/actions/nx-checkout/action.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: "Checkout and Fetch for Nx"
description: "Checks out the repo with submodules, extracts the branch name, and fetches additional commits for Nx."
runs:
using: "composite"
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Fetch develop and some commits for Nx
shell: bash
# This step should fetch some reasonably small amount branches and commits that Nx affected needs
# It's much faster than doing git fetch depth=1 of all commits
run: |
git fetch origin ${{ steps.extract_branch.outputs.branch }} --deepen=150
git fetch origin develop --deepen=200

View File

@@ -6,26 +6,15 @@ env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_GHACTIONS_TOKEN }}
concurrency:
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
type-check_and_lint:
setup-and-cache:
name: Setup and Cache Dependencies
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: "true"
- name: Extract branch name
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Fetch develop and some commits for Nx
# This step should fetch some reasonably small amount branches and commits that Nx affected needs
# It's much faster than doing git fetch depth=1 of all commits
run: |
git fetch origin ${{ steps.extract_branch.outputs.branch }} --deepen=150
git fetch origin develop --deepen=200
- name: Install node and yarn
uses: actions/setup-node@v4
with:
@@ -35,49 +24,106 @@ jobs:
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Yarn Cache
uses: actions/cache@v4
id: yarn-cache
with:
save-always: true
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
restore-keys: |
yarn-cache-folder-
# We can skip build for all deps because (even for whitelisted) because this is used only to validate yarn.lock and fill cache
- name: Install deps
run: |
yarn --immutable --mode=skip-build
type-check:
name: Type Checking
needs: setup-and-cache
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: "Checkout branches for Nx"
uses: ./.github/actions/nx-checkout
- name: "Minimal yarn install"
uses: ./.github/actions/minimal-yarn-install
- name: Type Check
run: yarn nx:type-check
lint:
name: Linting and formatting
needs: setup-and-cache
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: "Checkout branches for Nx"
uses: ./.github/actions/nx-checkout
- name: "Minimal yarn install"
uses: ./.github/actions/minimal-yarn-install
- name: ESlint Cache
uses: actions/cache@v4
with:
save-always: true
path: |
**/.eslintcache
!**/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/.eslintrc.js') }}
- name: check for duplicate dependencies
run: yarn dedupe --check
# We skip build of deps which is mostly unnecessary in CI and adds about 1 minute to yarn install
# You can whitelist some build in root package.json dependenciesMeta if necessary
- name: install deps
run: |
echo -e "\nenableScripts: false" >> .yarnrc.yml
yarn --immutable
- name: check files for correct formatting
run: yarn nx format:check
- name: verify TS project references
run: yarn verify-project-references
- name: verify workspace resolutions
run: yarn check-workspace-resolutions
- name: msg-system config validation
run: yarn workspace @suite-common/message-system validate-config
- name: lint styles
run: yarn nx:lint:styles
- run: git status
- name: build libs
run: yarn nx:build:libs
- run: git status
- name: lint js
# Cache strategy must be content or it won't work correctly on CI
- name: Lint JS
run: yarn lint:js --cache-strategy content
- name: type check
run: yarn nx:type-check
- run: git status
- name: unit tests
- name: Lint Styles
run: yarn nx:lint:styles
unit-tests:
name: Unit Tests
needs: setup-and-cache
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: "Checkout branches for Nx"
uses: ./.github/actions/nx-checkout
- name: "Minimal yarn install"
uses: ./.github/actions/minimal-yarn-install
- name: Unit Tests
run: yarn nx:test-unit
- name: translation duplicates
build-libs-for-publishing:
name: "Build libs for publishing"
needs: setup-and-cache
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: "Checkout branches for Nx"
uses: ./.github/actions/nx-checkout
- name: "Minimal yarn install"
uses: ./.github/actions/minimal-yarn-install
- name: Build Libs
run: yarn nx:build:libs
other-checks:
name: Other Checks
needs: setup-and-cache
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: "Checkout branches for Nx"
uses: ./.github/actions/nx-checkout
- name: "Minimal yarn install"
uses: ./.github/actions/minimal-yarn-install
- name: Check Files for Correct Formatting
run: yarn nx format:check
- name: Verify TS Project References
run: yarn verify-project-references
- name: Verify Workspace Resolutions
run: yarn check-workspace-resolutions
- name: Msg-system Config Validation
run: yarn workspace @suite-common/message-system validate-config
- name: Translation Duplicates
run: yarn workspace @trezor/suite translations:list-duplicates

13
nx.json
View File

@@ -13,7 +13,7 @@
},
"targetDefaults": {
"build:lib": {
"dependsOn": ["^build:lib"],
"dependsOn": [],
"inputs": [
"^prod",
"{workspaceRoot}/tsconfig.base.json",
@@ -23,7 +23,12 @@
"cache": true
},
"type-check": {
"dependsOn": ["^build:lib", "^type-check", "build:lib"],
"dependsOn": [
"^type-check",
"^guide-pull-content",
"guide-pull-content",
"@suite-common/message-system:build:lib"
],
"inputs": [
"^prod",
"{workspaceRoot}/tsconfig.base.json",
@@ -33,7 +38,7 @@
"cache": true
},
"test:unit": {
"dependsOn": [],
"dependsOn": ["@suite-common/message-system:build:lib"],
"inputs": [
"^prod",
"{workspaceRoot}/jest.config.base.js",
@@ -47,7 +52,7 @@
"cache": true
},
"lint:styles": {
"inputs": ["default"],
"inputs": ["default", "{workspaceRoot}/.stylelintrc"],
"outputs": ["{projectRoot}/.stylelintcache"],
"cache": true
}