Skip to content

Commit

Permalink
Force manual build to run lint to avoid unnecessary rebuilds (strapi#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin authored Apr 28, 2023
1 parent 7bbc3b8 commit dceea72
Show file tree
Hide file tree
Showing 47 changed files with 829 additions and 646 deletions.
6 changes: 6 additions & 0 deletions .github/actions/check-pr-status/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
preset: '../../../jest-preset.unit.js',
displayName: 'Github action check-pr-status',
};
14 changes: 14 additions & 0 deletions .github/filters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
backend:
- 'packages/**/package.json'
- 'packages/**/server/**/*.(js|ts)'
- 'packages/**/strapi-server.js'
- 'packages/{utils,generators,cli,providers}/**'
- 'packages/core/*/{lib,bin,ee}/**'
- 'api-tests/**'
frontend:
- 'packages/**/package.json'
- 'packages/**/admin/src/**'
- 'packages/**/admin/ee/admin/**'
- 'packages/**/strapi-admin.js'
- 'packages/core/helper-plugin/**'
- 'packages/admin-test-utils/**'
3 changes: 0 additions & 3 deletions .github/jest.config.js

This file was deleted.

28 changes: 27 additions & 1 deletion .github/workflows/skipped_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,28 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
nonDoc: ${{ steps.filter.outputs.nonDoc }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: .github/filters.yaml

lint:
name: 'lint (node: ${{ matrix.node }})'
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18]
node: [18]
steps:
- run: echo "Skipped"

Expand All @@ -34,6 +50,16 @@ jobs:
name: 'unit_front (node: ${{ matrix.node }})'
needs: [lint]
runs-on: ubuntu-latest
strategy:
matrix:
node: [18]
steps:
- run: echo "Skipped"

build:
name: 'build (node: ${{ matrix.node }})'
needs: [changes, lint, unit_front]
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18]
Expand Down
49 changes: 35 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,25 @@ permissions:
actions: read

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
id: filter
with:
filters: .github/filters.yaml

lint:
name: 'lint (node: ${{ matrix.node }})'
needs: [changes]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -44,7 +61,7 @@ jobs:

unit_back:
name: 'unit_back (node: ${{ matrix.node }})'
needs: [lint]
needs: [changes, lint]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -69,7 +86,7 @@ jobs:

unit_front:
name: 'unit_front (node: ${{ matrix.node }})'
needs: [lint]
needs: [changes, lint]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -88,13 +105,13 @@ jobs:
- uses: nrwl/nx-set-shas@v3
- run: yarn install --immutable
- name: Run build:ts for admin-test-utils
run: yarn build:ts --projects=@strapi/admin-test-utils --skip-nx-cache
run: yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
- name: Run test
run: yarn nx affected --target=test:front --nx-ignore-cycles

build:
name: 'build (node: ${{ matrix.node }})'
needs: [lint, unit_front]
needs: [changes, lint, unit_front]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -113,8 +130,9 @@ jobs:
run: yarn build --projects=@strapi/admin,@strapi/helper-plugin

api_ce_pg:
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[CE] API Integration (postgres, node: ${{ matrix.node }})'
strategy:
matrix:
Expand Down Expand Up @@ -153,8 +171,9 @@ jobs:
dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

api_ce_mysql:
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[CE] API Integration (mysql:latest, client: ${{ matrix.db_client }}, node: ${{ matrix.node }})'
strategy:
matrix:
Expand Down Expand Up @@ -192,8 +211,9 @@ jobs:
dbOptions: '--dbclient=${{ matrix.db_client }} --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

api_ce_mysql_5:
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[CE] API Integration (mysql:5, client: ${{ matrix.db_client }} , node: ${{ matrix.node }})'
strategy:
matrix:
Expand Down Expand Up @@ -230,8 +250,9 @@ jobs:
dbOptions: '--dbclient=${{ matrix.db_client }} --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

