chore(repo): teardown local registry in case of setup error (#23470)
This commit is contained in:
parent
44429451c8
commit
b641852d9c
@ -2,51 +2,60 @@ import { Config } from '@jest/types';
|
|||||||
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
|
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
|
||||||
import { existsSync, removeSync } from 'fs-extra';
|
import { existsSync, removeSync } from 'fs-extra';
|
||||||
import * as isCI from 'is-ci';
|
import * as isCI from 'is-ci';
|
||||||
import { exec, execSync } from 'node:child_process';
|
import { exec } from 'node:child_process';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
|
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
|
||||||
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';
|
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';
|
||||||
|
|
||||||
export default async function (globalConfig: Config.ConfigGlobals) {
|
export default async function (globalConfig: Config.ConfigGlobals) {
|
||||||
const isVerbose: boolean =
|
try {
|
||||||
process.env.NX_VERBOSE_LOGGING === 'true' || !!globalConfig.verbose;
|
const isVerbose: boolean =
|
||||||
|
process.env.NX_VERBOSE_LOGGING === 'true' || !!globalConfig.verbose;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For e2e-ci we populate the verdaccio storage up front, but for other workflows we need
|
* For e2e-ci we populate the verdaccio storage up front, but for other workflows we need
|
||||||
* to run the full local release process before running tests.
|
* to run the full local release process before running tests.
|
||||||
*/
|
*/
|
||||||
const requiresLocalRelease =
|
const requiresLocalRelease =
|
||||||
!process.env.NX_TASK_TARGET_TARGET?.startsWith('e2e-ci');
|
!process.env.NX_TASK_TARGET_TARGET?.startsWith('e2e-ci');
|
||||||
|
|
||||||
global.e2eTeardown = await startLocalRegistry({
|
global.e2eTeardown = await startLocalRegistry({
|
||||||
localRegistryTarget: '@nx/nx-source:local-registry',
|
localRegistryTarget: '@nx/nx-source:local-registry',
|
||||||
verbose: isVerbose,
|
verbose: isVerbose,
|
||||||
clearStorage: requiresLocalRelease,
|
clearStorage: requiresLocalRelease,
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the published version based on what has previously been loaded into the
|
* Set the published version based on what has previously been loaded into the
|
||||||
* verdaccio storage.
|
* verdaccio storage.
|
||||||
*/
|
*/
|
||||||
if (!requiresLocalRelease) {
|
if (!requiresLocalRelease) {
|
||||||
const publishedVersion = await getPublishedVersion();
|
const publishedVersion = await getPublishedVersion();
|
||||||
if (publishedVersion) {
|
if (publishedVersion) {
|
||||||
process.env.PUBLISHED_VERSION = publishedVersion;
|
process.env.PUBLISHED_VERSION = publishedVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.NX_E2E_SKIP_CLEANUP !== 'true' || !existsSync('./build')) {
|
if (process.env.NX_E2E_SKIP_CLEANUP !== 'true' || !existsSync('./build')) {
|
||||||
if (!isCI) {
|
if (!isCI) {
|
||||||
registerTsConfigPaths(join(__dirname, '../../tsconfig.base.json'));
|
registerTsConfigPaths(join(__dirname, '../../tsconfig.base.json'));
|
||||||
const { e2eCwd } = await import('./get-env-info');
|
const { e2eCwd } = await import('./get-env-info');
|
||||||
removeSync(e2eCwd);
|
removeSync(e2eCwd);
|
||||||
|
}
|
||||||
|
if (requiresLocalRelease) {
|
||||||
|
console.log('Publishing packages to local registry');
|
||||||
|
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
|
||||||
|
// Always show full release logs on CI, they should only happen once via e2e-ci
|
||||||
|
await runLocalRelease(publishVersion, isCI || isVerbose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (requiresLocalRelease) {
|
} catch (err) {
|
||||||
console.log('Publishing packages to local registry');
|
// Clean up registry if possible after setup related errors
|
||||||
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
|
if (typeof global.e2eTeardown === 'function') {
|
||||||
// Always show full release logs on CI, they should only happen once via e2e-ci
|
global.e2eTeardown();
|
||||||
await runLocalRelease(publishVersion, isCI || isVerbose);
|
console.log('Killed local registry process due to an error during setup');
|
||||||
}
|
}
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,10 +7,11 @@ const {
|
|||||||
} = require('nx/src/executors/run-commands/run-commands.impl');
|
} = require('nx/src/executors/run-commands/run-commands.impl');
|
||||||
|
|
||||||
async function populateLocalRegistryStorage() {
|
async function populateLocalRegistryStorage() {
|
||||||
|
let registryTeardown;
|
||||||
try {
|
try {
|
||||||
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
|
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
|
||||||
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
||||||
const registryTeardown = await startLocalRegistry({
|
registryTeardown = await startLocalRegistry({
|
||||||
localRegistryTarget: '@nx/nx-source:local-registry',
|
localRegistryTarget: '@nx/nx-source:local-registry',
|
||||||
verbose: isVerbose,
|
verbose: isVerbose,
|
||||||
clearStorage: true,
|
clearStorage: true,
|
||||||
@ -22,6 +23,11 @@ async function populateLocalRegistryStorage() {
|
|||||||
registryTeardown();
|
registryTeardown();
|
||||||
console.log('Killed local registry process');
|
console.log('Killed local registry process');
|
||||||
} catch (err) {
|
} 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);
|
console.error('Error:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user