From 67c8bbeb4f258b543ed49ce84af700ba40a890b2 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 19 Jul 2023 15:24:27 +0200 Subject: [PATCH 1/5] feat(e2e-runner): Use verbose logging in CI and when `--verbose` is used --- packages/core/src/utils/index.ts | 1 + .../core/src/utils/use-verbose-logging.ts | 3 +++ .../e2e-runner/src/executors/run/run.impl.ts | 23 ++++++++++--------- .../src/executors/run/utils/is-api-live.ts | 6 ++--- .../src/executors/run/utils/nx-target.ts | 17 +++++++------- 5 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 packages/core/src/utils/use-verbose-logging.ts diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index bede738f..d22c29ba 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -3,3 +3,4 @@ export * from './build-command' export * from './normalize-options' export * from './copy-file' export * from './is-ci' +export * from './use-verbose-logging' diff --git a/packages/core/src/utils/use-verbose-logging.ts b/packages/core/src/utils/use-verbose-logging.ts new file mode 100644 index 00000000..0b7225c6 --- /dev/null +++ b/packages/core/src/utils/use-verbose-logging.ts @@ -0,0 +1,3 @@ +import { isCI } from './is-ci' + +export const USE_VERBOSE_LOGGING = isCI() || Boolean(process.env.NX_VERBOSE_LOGGING) diff --git a/packages/e2e-runner/src/executors/run/run.impl.ts b/packages/e2e-runner/src/executors/run/run.impl.ts index 7c3664c5..6e0716d1 100644 --- a/packages/e2e-runner/src/executors/run/run.impl.ts +++ b/packages/e2e-runner/src/executors/run/run.impl.ts @@ -8,11 +8,15 @@ export interface RunOptions { runnerTarget?: string watch?: boolean targets: NxTargetOptions[] - debug?: boolean } let runningTargets = [] +async function killTargets() { + // Kill all targets + await Promise.all(runningTargets.map((nxTarget) => nxTarget.teardown())) +} + export async function endToEndRunner( options: RunOptions, context: ExecutorContext @@ -27,7 +31,7 @@ export async function endToEndRunner( // Start all targets await Promise.all(runningTargets.map((nxTarget) => nxTarget.setup())) } catch { - await Promise.all(runningTargets.map((nxTarget) => nxTarget.teardown())) + await killTargets() return { success: false } } @@ -47,8 +51,7 @@ export async function endToEndRunner( // eslint-disable-next-line @typescript-eslint/no-var-requires const runCommandsExecutor = require('@nx/workspace/src/executors/run-commands/run-commands.impl').default - success = (await runCommandsExecutor(rest as RunCommandsOptions, context)) - .success + success = (await runCommandsExecutor(rest as RunCommandsOptions, context)).success } else { throw new Error(`Unknown runner "${runner}"`) } @@ -59,16 +62,14 @@ export async function endToEndRunner( } // Kill all targets - await Promise.all(runningTargets.map((nxTarget) => nxTarget.teardown())) + await killTargets() return { success } } -process.on('SIGINT', async function () { - // Kill all targets - await Promise.all(runningTargets.map((nxTarget) => nxTarget.teardown())) - - process.exit() -}) +process.on('exit', () => killTargets()) +process.on('SIGINT', () => killTargets()) +process.on('SIGTERM', () => killTargets()) +process.on('SIGHUP', () => killTargets()) export default endToEndRunner diff --git a/packages/e2e-runner/src/executors/run/utils/is-api-live.ts b/packages/e2e-runner/src/executors/run/utils/is-api-live.ts index 9472d2d3..d1eee465 100644 --- a/packages/e2e-runner/src/executors/run/utils/is-api-live.ts +++ b/packages/e2e-runner/src/executors/run/utils/is-api-live.ts @@ -17,9 +17,9 @@ export const isApiLive = async ( return axios .get(url, axiosConfig) - .then((response) => { - return response.status >= 200 && response.status < 300 - }) + .then((response) => ( + response.status >= 200 && response.status < 300 + )) .catch(() => { return false }) diff --git a/packages/e2e-runner/src/executors/run/utils/nx-target.ts b/packages/e2e-runner/src/executors/run/utils/nx-target.ts index 368c3bf7..3ac32208 100644 --- a/packages/e2e-runner/src/executors/run/utils/nx-target.ts +++ b/packages/e2e-runner/src/executors/run/utils/nx-target.ts @@ -1,5 +1,5 @@ import { logger, parseTargetString } from '@nx/devkit' -import { isCI } from '@nx-extend/core' +import { USE_VERBOSE_LOGGING } from '@nx-extend/core' import * as childProcess from 'child_process' import type { RunOptions } from '../run.impl' @@ -89,8 +89,7 @@ export class NxTarget { `Target "${this.options.target}" was not able to start. Exit code: ${code}` ) ), - env: this.options.env, - verbose: this.runOptions.debug || isCI() + env: this.options.env }) if (this.killed) { @@ -99,11 +98,12 @@ export class NxTarget { } private async waitForProcess() { - await this._waitForAvailability() + await this.waitForAvailability() + logger.info(`Target "${this.options.target}" is live`) } - private async _waitForAvailability() { + private async waitForAvailability() { const cancellationToken = { canceled: this.killed } const error = await Promise.race([ @@ -150,7 +150,6 @@ function launchProcess( options: { onExit: (exitCode: number | null, signal: string | null) => void env?: { [key: string]: string } - verbose?: boolean } ): () => Promise { const { project, target, configuration } = parseTargetString(targetString) @@ -173,13 +172,13 @@ function launchProcess( } ) - if (options.verbose) { + if (USE_VERBOSE_LOGGING) { spawnedProcess.stdout.on('data', (data) => { - logger.info(`${targetString}: ${data.toString()}`) + logger.debug(`[${targetString}]: ${data.toString()}`) }) spawnedProcess.stderr.on('data', (data) => { - logger.error(`${targetString}: ${data.toString()}`) + logger.error(`[${targetString}]: ${data.toString()}`) }) } From acc34548698e881ada0de31e97d7564adbd4369d Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 19 Jul 2023 15:26:47 +0200 Subject: [PATCH 2/5] docs: Updated README --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19dbfa08..2c382bc1 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,19 @@ - `npm install --save-dev @nx-extend/strapi` - [Vercel](./packages/vercel/README.md) - `npm install --save-dev @nx-extend/vercel` - +- [Playwright](./packages/playwright/README.md) + - `npm install --save-dev @nx-extend/playwright` +- [Terraform](./packages/terraform/README.md) + - `npm install --save-dev @nx-extend/terraform` +- [Pulumi](./packages/Pulumi/README.md) + - `npm install --save-dev @nx-extend/Pulumi` ## GitHub actions +- [set-shas](./actions/set-shas/README.md) + - `uses: tripss/nx-extend/actions/set-shas@master` +- [plan](./actions/plan/README.md) + - `uses: tripss/nx-extend/actions/plan@master` - [run-many](./actions/run-many/README.md) - `uses: tripss/nx-extend/actions/run-many@master` From 1ebb13ebdaa91d8290128812840bc5c84fcb2bf6 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 19 Jul 2023 22:30:10 +0200 Subject: [PATCH 3/5] fix(gcp-functions): Improve logging when package is not added to functions package.json --- packages/gcp-functions/src/utils/generate-package-json.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/gcp-functions/src/utils/generate-package-json.ts b/packages/gcp-functions/src/utils/generate-package-json.ts index 5ba28a59..520ca95b 100644 --- a/packages/gcp-functions/src/utils/generate-package-json.ts +++ b/packages/gcp-functions/src/utils/generate-package-json.ts @@ -1,8 +1,8 @@ import { ExecutorContext, + logger, readJsonFile, - writeJsonFile -} from '@nx/devkit' + writeJsonFile} from '@nx/devkit' import { createLockFile, createPackageJson } from '@nx/js' import { readCachedProjectGraph } from '@nx/workspace/src/core/project-graph' import { fileExists } from '@nx/workspace/src/utils/fileutils' @@ -47,6 +47,7 @@ export const generatePackageJson = ( x.match(re2)[0].replace(/"/gm, '') ) + console.log('\n') dependenciesName.forEach((dep) => { let depName = dep @@ -62,7 +63,7 @@ export const generatePackageJson = ( if (packageIsDefined) { dependencies[depName] = workspacePackages.dependencies[depName] } else { - console.warn(`Could not add "${dep}", is it added to the package.json?`) + logger.warn(`Could not add "${dep}", is it added to the package.json?`) } }) } From bdd8328c670f9370da3779dae9c2d77e9489b117 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Fri, 21 Jul 2023 17:14:16 +0200 Subject: [PATCH 4/5] feat(gcp-functions): Added support for bucket events to runner --- packages/gcp-functions/runner/__runner.controller.ts | 3 +++ packages/gcp-functions/runner/index.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/gcp-functions/runner/__runner.controller.ts b/packages/gcp-functions/runner/__runner.controller.ts index fcb88eca..0fdfb85c 100644 --- a/packages/gcp-functions/runner/__runner.controller.ts +++ b/packages/gcp-functions/runner/__runner.controller.ts @@ -55,6 +55,9 @@ export function createController(gcpFunctions: NxEndpoints) { } else if (endpoint.trigger === 'topic') { return this.simulatePubSubEvent(req, res, endpoint.func) + + } else if (endpoint.trigger === 'bucket') { + return endpoint.func(req.body, res) } this.logger.warn(`"${req.path}" unsupported trigger!`) diff --git a/packages/gcp-functions/runner/index.ts b/packages/gcp-functions/runner/index.ts index fb068901..d0f18345 100644 --- a/packages/gcp-functions/runner/index.ts +++ b/packages/gcp-functions/runner/index.ts @@ -35,9 +35,13 @@ export async function bootstrapRunner(basicFunctionsMap: RunnerFunctionsMap, opt } const options: DeployExecutorSchema = project.targets['deploy'].options + let endpoint = `/${options.triggerValue || options.functionName || projectName}` + if (options.trigger === 'bucket') { + endpoint = `/${options.functionName || projectName}` + } nxEndpoints.push({ - endpoint: `/${options.functionName || projectName}`, + endpoint, trigger: options.trigger || 'http', func: (await module)[options.entryPoint] as HttpFunction }) From 6fae7c75ad8f4dfd6e9f57a56daabfdec9bfc8b5 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Fri, 21 Jul 2023 17:18:08 +0200 Subject: [PATCH 5/5] fix(e2e-runner): Inherit `stdio` instead of listening our-self --- .../src/executors/run/utils/nx-target.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/packages/e2e-runner/src/executors/run/utils/nx-target.ts b/packages/e2e-runner/src/executors/run/utils/nx-target.ts index 3ac32208..62d87409 100644 --- a/packages/e2e-runner/src/executors/run/utils/nx-target.ts +++ b/packages/e2e-runner/src/executors/run/utils/nx-target.ts @@ -163,6 +163,7 @@ function launchProcess( detached: true, shell: true, cwd: process.cwd(), + stdio: USE_VERBOSE_LOGGING ? 'inherit' : undefined, env: { ...process.env, // Make sure NODE_ENV is set to test @@ -172,26 +173,12 @@ function launchProcess( } ) - if (USE_VERBOSE_LOGGING) { - spawnedProcess.stdout.on('data', (data) => { - logger.debug(`[${targetString}]: ${data.toString()}`) - }) - - spawnedProcess.stderr.on('data', (data) => { - logger.error(`[${targetString}]: ${data.toString()}`) - }) - } - let processClosed = false spawnedProcess.once('exit', (exitCode, signal) => { processClosed = true options.onExit(exitCode, signal) - - // TODO:: If "output=on-error" log it }) - spawnedProcess.on('data', (line) => console.error(line.toString())) - return async () => { if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) { spawnedProcess.removeAllListeners()