Skip to content

Commit

Permalink
fix(verdaccio): e2e pipeline, nx-cmake still needs fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenscodes committed Mar 15, 2024
1 parent 60cb5e2 commit 13e0d6b
Show file tree
Hide file tree
Showing 29 changed files with 91 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = {
2,
'always',
[
...(await getProjects(
...getProjects(
ctx,
({ name }) => !name.includes('e2e') && !name.includes('sb'),
)),
),
],
],
},
Expand Down
12 changes: 4 additions & 8 deletions e2e/e2e-create-nx-cmake/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
"sourceRoot": "e2e/e2e-create-nx-cmake/tests",
"targets": {
"run-e2e": {
"dependsOn": ["^start-local-registry", "^publish"],
"dependsOn": ["^publish"],
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/{projectName}/jest.config.ts",
"runInBand": true
}
},
"finish-e2e": {
"dependsOn": ["run-e2e"],
"command": "nx stop-local-registry verdaccio"
},
"e2e": {
"dependsOn": ["finish-e2e"],
"executor": "nx:noop"
"dependsOn": ["^e2e"],
"command": "nx single-e2e verdaccio --e2e={projectName}"
},
"lint": {
"executor": "@nx/eslint:lint",
Expand All @@ -34,5 +30,5 @@
}
}
},
"implicitDependencies": ["verdaccio", "create-nx-cmake"]
"implicitDependencies": ["verdaccio", "create-nx-cmake", "e2e-nx-cmake"]
}
2 changes: 1 addition & 1 deletion e2e/e2e-create-nx-cmake/tests/create-nx-cmake.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function createTestProject(extraArgs = '') {
recursive: true,
});

execSync(`npx --yes create-nx-cmake@e2e ${projectName} ${extraArgs}`, {
execSync(`npx create-nx-cmake@e2e ${projectName} ${extraArgs}`, {
cwd: dirname(projectDirectory),
stdio: 'inherit',
env: process.env,
Expand Down
12 changes: 4 additions & 8 deletions e2e/e2e-nx-cmake/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
"sourceRoot": "e2e/e2e-nx-cmake/tests",
"targets": {
"run-e2e": {
"dependsOn": ["^start-local-registry", "^publish"],
"dependsOn": ["^publish"],
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/{projectName}/jest.config.ts",
"runInBand": true
}
},
"finish-e2e": {
"dependsOn": ["run-e2e"],
"command": "nx stop-local-registry verdaccio"
},
"e2e": {
"dependsOn": ["finish-e2e"],
"executor": "nx:noop"
"dependsOn": ["^e2e"],
"command": "nx single-e2e verdaccio --e2e={projectName}"
},
"lint": {
"executor": "@nx/eslint:lint",
Expand All @@ -34,5 +30,5 @@
}
}
},
"implicitDependencies": ["verdaccio", "nx-cmake"]
"implicitDependencies": ["nx-cmake"]
}
2 changes: 1 addition & 1 deletion e2e/e2e-nx-cmake/tests/nx-cmake.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function createTestProject() {
});

