Skip to content

Commit

Permalink
chore: convert to inferred tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Sep 1, 2024
1 parent 6f31097 commit e10afdc
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 388 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e" targets have been requested
- run: pnpm exec nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e-ci" --with-env-vars="ANDROID_SDK_VERSION,FLUTTER_VERSION,JDK_VERSION"
- run: pnpm exec nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e" --with-env-vars="ANDROID_SDK_VERSION,FLUTTER_VERSION,JDK_VERSION"

# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track develop origin/develop || exit 0
Expand All @@ -46,4 +46,4 @@ jobs:
main-branch-name: 'develop'

- run: pnpm exec nx-cloud record -- nx format:check
- run: pnpm exec nx affected -t lint test build e2e-ci --parallel=5 --exclude=smoke --codeCoverage
- run: pnpm exec nx affected -t lint test-ci build e2e --parallel=5 --exclude=smoke
2 changes: 1 addition & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
env:
NX_E2E_CI_CACHE_KEY: smoke-gha-${{ matrix.os }}-${{ matrix.node-version }}
NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}
run: pnpm nx test smoke
run: pnpm nx e2e-ci smoke
12 changes: 1 addition & 11 deletions e2e/nx-flutter-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
"sourceRoot": "e2e/nx-flutter-e2e/tests",
"tags": ["e2e"],
"implicitDependencies": ["nx-flutter"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/nx-flutter-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
12 changes: 1 addition & 11 deletions e2e/nx-ktor-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
"sourceRoot": "e2e/nx-ktor-e2e/tests",
"tags": ["e2e"],
"implicitDependencies": ["nx-ktor"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/nx-ktor-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
12 changes: 1 addition & 11 deletions e2e/nx-melos-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
"sourceRoot": "e2e/nx-melos-e2e/tests",
"tags": ["e2e"],
"implicitDependencies": ["nx-melos"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/nx-melos-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
20 changes: 16 additions & 4 deletions e2e/nx-micronaut-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@
"implicitDependencies": ["nx-micronaut"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"inputs": [
"default",
"^default",
"{workspaceRoot}/jest.preset.js",
{
"externalDependencies": ["jest"]
}
],
"options": {
"jestConfig": "e2e/nx-micronaut-e2e/jest.config.ts",
"passWithNoTests": true,
"runInBand": true
},
"dependsOn": ["^build"]
"dependsOn": ["^build"],
"configurations": {
"ci": {
"ci": true,
"coverage": true
}
}
}
}
}
12 changes: 1 addition & 11 deletions e2e/nx-quarkus-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
"sourceRoot": "e2e/nx-quarkus-e2e/tests",
"tags": ["e2e"],
"implicitDependencies": ["nx-quarkus"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/nx-quarkus-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
12 changes: 1 addition & 11 deletions e2e/nx-spring-boot-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
"sourceRoot": "e2e/nx-spring-boot-e2e/tests",
"tags": ["e2e"],
"implicitDependencies": ["nx-spring-boot"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/nx-spring-boot-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
11 changes: 1 addition & 10 deletions e2e/smoke/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,5 @@
"nx-ktor",
"nx-melos"
],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/e2e/smoke"],
"options": {
"jestConfig": "e2e/smoke/jest.config.ts"
},
"dependsOn": ["^build"]
}
}
"targets": {}
}
173 changes: 173 additions & 0 deletions e2e/smoke/tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { getPackageManagerCommand } from '@nx/devkit';
import {
createTestProject,
isLocalNxMatchingLatestFeatureVersion,
runNxCommand,
} from '@nxrocks/common/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs-extra';

process.env.NODE_OPTIONS = '--max-old-space-size=8192'; // to avoid oom error during the tests

let projectDirectory: string;

const execSyncOptions: (cwd?: string) => {
silenceError?: boolean;
env?: NodeJS.ProcessEnv;
cwd?: string;
} = (cwd: string = projectDirectory) => ({
cwd: cwd,
env: {
...process.env,
GIT_COMMITTER_NAME: 'Smoke Test CI',
GIT_COMMITTER_EMAIL: '[email protected]',
GIT_AUTHOR_NAME: 'Smoke Test CI',
GIT_AUTHOR_EMAIL: '[email protected]',
},
silentError: 'false',
});

const bootapp = 'bootapp';
const bootlib = 'bootlib';
const quarkusapp = 'quarkusapp';
const quarkuslib = 'quarkuslib';
const flutterapp = 'flutterapp';
const flutterlib = 'flutterlib';
const mnApp = 'mnapp';
const krApp = 'krapp';

