From 418dd7faf2d1f5d88edd3fe8ca5aa2518662df8c Mon Sep 17 00:00:00 2001 From: Soyn Date: Sun, 4 Aug 2019 23:09:53 +0800 Subject: [PATCH 01/16] Add gitlab, bitbucket cloud platform to hint info when not supported platform is added. --- source/commands/ci/runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/commands/ci/runner.ts b/source/commands/ci/runner.ts index f926b3dce..574399236 100644 --- a/source/commands/ci/runner.ts +++ b/source/commands/ci/runner.ts @@ -51,7 +51,7 @@ export const runRunner = async (app: SharedCLI, config?: Partial) if (!platform) { console.log(chalk.red(`Could not find a source code hosting platform for ${source.name}.`)) console.log( - `Currently Danger JS only supports GitHub and BitBucket Server, if you want other platforms, consider the Ruby version or help add support.` + `Currently Danger JS only supports GitHub, BitBucket Server, Gitlab and Bitbucket Cloud, if you want other platforms, consider the Ruby version or help add support.` ) process.exitCode = 1 } From 7a0944f394ddb06cd6c704c6b7a809177857d434 Mon Sep 17 00:00:00 2001 From: Franco Meloni Date: Tue, 6 Aug 2019 22:30:05 +0100 Subject: [PATCH 02/16] Add bitrise commit hash --- source/ci_source/providers/Bitrise.ts | 6 +++++- .../ci_source/providers/_tests/_bitrise.test.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/source/ci_source/providers/Bitrise.ts b/source/ci_source/providers/Bitrise.ts index 0bd09ada3..641448ddc 100644 --- a/source/ci_source/providers/Bitrise.ts +++ b/source/ci_source/providers/Bitrise.ts @@ -72,6 +72,10 @@ export class Bitrise implements CISource { } get ciRunURL() { - return process.env.BITRISE_PULL_REQUEST + return this.env.BITRISE_PULL_REQUEST + } + + get commitHash() { + return this.env.BITRISE_GIT_COMMIT } } diff --git a/source/ci_source/providers/_tests/_bitrise.test.ts b/source/ci_source/providers/_tests/_bitrise.test.ts index 721e686e1..def8c0781 100644 --- a/source/ci_source/providers/_tests/_bitrise.test.ts +++ b/source/ci_source/providers/_tests/_bitrise.test.ts @@ -73,3 +73,19 @@ describe(".repoSlug", () => { expect(bitrise.repoSlug).toEqual("artsy/eigen") }) }) + +describe("commit hash", () => { + it("returns correct commit hash when present", () => { + const env = { + ...correctEnv, + BITRISE_GIT_COMMIT: "1234abc", + } + const bitrise = new Bitrise(env) + expect(bitrise.commitHash).toEqual("1234abc") + }) + + it("returns no commit hash when not present", () => { + const bitrise = new Bitrise(correctEnv) + expect(bitrise.commitHash).toBeUndefined() + }) +}) From 2d2c9354c4b6eb77dcab01a2f47f877662481381 Mon Sep 17 00:00:00 2001 From: Franco Meloni Date: Tue, 6 Aug 2019 22:33:01 +0100 Subject: [PATCH 03/16] Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf7e0edd0..ad736cf6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ +- Take commit hash from bitrise env - [@f-meloni] + # 9.1.4 - Use new env `BITBUCKET_REPO_FULL_NAME` in bitbucket pipeline. - [@Soyn] From eaab0aa05301018d1a6d2d63ef493109616bb120 Mon Sep 17 00:00:00 2001 From: Orta Date: Thu, 15 Aug 2019 10:37:02 -0400 Subject: [PATCH 04/16] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index faea2f430..c524d1c42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:10-slim MAINTAINER Orta Therox -LABEL "com.github.actions.name"="Danger JS" +LABEL "com.github.actions.name"="Danger JS Action" LABEL "com.github.actions.description"="Runs JavaScript/TypeScript Dangerfiles" LABEL "com.github.actions.icon"="zap" LABEL "com.github.actions.color"="blue" From 9be87602572228265ccafdb41744e68f52c72b99 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 15 Aug 2019 11:15:07 -0400 Subject: [PATCH 05/16] Improve docs for GitHub Actions --- source/ci_source/providers/GitHubActions.ts | 129 ++++++++++++++++---- source/platforms/platform.ts | 10 +- 2 files changed, 112 insertions(+), 27 deletions(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 7745b1992..91c435a82 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -7,33 +7,117 @@ import { readFileSync, existsSync } from "fs" /** * ### CI Setup * - * To use Danger JS with GitHub Actions, you'll need want to set up - * Danger to run on a `pull_request` webhook. To do this, you'll need - * to add/amend your repo's workflow file with something like: + * * + * There are two ways to use Danger with GitHub Actions. If you include Danger as a dev-dependency, then + * you can call danger directly as another build-step after your tests: * + * ```ruby + * name: Node CI + * on: [pull_request] + * + * jobs: + * test: + * runs-on: ubuntu-latest + * + * steps: + * - uses: actions/checkout@master + * - name: Use Node.js 10.x + * uses: actions/setup-node@v1 + * with: + * version: 10.x + * - name: install yarn + * run: npm install -g yarn + * - name: yarn install, build, and test + * run: | + * yarn install --frozen-lockfile + * yarn build + * yarn test + * - name: Danger + * run: yarn danger ci + * env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + * ``` + * + * If you are not running in a JavaScript ecosystem, or don't want to include the dependency then + * you can use Danger JS as an action. + * + * ```yml + * name: "Danger JS" + * on: [pull_request] + * + * jobs: + * build: + * name: Danger JS + * runs-on: ubuntu-latest + * steps: + * - uses: actions/checkout@v1 + * - name: Danger + * uses: danger/danger-js@9.1.6 + * env: + * GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} * ``` - * workflow "Dangerfile JS Eval" { - * on = "pull_request" - * resolves = "Danger JS" - * } - * - * action "Danger JS" { - * uses = "danger/danger-js@master" - * secrets = ["GITHUB_TOKEN"] - * } + * + * Note it's likely the version number should change, but you get the point. This will run Danger + * self-encapsulated inside a GitHub action. + * + * + * + * + * There are two ways to use Danger with GitHub Actions. If you include Danger as a dependency, then + * you can call danger directly as another build-step after your tests: + * + * ```ruby + * name: CI + * on: [pull_request] + * jobs: + * build: + * runs-on: macos-latest + * + * steps: + * - uses: actions/checkout@master + * - name: Build + * run: swift build + * + * - name: Test + * run: swift test + * + * - name: Danger + * run: danger-swift ci + * env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + * ``` + * + * If don't want to include the dependency then you can use Danger Swift via an action. + * + * ```yml + * name: "Danger Swift" + * on: [pull_request] + * + * jobs: + * build: + * name: Danger JS + * runs-on: ubuntu-latest + * steps: + * - uses: actions/checkout@v1 + * - name: Danger + * uses: danger/swift@2.0.1 + * env: + * GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} * ``` * - * You can pass additional CLI to Danger JS in an action via: + * Note it's likely the version number should change, but you get the point. This will run Danger + * self-encapsulated inside a GitHub action. + * + * + * + * You can pass additional CLI to Danger via an action via the args: * * ``` - * action "Danger JS" { - * [...] - * args = "--dangerfile artsy/peril-settings/org/allPRs.ts" - * } + * - uses: danger/... + * args: "--dangerfile artsy/peril-settings/org/allPRs.ts" * ``` * * This runs the file [`org/allPRs.ts`](https://github.com/artsy/peril-settings/blob/master/org/allPRs.ts) - * from the repo [artsy/peril-settings](https://github.com/artsy/peril-settings). + * from the repo [artsy/peril-settings](https://github.com/artsy/peril-settings). This gives you the ability + * to have Danger acting on non-pull-requests via GitHub Actions. * * ### Token Setup * @@ -41,11 +125,10 @@ import { readFileSync, existsSync } from "fs" * enabled in your workspace. This is so that Danger can connect * to GitHub. * - * ``` - * action "Danger JS" { - * uses = "danger/danger-js@master" - * secrets = ["GITHUB_TOKEN"] - * } + * ```yml + * - name: Danger JS + * uses: danger/danger-js@9.1.6 + * env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} * ``` * */ diff --git a/source/platforms/platform.ts b/source/platforms/platform.ts index 96fd584c7..2ad9cb185 100644 --- a/source/platforms/platform.ts +++ b/source/platforms/platform.ts @@ -141,10 +141,12 @@ export function getPlatformForEnv(env: Env, source: CISource): Platform { // They need to set the token up for GitHub actions to work if (env["GITHUB_EVENT_NAME"] && !env["GITHUB_TOKEN"]) { console.error(`You need to add GITHUB_TOKEN to your Danger action in the workflow: - - action "${env["GITHUB_ACTION"]}" { - ${chalk.green('+ secrets = ["GITHUB_TOKEN"]"')} - }`) + + - name: Danger JS + uses: danger/danger-js@X.Y.Z + ${chalk.green(`env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}`)} + `) } // GitHub Platform From 295d0654f845b04b563f612953e82f461f4b8847 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 15 Aug 2019 11:16:24 -0400 Subject: [PATCH 06/16] vbump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89790590e..6295c11a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "9.1.5", + "version": "9.1.6", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", From 329df5dc6c6db96b5293537671a3d5b5fc5b25cb Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 15 Aug 2019 11:17:14 -0400 Subject: [PATCH 07/16] Docs update --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad736cf6c..89009375b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,16 @@ +# 9.1.7 + +- GitHub Actions docs update - [@orta] + +# 9.1.6 + +- Release only made for GitHub Actions - [@orta] + +# 9.1.5 + - Take commit hash from bitrise env - [@f-meloni] # 9.1.4 From 54530706dc611a070285a88a772d05ad3d003bc2 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 15 Aug 2019 11:21:30 -0400 Subject: [PATCH 08/16] Release 9.1.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6295c11a0..9c309caaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "9.1.6", + "version": "9.1.7", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", From eb45b225025ac07891963d213f0fa2d004f1ff32 Mon Sep 17 00:00:00 2001 From: Ilja Daderko Date: Mon, 19 Aug 2019 09:44:33 +0300 Subject: [PATCH 09/16] Fix event.json path in new GitHub Actions When using danger through `node_modules` during new actions run i.e `run: yarn danger ci` as opposed to `uses: danger/danger-js` path to `event.json` file is different. Path to this file exists on `GITHUB_EVENT_PATH` env variable. Further discussion happened here: https://spectrum.chat/danger/general/does-danger-support-new-github-actions~e19e146a-c155-4e29-9b2b-d2ad9c3da3f0 --- source/ci_source/providers/GitHubActions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 91c435a82..038e20ccf 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -138,7 +138,8 @@ export class GitHubActions implements CISource { constructor(private readonly env: Env) { if (existsSync("/github/workflow/event.json")) { - const event = readFileSync("/github/workflow/event.json", "utf8") + const eventFilePath = process.env.GITHUB_EVENT_PATH || "/github/workflow/event.json" + const event = readFileSync(eventFilePath, "utf8") this.event = JSON.parse(event) } } From 700dce75ca2b389a660a88821a261f7329200220 Mon Sep 17 00:00:00 2001 From: Ilja Daderko Date: Mon, 19 Aug 2019 16:16:39 +0300 Subject: [PATCH 10/16] Update GitHubActions.ts --- source/ci_source/providers/GitHubActions.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 038e20ccf..82db6e848 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -133,12 +133,13 @@ import { readFileSync, existsSync } from "fs" * */ +const eventFilePath = process.env.GITHUB_EVENT_PATH || "/github/workflow/event.json" + export class GitHubActions implements CISource { private event: any constructor(private readonly env: Env) { - if (existsSync("/github/workflow/event.json")) { - const eventFilePath = process.env.GITHUB_EVENT_PATH || "/github/workflow/event.json" + if (existsSync(eventFilePath)) { const event = readFileSync(eventFilePath, "utf8") this.event = JSON.parse(event) } From 55b75f330e035d84cc758bb7f1c0da0ef7d2ecb3 Mon Sep 17 00:00:00 2001 From: Ilja Daderko Date: Mon, 19 Aug 2019 16:26:48 +0300 Subject: [PATCH 11/16] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89009375b..bf4bf2b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ +# 9.1.8 + +- Get GitHub Actions event file pathname from env variable - [@IljaDaderko] + # 9.1.7 - GitHub Actions docs update - [@orta] From 178fb30516d3488d8473fe23e39e10a881225952 Mon Sep 17 00:00:00 2001 From: Ilja Daderko Date: Mon, 19 Aug 2019 19:08:59 +0300 Subject: [PATCH 12/16] Grab github variable from env --- source/ci_source/providers/GitHubActions.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 82db6e848..0955188d6 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -133,12 +133,13 @@ import { readFileSync, existsSync } from "fs" * */ -const eventFilePath = process.env.GITHUB_EVENT_PATH || "/github/workflow/event.json" - export class GitHubActions implements CISource { private event: any constructor(private readonly env: Env) { + const { GITHUB_EVENT_PATH } = env + const eventFilePath = GITHUB_EVENT_PATH || "/github/workflow/event.json" + if (existsSync(eventFilePath)) { const event = readFileSync(eventFilePath, "utf8") this.event = JSON.parse(event) From 0dc412ee7fc2fcb11a7be26015601547ab089174 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 19 Aug 2019 12:58:12 -0400 Subject: [PATCH 13/16] Prepare for release --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4bf2b6a..fd158432e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1705,3 +1705,4 @@ Not usable for others, only stubs of classes etc. - [@orta] [@mrndjo]: https://github.com/mrndjo [@bigkraig]: https://github.com/bigkraig [@notjosh]: https://github.com/notjosh +[@iljadaderko]: https://github.com/IljaDaderko From fbcbc6a9f652227b481b28ca226cee02a820d970 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 19 Aug 2019 12:59:15 -0400 Subject: [PATCH 14/16] Release 9.1.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c309caaa..a04fec0ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "9.1.7", + "version": "9.1.8", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", From 5a053c6cd554c40ed08ff760bc9bde980fe3113b Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Thu, 22 Aug 2019 09:44:34 -0700 Subject: [PATCH 15/16] Improve docs for GitHub Actions Reference: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswithargs --- source/ci_source/providers/GitHubActions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 0955188d6..9b3582512 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -112,7 +112,8 @@ import { readFileSync, existsSync } from "fs" * * ``` * - uses: danger/... - * args: "--dangerfile artsy/peril-settings/org/allPRs.ts" + * with: + * args: "--dangerfile artsy/peril-settings/org/allPRs.ts" * ``` * * This runs the file [`org/allPRs.ts`](https://github.com/artsy/peril-settings/blob/master/org/allPRs.ts) From 0dd31320bf4a4abbdeb9e97a0af375b4a1a2b9b3 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Thu, 22 Aug 2019 09:51:08 -0700 Subject: [PATCH 16/16] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd158432e..e1bb77a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ +- Improve docs for GitHub Actions - [@nguyenhuy] + # 9.1.8 - Get GitHub Actions event file pathname from env variable - [@IljaDaderko]