execSync(
`npx --yes create-nx-workspace@latest ${projectName} --preset=${plugin} --nxCloud=skip --no-interactive`,
`npx create-nx-workspace@latest ${projectName} --preset=${plugin} --ci=skip --interactive=false --verbose`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@types/node": "20.11.25",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
"@verdaccio/types": "^10.8.0",
"commitizen": "^4.3.0",
"commitlint": "^19.0.3",
"cz-git": "^1.9.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage
storage: ../../tmp/local-registry/storage

# a list of other known repositories we can talk to
uplinks:
Expand Down Expand Up @@ -34,3 +34,5 @@ server:

listen:
- 0.0.0.0:4873

_debug: true
7 changes: 7 additions & 0 deletions packages/verdaccio/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
"command": "ts-node {projectRoot}/src/bin/publish.ts {args.name} {args.ver} {args.tag}"
}
},
"single-e2e": {
"executor": "nx:run-commands",
"options": {
"color": true,
"command": "ts-node {projectRoot}/src/bin/single-e2e.ts {args.e2e}"
}
},
"run-many-e2e": {
"executor": "nx:run-commands",
"options": {
Expand Down
24 changes: 9 additions & 15 deletions packages/verdaccio/src/bin/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function invariant(condition: boolean, message: string) {
}
}

const registry = 'http://localhost:4873';

// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
const [, , name, version, tag = 'next'] = process.argv;
Expand Down Expand Up @@ -36,7 +38,6 @@ invariant(

process.chdir(outputPath);

// Updating the version in "package.json" before publishing
try {
const json = JSON.parse(readFileSync(`package.json`).toString());
json.version = version;
Expand All @@ -45,21 +46,14 @@ try {
console.error(`Error reading package.json file from library build output.`);
}

const host = 'localhost';
const port = 4873;
const registry = `http://${host}:${port}`;

execSync(
`npm config set //${host}:${port}/:_authToken "secretVerdaccioToken"`,
{
encoding: 'utf-8',
stdio: 'inherit',
env: {
...process.env,
npm_config_registry: registry,
},
execSync(`npm config set //localhost:4873/:_authToken "secretVerdaccioToken"`, {
encoding: 'utf-8',
stdio: 'inherit',
env: {
...process.env,
npm_config_registry: registry,
},
);
});

// Execute "npm publish" to publish
execSync(`npm publish --access public --tag ${tag} --registry ${registry}`, {
Expand Down
3 changes: 3 additions & 0 deletions packages/verdaccio/src/bin/single-e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { e2eSingle } from '../lib/single-e2e';
const [, , target] = process.argv;
e2eSingle(target);
6 changes: 5 additions & 1 deletion packages/verdaccio/src/bin/start-local-registry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { startLocalRegistry } from '../lib/startLocalRegistry';

startLocalRegistry();
const registryProcess = startLocalRegistry();
if (registryProcess) {
console.log('Local registry started on port 4873');
registryProcess.unref();
}
4 changes: 4 additions & 0 deletions packages/verdaccio/src/bin/stop-local-registry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { exit } from 'node:process';
import { stopLocalRegistry } from '../lib/stopLocalRegistry';

stopLocalRegistry(null);
if (!process.env['SKIP']) {
exit(0);
}
1 change: 0 additions & 1 deletion packages/verdaccio/src/config/hostname.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/verdaccio/src/config/port.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/verdaccio/src/config/project.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/verdaccio/src/config/registry.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/verdaccio/src/config/storage.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/verdaccio/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { e2e } from './lib/e2e';
export { e2eSingle } from './lib/single-e2e';
1 change: 0 additions & 1 deletion packages/verdaccio/src/lib/localRegistryTarget.ts

This file was deleted.

9 changes: 3 additions & 6 deletions packages/verdaccio/src/lib/setLocalRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { execSync } from 'child_process';
import { port } from '../config/port';
import { registry } from '../config/registry';
import { hostname } from '../config/hostname';

export const setLocalRegistry = () => {
process.env['npm_config_registry'] = registry;
const cmd = `npm config set //${hostname}:${port}/:_authToken "secretVerdaccioToken"`;
process.env['npm_config_registry'] = 'http://localhost:4873';
const cmd = `npm config set //localhost:4873/:_authToken "secretVerdaccioToken"`;
execSync(cmd);
console.log('Set npm config registry to ' + registry);
console.log('Set npm config registry to ' + 'http://localhost:4873');
};
24 changes: 24 additions & 0 deletions packages/verdaccio/src/lib/single-e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { execSync } from 'node:child_process';
import { exit } from 'node:process';
import { startLocalRegistry } from './startLocalRegistry';
import { stopLocalRegistry } from './stopLocalRegistry';

export const e2eSingle = (target: string) => {
const registryProcess = startLocalRegistry();
const head = process.env['NX_HEAD']
? `--head=${process.env['NX_HEAD']}`
: '';
const base = process.env['NX_BASE']
? `--base=${process.env['NX_BASE']}`
: '';
const cmd = `nx run-e2e ${target} --nx-bail --output-style=stream --configuration=ci ${base} ${head}`;
execSync(cmd, {
stdio: 'inherit',
env: {
...process.env,
SKIP: 'true',
},
});
stopLocalRegistry(registryProcess);
exit(0);
};
11 changes: 3 additions & 8 deletions packages/verdaccio/src/lib/startLocalRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { ChildProcess, spawn } from 'child_process';
import { localRegistryTarget } from './localRegistryTarget';
import { port } from '../config/port';
import { project } from '../config/project';
import { setLocalRegistry } from './setLocalRegistry';

export const startLocalRegistry = (): ChildProcess | null => {
if (process.env['SKIP']) {
console.log('Skipping start');
return null;
}
const childProcess = spawn('nx', [localRegistryTarget, project], {
stdio: 'inherit',
setLocalRegistry();
const childProcess = spawn('nx', ['local-registry', 'verdaccio'], {
stdio: 'pipe',
detached: true,
env: {
...process.env,
},
});
childProcess.unref();
console.log('Local registry started on port ' + port);
setLocalRegistry();
return childProcess;
};
3 changes: 1 addition & 2 deletions packages/verdaccio/src/lib/stopLocalRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChildProcess, execSync } from 'child_process';
import { port } from '../config/port';
import { unsetLocalRegistry } from './unsetLocalRegistry';

export const stopLocalRegistry = (childProcess: ChildProcess | null) => {
Expand All @@ -12,7 +11,7 @@ export const stopLocalRegistry = (childProcess: ChildProcess | null) => {
childProcess.kill();
return;
}
execSync(`npx kill-port ${port}`, {
execSync(`npx kill-port 4873`, {
env: {
...process.env,
npm_config_registry: 'https://registry.npmjs.org',
Expand Down
4 changes: 1 addition & 3 deletions packages/verdaccio/src/lib/unsetLocalRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { execSync } from 'child_process';
import { port } from '../config/port';
import { hostname } from '../config/hostname';

export const unsetLocalRegistry = () => {
execSync(`npm config delete //${hostname}:${port}/:_authToken`);
execSync(`npm config delete //localhost:4873/:_authToken`);
};
6 changes: 2 additions & 4 deletions plugins/create-nx-cmake/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ async function main() {

console.log(`Creating the workspace: ${name}`);

// This assumes "nx-cmake" and "create-nx-cmake" are at the same version
const { version } = await import('../package.json');

// TODO: update below to customize the workspace
const { directory } = await createWorkspace(`nx-cmake@${version}`, {
const { directory } = await createWorkspace(`nx-cmake`, {
name,
nxCloud: 'skip',
interactive: false,
packageManager: 'npm',
});

Expand Down
10 changes: 4 additions & 6 deletions plugins/create-nx-cmake/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "create-nx-cmake",
"version": "0.6.0",
"bin": {
"create-nx-cmake": "./bin/index.js"
},
"typings": "./bin/index.d.ts",
"dependencies": {
"create-nx-workspace": "18.0.8",
"tslib": "^2.6.2"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"author": {
"email": "me@clemenshorn.com",
"name": "Clemens Horn",
Expand All @@ -31,8 +32,5 @@
"bugs": {
"url": "https://github.com/clemenscodes/nx-plugins/issues/new",
"email": "me@clemenshorn.com"
},
"bin": {
"create-nx-cmake": "./bin/index.js"
}
}
1 change: 0 additions & 1 deletion plugins/nx-cmake/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"description": "An Nx plugin to add CMake, C and C++ support for Nx workspaces",
"version": "0.6.0",
"license": "MIT",
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"generators": "./generators.json",
Expand Down
1 change: 1 addition & 0 deletions plugins/nx-cmake/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"command": "nx upload verdaccio --name={projectName} --ver=1.0.0 --tag=e2e"
}
},
"implicitDependencies": ["verdaccio"],
"tags": []
}
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13e0d6b

Please sign in to comment.