Skip to content

Commit

Permalink
Merge pull request #1 from krancour/initial
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
krancour authored Jul 29, 2021
2 parents 5a43f80 + 94cb8fd commit 4a9623b
Show file tree
Hide file tree
Showing 31 changed files with 2,027 additions and 201 deletions.
63 changes: 63 additions & 0 deletions .brigade/brigade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { events, Event, Job, ConcurrentGroup } from "@brigadecore/brigadier"

const goImg = "brigadecore/go-tools:v0.1.0"
const localPath = "/workspaces/brigade-foundations"

// MakeTargetJob is just a job wrapper around a make target.
class MakeTargetJob extends Job {
constructor(target: string, img: string, event: Event, env?: {[key: string]: string}) {
super(target, img, event)
this.primaryContainer.sourceMountPath = localPath
this.primaryContainer.workingDirectory = localPath
this.primaryContainer.environment = env || {}
this.primaryContainer.environment["SKIP_DOCKER"] = "true"
this.primaryContainer.command = [ "make" ]
this.primaryContainer.arguments = [ target ]
}
}

// A map of all jobs. When a check_run:rerequested event wants to re-run a
// single job, this allows us to easily find that job by name.
const jobs: {[key: string]: (event: Event) => Job } = {}

const testUnitJobName = "test-unit"
const testUnitJob = (event: Event) => {
return new MakeTargetJob(testUnitJobName, goImg, event)
}
jobs[testUnitJobName] = testUnitJob

const lintJobName = "lint"
const lintJob = (event: Event) => {
return new MakeTargetJob(lintJobName, goImg, event)
}
jobs[lintJobName] = lintJob

// Run the entire suite of tests WITHOUT publishing anything initially. If
// EVERYTHING passes AND this was a push (merge, presumably) to the master
// branch, then publish an "edge" image.
async function runSuite(event: Event): Promise<void> {
await new ConcurrentGroup( // Basic tests
testUnitJob(event),
lintJob(event),
).run()
}

// Either of these events should initiate execution of the entire test suite.
events.on("brigade.sh/github", "check_suite:requested", runSuite)
events.on("brigade.sh/github", "check_suite:rerequested", runSuite)

// This event indicates a specific job is to be re-run.
events.on("brigade.sh/github", "check_run:rerequested", async event => {
// Check run names are of the form <project name>:<job name>, so we strip
// event.project.id.length + 1 characters off the start of the check run name
// to find the job name.
const jobName = JSON.parse(event.payload).check_run.name.slice(event.project.id.length + 1)
const job = jobs[jobName]
if (job) {
await job(event).run()
return
}
throw new Error(`No job found with name: ${jobName}`)
})

events.process()
6 changes: 6 additions & 0 deletions .brigade/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "brigade-foundations-ci-cd",
"dependencies": {
"@brigadecore/brigadier": "^2.0.0-beta.1"
}
}
19 changes: 19 additions & 0 deletions .brigade/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/brigadecore/brigade/v2/v2/apiserver/schemas/project.json
apiVersion: brigade.sh/v2-beta
kind: Project
metadata:
id: brigade-foundations
description: Brigade Foundations built with Brigade 2!
spec:
eventSubscriptions:
- source: brigade.sh/github
qualifiers:
repo: brigadecore/brigade-foundations
types:
- check_run:rerequested
- check_suite:requested
- check_suite:rerequested
- push
workerTemplate:
git:
cloneURL: https://github.com/brigadecore/brigade-foundations.git
15 changes: 15 additions & 0 deletions .brigade/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@brigadecore/brigadier@^2.0.0-beta.1":
version "2.0.0-beta.1"
resolved "https://registry.yarnpkg.com/@brigadecore/brigadier/-/brigadier-2.0.0-beta.1.tgz#8abd9461d445d1d13c83404cec22c16f3cbc2104"
integrity sha512-PoDfSAYMpqXyhTP+DBE7B1xHXtCxuW7SCLcH9/yQyr4kgeKxsAyYvy1baQx1G5ujpWcKX4ULmxf7dsJdHPX+3w==
dependencies:
"@types/node" "^14.14.11"

"@types/node@^14.14.11":
version "14.17.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.6.tgz#cc61c8361c89e70c468cda464d1fa3dd7e5ebd62"
integrity sha512-iBxsxU7eswQDGhlr3AiamBxOssaYxbM+NKXVil8jg9yFXvrfEFbDumLD/2dMTB+zYyg7w+Xjt8yuxfdbUHAtcQ==
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.gocache/
coverage.txt
.DS_Store
.brigade/node_modules/
.brigade/secrets.yaml

# IDEs
.vscode/
.devcontainer/
.idea/
.swp
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is described here: https://help.github.com/en/articles/about-code-owners

# Global Owners: These members are Core Maintainers of Brigade
* @brigadecore/maintainers
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing Guide

See our Brigade project [Contributing Guide](https://github.com/brigadecore/community/blob/master/contributing.md).
Loading

0 comments on commit 4a9623b

Please sign in to comment.