describe('nxrocks smoke tests', () => {
afterEach(async () => {
if (!process.env.KEEP_SMOKE_TESTS_DIR) {
// Cleanup the test project
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
} else {
console.warn(
`Keeping smoke test directory at '${projectDirectory}'. Do not forget to remove it when done!`
);
}
});

it.each`
pkgManager | workspaceVersion | pluginVersion
${'npm'} | ${'latest'} | ${'0.0.0-e2e'}
${'yarn'} | ${'latest'} | ${'0.0.0-e2e'}
${'pnpm'} | ${'latest'} | ${'0.0.0-e2e'}
${'npm'} | ${'local'} | ${'0.0.0-e2e'}
${'yarn'} | ${'local'} | ${'0.0.0-e2e'}
${'pnpm'} | ${'local'} | ${'0.0.0-e2e'}
`(
`should sucessfully run using '$workspaceVersion' Nx workspace, $pluginVersion plugins version and $pkgManager package manager`,
async ({ pkgManager, workspaceVersion, pluginVersion }) => {
if (!process.env.CI && !process.env.FORCE_SMOKE_TESTS) {
console.log(
'Skipping smoke test because not running on CI and FORCE_SMOKE_TESTS is not set'
);
return;
}

if (
workspaceVersion === 'latest' &&
isLocalNxMatchingLatestFeatureVersion()
) {
console.log(
'Skipping current test case because we are already using most recent version of Nx'
);
return;
}

projectDirectory = createTestProject(
pkgManager,
'nxrocks-smoke',
workspaceVersion
);

execSync('git init', execSyncOptions());

const pluginPkgs = [
`@nxrocks/nx-spring-boot@${pluginVersion}`,
`@nxrocks/nx-quarkus@${pluginVersion}`,
`@nxrocks/nx-micronaut@${pluginVersion}`,
`@nxrocks/nx-flutter@${pluginVersion}`,
`@nxrocks/nx-melos@${pluginVersion}`,
`@nxrocks/nx-ktor@${pluginVersion}`,
].join(' ');

execSync(
`${getPackageManagerCommand(pkgManager).addDev} ${pluginPkgs}`,
execSyncOptions(projectDirectory)
);

runNxCommand(
`generate @nxrocks/nx-spring-boot:new ${bootapp} --skip-format=false --projectType application --no-interactive`,
pkgManager,
execSyncOptions()
);
runNxCommand(
`generate @nxrocks/nx-spring-boot:new ${bootlib} --skip-format=false --projectType library --no-interactive`,
pkgManager,
execSyncOptions()
);

runNxCommand(
`generate @nxrocks/nx-quarkus:new ${quarkusapp} --skip-format=false --projectType application --no-interactive`,
pkgManager,
execSyncOptions()
);
runNxCommand(
`generate @nxrocks/nx-quarkus:new ${quarkuslib} --skip-format=false --projectType library --no-interactive`,
pkgManager,
execSyncOptions()
);

runNxCommand(
`generate @nxrocks/nx-micronaut:new ${mnApp} --skip-format=false --no-interactive`,
pkgManager,
execSyncOptions()
);

runNxCommand(
`generate @nxrocks/nx-melos:init --scriptNameSeparator=-`,
pkgManager,
execSyncOptions()
);

runNxCommand(
`generate @nxrocks/nx-ktor:new ${krApp} --skip-format=false --no-interactive`,
pkgManager,
execSyncOptions()
);

runNxCommand(
`generate @nxrocks/nx-flutter:new ${flutterapp} --template app --no-interactive`,
pkgManager,
execSyncOptions()
);
runNxCommand(
`generate @nxrocks/nx-flutter:new ${flutterlib} --template plugin --no-interactive`,
pkgManager,
execSyncOptions()
);

execSync(`git add -A`, execSyncOptions());
execSync(`git commit -am "chore: scaffold projects"`, execSyncOptions());

runNxCommand(`clean ${bootapp}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${bootlib}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${quarkusapp}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${quarkuslib}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${mnApp}`, pkgManager, execSyncOptions());
runNxCommand(`melos-bootstrap`, pkgManager, execSyncOptions());
runNxCommand(`clean ${flutterapp}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${flutterlib}`, pkgManager, execSyncOptions());
runNxCommand(`clean ${krApp}`, pkgManager, execSyncOptions());

expect(true).toBeTruthy();
},
3600000
);
});
Loading

0 comments on commit e10afdc

Please sign in to comment.