Skip to content

Commit

Permalink
Merge pull request #133 from TriPSs/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
TriPSs committed Jul 21, 2023
2 parents 860c4d1 + 6fae7c7 commit 9cfe31a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 39 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
3 changes: 3 additions & 0 deletions packages/core/src/utils/use-verbose-logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { isCI } from './is-ci'

export const USE_VERBOSE_LOGGING = isCI() || Boolean(process.env.NX_VERBOSE_LOGGING)
23 changes: 12 additions & 11 deletions packages/e2e-runner/src/executors/run/run.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
}
Expand All @@ -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}"`)
}
Expand All @@ -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
6 changes: 3 additions & 3 deletions packages/e2e-runner/src/executors/run/utils/is-api-live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
26 changes: 6 additions & 20 deletions packages/e2e-runner/src/executors/run/utils/nx-target.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand All @@ -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([
Expand Down Expand Up @@ -150,7 +150,6 @@ function launchProcess(
options: {
onExit: (exitCode: number | null, signal: string | null) => void
env?: { [key: string]: string }
verbose?: boolean
}
): () => Promise<void> {
const { project, target, configuration } = parseTargetString(targetString)
Expand All @@ -164,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
Expand All @@ -173,26 +173,12 @@ function launchProcess(
}
)

if (options.verbose) {
spawnedProcess.stdout.on('data', (data) => {
logger.info(`${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()
Expand Down
3 changes: 3 additions & 0 deletions packages/gcp-functions/runner/__runner.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!`)
Expand Down
6 changes: 5 additions & 1 deletion packages/gcp-functions/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
7 changes: 4 additions & 3 deletions packages/gcp-functions/src/utils/generate-package-json.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -47,6 +47,7 @@ export const generatePackageJson = (
x.match(re2)[0].replace(/"/gm, '')
)

console.log('\n')
dependenciesName.forEach((dep) => {
let depName = dep

Expand All @@ -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?`)
}
})
}
Expand Down

0 comments on commit 9cfe31a

Please sign in to comment.