api_ce_sqlite:
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[CE] API Integration (sqlite, client: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
strategy:
matrix:
Expand All @@ -256,9 +277,9 @@ jobs:
# EE
api_ee_pg:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[EE] API Integration (postgres, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
if: needs.changes.outputs.backend == 'true' && github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
strategy:
Expand Down Expand Up @@ -300,9 +321,9 @@ jobs:

api_ee_mysql:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[EE] API Integration (mysql:latest, client: ${{ matrix.db_client }}, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
if: needs.changes.outputs.backend == 'true' && github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
strategy:
Expand Down Expand Up @@ -343,9 +364,9 @@ jobs:

api_ee_sqlite:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
needs: [changes, lint, unit_back, unit_front]
name: '[EE] API Integration (sqlite, client: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
if: needs.changes.outputs.backend == 'true' && github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
strategy:
Expand Down
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
yarn nx affected:lint --uncommitted --nx-ignore-cycles
12 changes: 12 additions & 0 deletions jest.config.front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

/** @type {import('jest').Config} */
const config = {
projects: [
'<rootDir>/packages/plugins/*/jest.config.front.js',
'<rootDir>/packages/core/*/jest.config.front.js',
'<rootDir>/scripts/*/jest.config.front.js',
],
};

module.exports = config;
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

/** @type {import('jest').Config} */
const config = {
projects: [
'<rootDir>/packages/plugins/*/jest.config.js',
'<rootDir>/packages/utils/*/jest.config.js',
'<rootDir>/packages/generators/*/jest.config.js',
'<rootDir>/packages/core/*/jest.config.js',
'<rootDir>/packages/providers/*/jest.config.js',
'<rootDir>/.github/actions/*/jest.config.js',
],
};

module.exports = config;
50 changes: 50 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

const path = require('path');
const fs = require('fs');
const findUp = require('find-up');

const includes = ['packages', '.github'];

const root = path.resolve(__dirname);

function extractPackageName(pkgJsonPath) {
return JSON.parse(fs.readFileSync(pkgJsonPath).toString()).name;
}

function getLintCommand(files) {
const affectedFolders = new Set();

for (const file of files) {
const r = findUp.sync('package.json', { cwd: file });
const relPath = path.relative(root, r);

if (includes.some((incl) => relPath.startsWith(incl))) {
affectedFolders.add(r);
}
}

const affectedPackages = [...affectedFolders].map(extractPackageName);

if (affectedPackages.length === 0) {
return null;
}
return `nx run-many -t lint -p ${affectedPackages.join()}`;
}

function getCodeCommands(files) {
const lintCmd = getLintCommand(files);

const prettierCmd = `prettier --write ${files.join(' ')}`;

if (lintCmd) {
return [lintCmd, prettierCmd];
}

return [prettierCmd];
}

module.exports = {
'*.{js,ts}': getCodeCommands,
'*.{md,css,scss,yaml,yml}': ['prettier --write'],
};
9 changes: 3 additions & 6 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
"dependsOn": ["^build:ts"]
},
"test:unit": {
"inputs": ["default", "{workspaceRoot}/jest-preset.unit.js"],
"dependsOn": ["build:ts"]
"inputs": ["default", "{workspaceRoot}/jest-preset.unit.js"]
},
"test:front": {
"inputs": ["default", "{workspaceRoot}/jest-preset.front.js"],
"dependsOn": ["^build"]
"inputs": ["default", "{workspaceRoot}/jest-preset.front.js"]
},
"lint": {
"inputs": [
Expand All @@ -44,8 +42,7 @@
"{projectRoot}/.eslintignore",
"{projectRoot}/tsconfig.eslint.json",
"{workspaceRoot}/packages/utils/eslint-config-custom/**/*"
],
"dependsOn": ["build:ts"]
]
}
},
"tasksRunnerOptions": {
Expand Down
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,21 @@
"format:other": "yarn prettier:other --write",
"prettier:code": "prettier --cache --cache-strategy content \"**/*.{js,ts}\"",
"prettier:other": "prettier --cache --cache-strategy content \"**/*.{md,css,scss,yaml,yml}\"",
"test:front": "cross-env IS_EE=true nx run-many --target=test:front --nx-ignore-cycles",
"test:front:watch": "cross-env IS_EE=true nx run-many --target=test:front:watch --nx-ignore-cycles",
"test:front:update": "yarn test:front -u",
"test:front:ce": "cross-env IS_EE=false nx run-many --target=test:front --nx-ignore-cycles",
"test:front:watch:ce": "cross-env IS_EE=false nx run-many --target=test:front:watch --nx-ignore-cycles",
"test:front:all": "cross-env IS_EE=true nx run-many --target=test:front --nx-ignore-cycles",
"test:front": "cross-env IS_EE=true jest --config jest.config.front.js",
"test:front:watch": "cross-env IS_EE=true run test:front --watch",
"test:front:update": "run test:front -u",
"test:front:all:ce": "cross-env IS_EE=false nx run-many --target=test:front:ce --nx-ignore-cycles",
"test:front:ce": "cross-env IS_EE=false run test:front",
"test:front:watch:ce": "cross-env IS_EE=false run test:front --watch",
"test:front:update:ce": "yarn test:front:ce -u",
"test:unit": "nx run-many --target=test:unit --nx-ignore-cycles",
"test:unit:watch": "nx run-many --target=test:unit:watch --nx-ignore-cycles",
"test:unit:all": "nx run-many --target=test:unit --nx-ignore-cycles",
"test:unit": "jest --config jest.config.js",
"test:unit:watch": "run test:unit --watch",
"test:api": "node test/api.js",
"test:generate-app": "node test/create-test-app.js",
"doc:api": "node scripts/open-api/serve.js"
},
"lint-staged": {
"*.{js,ts,md,css,scss,yaml,yml}": [
"prettier --write"
]
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
Expand Down Expand Up @@ -91,6 +89,7 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"execa": "1.0.0",
"find-up": "5.0.0",
"fs-extra": "10.1.0",
"get-port": "5.1.1",
"glob": "7.2.3",
Expand Down
1 change: 1 addition & 0 deletions packages/core/admin/jest.config.front.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
module.exports = {
preset: '../../../jest-preset.front.js',
collectCoverageFrom: ['<rootDir>/packages/core/admin/admin/**/*.js'],
displayName: 'Core admin',
};
1 change: 1 addition & 0 deletions packages/core/admin/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
preset: '../../../jest-preset.unit.js',
displayName: 'Core admin',
};
1 change: 1 addition & 0 deletions packages/core/content-manager/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
preset: '../../../jest-preset.unit.js',
displayName: 'Core content-manager',
};
1 change: 1 addition & 0 deletions packages/core/content-type-builder/jest.config.front.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
preset: '../../../jest-preset.front.js',
displayName: 'Core content-type-builder',
};
1 change: 1 addition & 0 deletions packages/core/content-type-builder/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
preset: '../../../jest-preset.unit.js',
displayName: 'Core content-type-builder',
};
Loading

0 comments on commit dceea72

Please sign in to comment.