diff --git a/.bettercodehub.yml b/.bettercodehub.yml index 7e4ff05b..bc3e198b 100644 --- a/.bettercodehub.yml +++ b/.bettercodehub.yml @@ -2,6 +2,7 @@ exclude: - /vendor/.* - /docs/.* - /website/.* +- brigade.js component_depth: 1 languages: - go diff --git a/.codebeatignore b/.codebeatignore index c11f344c..48377e9e 100644 --- a/.codebeatignore +++ b/.codebeatignore @@ -1,3 +1,4 @@ docs/** vendor/** website/** +brigade.js diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 627fe7c7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -sudo: required -dist: trusty - -language: generic - -install: - - mkdir -p $HOME/goroot - - curl -L https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz | tar -xz --strip-components=1 -C $HOME/goroot - - export GOROOT=$HOME/goroot - - export GOPATH=$HOME/gopath - - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - - mkdir -p $GOPATH/src/github.com/autonomy/conform - - rsync -az ${TRAVIS_BUILD_DIR}/ $GOPATH/src/github.com/autonomy/conform/ - - export TRAVIS_BUILD_DIR=$GOPATH/src/github.com/autonomy/conform - - cd $GOPATH/src/github.com/autonomy/conform - - sudo apt-get -y remove docker docker-engine - - sudo apt-get -y update - - sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - - sudo apt-get update - - sudo apt-get -y install docker-ce=18.06.1~ce~3-0~ubuntu - - GO111MODULE=on go get github.com/autonomy/conform - -script: - - GO111MODULE=on go mod tidy -v - - conform enforce - - conform build - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/brigade.js b/brigade.js new file mode 100644 index 00000000..755d74c5 --- /dev/null +++ b/brigade.js @@ -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 +}