Skip to content

Commit

Permalink
chore(ci): add brigade configuration (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Oct 19, 2018
1 parent 18d8905 commit e67dd43
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
1 change: 1 addition & 0 deletions .bettercodehub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ exclude:
- /vendor/.*
- /docs/.*
- /website/.*
- brigade.js
component_depth: 1
languages:
- go
Expand Down
1 change: 1 addition & 0 deletions .codebeatignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs/**
vendor/**
website/**
brigade.js
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

73 changes: 73 additions & 0 deletions brigade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { events, Job, Group } = require("brigadier");

events.on("exec", function (e, project) {
job = conform(e, project)
job.run().then(result => {
console.log(result.toString())
})
})

events.on("push", function (e, project) {
job = conform(e, project)
job.run().then(result => {
console.log(result.toString())
})
})

events.on("pull_request", function (e, project) {
start = notify("pending", `Build ${e.buildID} started`, e, project)
job = conform(e, project)
Group.runAll([start, job])
.then(() => {
return notify("success", `Build ${e.buildID} passed`, e, project).run()
}).catch(err => {
return notify("failure", `Build ${e.buildID} failed`, e, project).run()
});
})

function conform(e, project) {
var job = new Job("conform", "golang:1.11.1")

job.env = {
// "DOCKER_HOST": "tcp://docker:2375"
"DOCKER_USERNAME": project.secrets.DOCKER_USERNAME,
"DOCKER_PASSWORD": project.secrets.DOCKER_PASSWORD,
"GO111MODULE": "on",
}

job.tasks = [
"apt-get update",
"apt-get -y install apt-transport-https ca-certificates curl software-properties-common",
"curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -",
"add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\"",
"apt-get update",
"apt-get -y install docker-ce=18.06.1~ce~3-0~debian",
"cd /src",
"go install .",
"conform enforce",
"conform build",
]

job.docker.enabled = true

// Unit is milliseconds, 900000ms = 15m.
job.timeout = 900000

job.host.nodeSelector.set("node-role.kubernetes.io/ci", "")

return job
}

function notify(state, msg, e, project) {
const gh = new Job(`notify-${state}`, "technosophos/github-notify:latest")
gh.env = {
GH_REPO: project.repo.name,
GH_STATE: state,
GH_DESCRIPTION: msg,
GH_CONTEXT: "brigade",
GH_TOKEN: project.secrets.GH_TOKEN,
GH_COMMIT: e.revision.commit,
GH_TARGET_URL: `https://ci.dev.autonomy.io/builds/${e.buildID}`,
}
return gh
}

0 comments on commit e67dd43

Please sign in to comment.