Skip to content

chore(repo): make local-registry continuous #30789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
NX_E2E_RUN_E2E: 'true'
NX_CI_EXECUTION_ENV: 'linux'
NX_CLOUD_NO_TIMEOUTS: 'true'
NX_ALLOW_NON_CACHEABLE_DTE: 'true'
NX_CLOUD_USE_NEW_TASK_APIS: 'true'
NX_CLOUD_USE_NEW_STREAM_OUTPUT: 'true'

steps:
Expand Down Expand Up @@ -106,7 +108,7 @@ jobs:

main-macos:
runs-on: macos-latest

env:
NX_E2E_CI_CACHE_KEY: e2e-github-macos
NX_PERF_LOGGING: 'false'
Expand Down
8 changes: 8 additions & 0 deletions .nx/workflows/dynamic-changesets.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
distribute-on:
default: auto linux-medium, 1 linux-extra-large
assignment-rules:
- targets:
- e2e-ci**
run-on:
- agent: linux-medium
parallelism: 1
- agent: linux-extra-large
parallelism: 1

- projects:
- nx-dev
targets:
Expand Down
61 changes: 53 additions & 8 deletions e2e/utils/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Config } from '@jest/types';
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { existsSync, removeSync } from 'fs-extra';
import * as isCI from 'is-ci';
import { exec } from 'node:child_process';
import { exec, execSync } from 'node:child_process';
import { join } from 'node:path';
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';
Expand All @@ -19,18 +18,54 @@ export default async function (globalConfig: Config.ConfigGlobals) {
const requiresLocalRelease =
!process.env.NX_TASK_TARGET_TARGET?.startsWith('e2e-ci');

global.e2eTeardown = await startLocalRegistry({
localRegistryTarget: '@nx/nx-source:local-registry',
verbose: isVerbose,
clearStorage: requiresLocalRelease,
});
const listenAddress = 'localhost';
const port = process.env.NX_LOCAL_REGISTRY_PORT ?? '4873';
const registry = `http://${listenAddress}:${port}`;
const authToken = 'secretVerdaccioToken';

while (true) {
await new Promise((resolve) => setTimeout(resolve, 250));
try {
await assertLocalRegistryIsRunning(registry);
break;
} catch {
console.log(`Waiting for Local registry to start on ${registry}...`);
}
}

process.env.npm_config_registry = registry;
execSync(
`npm config set //${listenAddress}:${port}/:_authToken "${authToken}" --ws=false`,
{
windowsHide: false,
}
);

// bun
process.env.BUN_CONFIG_REGISTRY = registry;
process.env.BUN_CONFIG_TOKEN = authToken;
// yarnv1
process.env.YARN_REGISTRY = registry;
// yarnv2
process.env.YARN_NPM_REGISTRY_SERVER = registry;
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;

global.e2eTeardown = () => {
execSync(
`npm config delete //${listenAddress}:${port}/:_authToken --ws=false`,
{
windowsHide: false,
}
);
};

/**
* Set the published version based on what has previously been loaded into the
* verdaccio storage.
*/
if (!requiresLocalRelease) {
const publishedVersion = await getPublishedVersion();
let publishedVersion = await getPublishedVersion();
console.log(`Testing Published version: Nx ${publishedVersion}`);
if (publishedVersion) {
process.env.PUBLISHED_VERSION = publishedVersion;
}
Expand Down Expand Up @@ -60,6 +95,9 @@ export default async function (globalConfig: Config.ConfigGlobals) {
}

function getPublishedVersion(): Promise<string | undefined> {
execSync(`npm config get registry`, {
stdio: 'inherit',
});
return new Promise((resolve) => {
// Resolve the published nx version from verdaccio
exec(
Expand All @@ -76,3 +114,10 @@ function getPublishedVersion(): Promise<string | undefined> {
);
});
}

async function assertLocalRegistryIsRunning(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
}
14 changes: 9 additions & 5 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,17 @@
},
"e2e-ci--**/**": {
"inputs": ["e2eInputs", "^production"],
"parallelism": false,
"dependsOn": ["@nx/nx-source:populate-local-registry-storage"]
"dependsOn": [
"@nx/nx-source:populate-local-registry-storage",
"@nx/nx-source:local-registry"
]
},
"e2e-macos-ci--**/*": {
"inputs": ["e2eInputs", "^production"],
"parallelism": false,
"dependsOn": ["@nx/nx-source:populate-local-registry-storage"]
"dependsOn": [
"@nx/nx-source:populate-local-registry-storage",
"@nx/nx-source:local-registry"
]
},
"e2e-base": {
"inputs": ["default", "^production"]
Expand Down Expand Up @@ -254,7 +258,7 @@
"nxCloudId": "62d013ea0852fe0a2df74438",
"nxCloudUrl": "https://staging.nx.app",
"parallel": 1,
"bust": 7,
"bust": 1,
"defaultBase": "master",
"conformance": {
"rules": [
Expand Down
7 changes: 5 additions & 2 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"options": {
"port": 4873,
"config": ".verdaccio/config.yml",
"storage": "build/local-registry/storage"
"storage": "build/local-registry/storage",
"clear": false
}
},
"populate-local-registry-storage": {
Expand All @@ -16,9 +17,11 @@
{
"input": "production",
"projects": ["tag:npm:public"]
}
},
"{workspaceRoot}/scripts/local-registry"
],
"dependsOn": [
"local-registry",
{
"target": "build",
"projects": ["tag:npm:public"]
Expand Down
51 changes: 34 additions & 17 deletions scripts/local-registry/populate-storage.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
// @ts-check

const { startLocalRegistry } = require('@nx/js/plugins/jest/local-registry');
const { exec } = require('node:child_process');
const { exec, execSync } = require('node:child_process');
const {
LARGE_BUFFER,
} = require('nx/src/executors/run-commands/run-commands.impl');

async function populateLocalRegistryStorage() {
let registryTeardown;
const listenAddress = 'localhost';
const port = process.env.NX_LOCAL_REGISTRY_PORT ?? '4873';
const registry = `http://${listenAddress}:${port}`;
const authToken = 'secretVerdaccioToken';

while (true) {
await new Promise((resolve) => setTimeout(resolve, 250));
try {
await assertLocalRegistryIsRunning(registry);
break;
} catch {
console.log(`Waiting for Local registry to start on ${registry}...`);
}
}

process.env.npm_config_registry = registry;

// bun
process.env.BUN_CONFIG_REGISTRY = registry;
process.env.BUN_CONFIG_TOKEN = authToken;
// yarnv1
process.env.YARN_REGISTRY = registry;
// yarnv2
process.env.YARN_NPM_REGISTRY_SERVER = registry;
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;

try {
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
registryTeardown = await startLocalRegistry({
localRegistryTarget: '@nx/nx-source:local-registry',
verbose: isVerbose,
clearStorage: true,
});

console.log('Publishing packages to local registry to populate storage');
await runLocalRelease(publishVersion, isVerbose);

registryTeardown();
console.log('Killed local registry process');
} catch (err) {
// Clean up registry if possible after setup related errors
if (typeof registryTeardown === 'function') {
registryTeardown();
console.log('Killed local registry process due to an error during setup');
}
console.error('Error:', err);
process.exit(1);
}
Expand Down Expand Up @@ -60,3 +70,10 @@ function runLocalRelease(publishVersion, isVerbose) {
});
}
exports.runLocalRelease = runLocalRelease;

async function assertLocalRegistryIsRunning(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
}
Loading