Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI integration for Concourse #658

Merged
merged 3 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

## Master

- Adds CI integration for Concourse - [@cwright017][]

# 3.8.9

- Adds debug logs to the vm2 runner used in Peril - [@orta][]
Expand Down Expand Up @@ -1223,3 +1225,4 @@ Not usable for others, only stubs of classes etc. - [@orta][]
[@codestergit]: https://github.com/codestergit
[@danielrosenwasser]: https://github.com/DanielRosenwasser
[@joshacheson]: https://github.com/joshacheson
[@cwright017]: https://github.com/Cwright017
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ review.
You can use Danger to codify your teams norms, leaving humans to think about harder problems.

Danger JS currently works with GitHub or BitBucket Server and Travis CI, Circle CI, Semaphore, Jenkins, Docker Cloud,
Bitrise, surf-build, Codeship, Drone, Buildkite, Nevercode, buddybuild, Visual Studio Team Services, TeamCity or
Screwdriver.
Bitrise, surf-build, Codeship, Drone, Buildkite, Nevercode, buddybuild, Visual Studio Team Services, TeamCity,
Screwdriver or Concourse.

[![npm](https://img.shields.io/npm/v/danger.svg)](https://www.npmjs.com/package/danger)
[![Build Status](https://travis-ci.org/danger/danger-js.svg?branch=master)](https://travis-ci.org/danger/danger-js)
Expand All @@ -32,12 +32,12 @@ Screwdriver.

You can:

* Enforce CHANGELOGs
* Enforce links to Trello/JIRA in PR/MR bodies
* Enforce using descriptive labels
* Look out for common anti-patterns
* Highlight interesting build artifacts
* Give warnings when specific files change
- Enforce CHANGELOGs
- Enforce links to Trello/JIRA in PR/MR bodies
- Enforce using descriptive labels
- Look out for common anti-patterns
- Highlight interesting build artifacts
- Give warnings when specific files change

Danger provides the glue to let _you_ build out the rules specific to your team's culture, offering useful metadata and
a comprehensive plugin system to share common issues.
Expand All @@ -51,9 +51,9 @@ We keep all of the end-user documentation at <http://danger.systems/js>.

Some quick links to get you started:

* [Getting Started](http://danger.systems/js/guides/getting_started.html)
* [Guides Index](http://danger.systems/js/guides.html)
* [DSL Reference](http://danger.systems/js/reference.html)
- [Getting Started](http://danger.systems/js/guides/getting_started.html)
- [Guides Index](http://danger.systems/js/guides.html)
- [DSL Reference](http://danger.systems/js/reference.html)

## This thing is broken, I should help improve it!

Expand Down Expand Up @@ -92,12 +92,12 @@ Check the issues, I try and keep my short term perspective there. Long term is i

Following [this commit](https://github.com/danger/danger-js/commit/a26ac3b3bd4f002acd37f6a363c8e74c9d5039ab) as a model:

* Checkout the `master` branch. Ensure your working tree is clean, and make sure you have the latest changes by running
- Checkout the `master` branch. Ensure your working tree is clean, and make sure you have the latest changes by running
`git pull`.
* Update `package.json` with the new version - for the sake of this example, the new version is **0.21.0**.
* Modify `changelog.md`, adding a new `### 0.21.0` heading under the `### Master` heading at the top of the file.
* Commit both changes with the commit message **Version bump**.
* Publish - `npm publish`.
- Update `package.json` with the new version - for the sake of this example, the new version is **0.21.0**.
- Modify `changelog.md`, adding a new `### 0.21.0` heading under the `### Master` heading at the top of the file.
- Commit both changes with the commit message **Version bump**.
- Publish - `npm publish`.

:ship:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "3.8.9",
"version": "3.9.0",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
60 changes: 60 additions & 0 deletions source/ci_source/providers/Concourse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"

/**
* Concourse CI Integration
*
* https://concourse-ci.org/
*
* ### CI Setup
*
* With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs.
*
* ``` shell
* build:
* image: golang
* commands:
* - ...
* - yarn danger ci
* ```
*
* ### Environment Variable Setup
*
* As this is self-hosted, you will need to add the `CONCOURSE` environment variable `export CONCOURSE=true` to your build environment,
* as well as setting environment variables for `PULL_REQUEST_ID` and `REPO_SLUG`. Assuming you are using the github pull request resource
* https://github.com/jtarchie/github-pullrequest-resource the id of the PR can be accessed from `git config --get pullrequest.id`.
*
* ### Token Setup
*
* Once again as this is self-hosted, you will need to add `DANGER_GITHUB_API_TOKEN` environment variable to the build environment.
* The suggested method of storing the token is within the vault - https://concourse-ci.org/creds.html
*/
export class Concourse implements CISource {
constructor(private readonly env: Env) {}

get name(): string {
return "Concourse"
}

get isCI(): boolean {
return ensureEnvKeysExist(this.env, ["CONCOURSE"])
}

get isPR(): boolean {
const mustHave = ["PULL_REQUEST_ID", "REPO_SLUG"]
const mustBeInts = ["PULL_REQUEST_ID"]
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts)
}

get pullRequestID(): string {
return this.env.PULL_REQUEST_ID
}

get repoSlug(): string {
return this.env.REPO_SLUG
}

get ciRunURL() {
return this.env.BUILD_URL
}
}
72 changes: 72 additions & 0 deletions source/ci_source/providers/_tests/_concourse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Concourse } from "../Concourse"
import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
CONCOURSE: "true",
REPO_SLUG: "danger/danger-js",
PULL_REQUEST_ID: "2",
BUILD_URL: "https://github.com/danger/danger-js/blob/master",
}

describe("being found when looking for CI", () => {
it("finds Concourse with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(Concourse)
})
})

describe(".isCI", () => {
it("validates when all Concourse environment vars are set", () => {
const concourse = new Concourse(correctEnv)
expect(concourse.isCI).toBeTruthy()
})

it("does not validate without env", () => {
const concourse = new Concourse({})
expect(concourse.isCI).toBeFalsy()
})
})

describe(".isPR", () => {
it("validates when all Concourse environment vars are set", () => {
const concourse = new Concourse(correctEnv)
expect(concourse.isPR).toBeTruthy()
})

it("does not validate outside of Concourse", () => {
const concourse = new Concourse({})
expect(concourse.isPR).toBeFalsy()
})

const envs = ["CONCOURSE", "REPO_SLUG", "PULL_REQUEST_ID"]
envs.forEach((key: string) => {
let env = Object.assign({}, correctEnv)
env[key] = null

it(`does not validate when ${key} is missing`, () => {
const concourse = new Concourse({})
expect(concourse.isCI && concourse.isPR).toBeFalsy()
})
})

describe("repo slug", () => {
it("returns correct slug", () => {
const concourse = new Concourse(correctEnv)
expect(concourse.repoSlug).toEqual("danger/danger-js")
})
})

describe("pull request id", () => {
it("returns correct id", () => {
const concourse = new Concourse(correctEnv)
expect(concourse.pullRequestID).toEqual("2")
})
})

describe("build url", () => {
it("returns correct build url", () => {
const concourse = new Concourse(correctEnv)
expect(concourse.ciRunURL).toEqual("https://github.com/danger/danger-js/blob/master")
})
})
})
3 changes: 3 additions & 0 deletions source/ci_source/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BuddyBuild } from "./BuddyBuild"
import { Buildkite } from "./Buildkite"
import { Circle } from "./Circle"
import { Codeship } from "./Codeship"
import { Concourse } from "./Concourse"
import { DockerCloud } from "./DockerCloud"
import { Drone } from "./Drone"
import { FakeCI } from "./Fake"
Expand Down Expand Up @@ -32,6 +33,7 @@ const providers = [
Bitrise,
TeamCity,
Screwdriver,
Concourse,
]

// Mainly used for Dangerfile linting
Expand All @@ -50,6 +52,7 @@ const realProviders = [
VSTS,
TeamCity,
Screwdriver,
Concourse,
]

export { providers, realProviders }