Skip to content

Commit

Permalink
Initial work on adding a danger-process style runner for JS
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 15, 2017
1 parent a9d2691 commit 64899d9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Master

### 2.0.0-alpha.20

- Moves away from vm2 to a require-based Dangerfile runner. This removes the sandboxing aspect of
the Dangerfile completely, but the sandboxing was mainly for Peril and I have a plan for that.

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "2.0.0-alpha.19",
"version": "2.0.0-alpha.20",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down Expand Up @@ -61,6 +61,7 @@
"@types/chalk": "^0.4.31",
"@types/commander": "^2.3.31",
"@types/debug": "0.0.29",
"@types/get-stdin": "^5.0.1",
"@types/jest": "^20.0.0",
"@types/lodash.includes": "^4.3.3",
"@types/node-fetch": "^1.6.6",
Expand Down Expand Up @@ -95,6 +96,7 @@
"chalk": "^2.0.0",
"commander": "^2.9.0",
"debug": "^3.0.0",
"get-stdin": "^5.0.1",
"github": "^11",
"jsome": "^2.3.25",
"jsonpointer": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function run() {
}

if (platform) {
console.log(`${chalk.bold("OK")}, everything looks good: ${source.name} on ${platform.name}`)
d.log(`${chalk.bold("OK")}, everything looks good: ${source.name} on ${platform.name}`)
const dangerFile = dangerfilePath(program)

const exists = validateDangerfileExists(dangerFile)
Expand Down
49 changes: 49 additions & 0 deletions source/commands/danger-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import setSharedArgs, { SharedCLI } from "./utils/sharedDangerfileArgs"

import * as chalk from "chalk"
import * as program from "commander"
import * as fs from "fs"
import * as getSTDIN from "get-stdin"

import { contextForDanger } from "../runner/Dangerfile"
import inline from "../runner/runners/inline"
import { Executor } from "../runner/Executor"
import { getPlatformForEnv } from "../platforms/platform"
import getRuntimeCISource from "./utils/getRuntimeCISource"

// Given the nature of this command, it can be tricky to test, so I use a command like this:
//
// env DANGER_GITHUB_API_TOKEN='xxx' DANGER_FAKE_CI="YEP" DANGER_TEST_REPO='artsy/eigen' DANGER_TEST_PR='2408'
// yarn ts-node -s -- source/commands/danger-process.ts ./scripts/danger_runner.rb
//

program
.usage("[options] dangerfile")
.description("Handles running the Dangerfile, expects a DSL from STDIN, which should be passed from `danger run`.")

setSharedArgs(program).parse(process.argv)

const app = (program as any) as SharedCLI

const run = async (jsonString: string) => {
const dsl = JSON.parse(jsonString)
console.log(dsl)

// Set up the runtime env
const context = contextForDanger(dsl)
const runtimeEnv = await inline.createDangerfileRuntimeEnvironment(context)
const results = await inline.runDangerfileEnvironment(app.dangerfile, undefined, runtimeEnv)

const config = {
stdoutOnly: app.textOnly,
verbose: app.verbose,
}

const source = await getRuntimeCISource(app)
const platform = getPlatformForEnv(process.env, source!)

const exec = new Executor(source!, platform, inline, config)
await exec.handleResults(results)
}

getSTDIN().then(run)
2 changes: 1 addition & 1 deletion source/runner/runners/utils/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let hasBabel = false
let hasBabelTypeScript = false
let hasFlow = false

// Yes, lots of linter disables, but I want to support TS/Babel/Neither correclty
// Yes, lots of linter disables, but I want to support TS/Babel/Neither correctly

try {
require.resolve("typescript") // tslint:disable-line
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.29.tgz#a1e514adfbd92f03a224ba54d693111dbf1f3754"

"@types/get-stdin@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@types/get-stdin/-/get-stdin-5.0.1.tgz#46afbcaf09e94fe025afa07ae994ac3168adbdf3"
dependencies:
"@types/node" "*"

"@types/jest@^20.0.0":
version "20.0.4"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-20.0.4.tgz#91e2c76fbe90b3a719b5d689958f0495f005beb9"
Expand Down Expand Up @@ -2099,6 +2105,10 @@ get-stdin@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"

get-stdin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"

get-stream@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-2.3.1.tgz#5f38f93f346009666ee0150a054167f91bdd95de"
Expand Down

0 comments on commit 64899d9

Please sign in to comment.