This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add buildkite support for env vars for #5
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
axios = require("axios") | ||
R = require("ramda") | ||
la = require("lazy-ass") | ||
check = require("check-more-types") | ||
debug = require("debug")("bumper") | ||
|
||
toData = R.prop("data") | ||
|
||
getPipelineUrl = (organization, project) -> | ||
la(check.unemptyString(organization), "missing organization", organization) | ||
la(check.unemptyString(project), "missing project", project) | ||
"/organizations/#{organization}/pipelines/#{project}" | ||
|
||
module.exports = { | ||
create: (token) -> | ||
throw new Error("Buildkite requires an access token!") if !token | ||
|
||
api = axios.create({ | ||
baseURL: "https://api.buildkite.com/v2" | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': "Bearer #{token}" | ||
} | ||
}) | ||
|
||
api.getPipelineUrl = getPipelineUrl | ||
|
||
api.getPipeline = (organization, project) -> | ||
url = getPipelineUrl(organization, project) | ||
debug("getting pipeline", url) | ||
api.get(url) | ||
.then toData | ||
|
||
api.setPipeline = (organization, project, pipeline) -> | ||
la(check.object(pipeline), "missing pipeline to set", pipeline) | ||
debug("setting pipeline for", organization, project) | ||
url = getPipelineUrl(organization, project) | ||
api.post(url, pipeline) | ||
.then toData | ||
|
||
api.setEnvironmentVariables = (organization, project, variables = {}) -> | ||
url = getPipelineUrl(organization, project) | ||
api.patch(url, { | ||
env: variables | ||
}) | ||
|
||
api.updateEnvironmentVariables = (organization, project, variables) -> | ||
api.getPipeline(organization, project) | ||
.then (pipeline) -> | ||
merged = R.merge(pipeline.env, variables) | ||
api.setEnvironmentVariables(organization, project, merged) | ||
|
||
api.triggerNewBuild = (organization, project) -> | ||
throw new Error "Not implemented for Buildkite yet" | ||
# https://buildkite.com/docs/rest-api/builds#create-a-build | ||
|
||
return api | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
_ = require("lodash") | ||
Promise = require("bluebird") | ||
providerApi = require("./buildkite-api") | ||
debug = require("debug")("bumper") | ||
|
||
api = | ||
configure: (options={}) -> | ||
api = providerApi.create(options.buildkiteToken) | ||
|
||
return { | ||
updateProjectEnv: (organization, project, variables) -> | ||
debug("updating Buildkite variables for", organization, project) | ||
debug(variables) | ||
api.updateEnvironmentVariables(organization, project, variables) | ||
|
||
runProject: (organization, project) -> | ||
api.triggerNewBuild(organization, project) | ||
} | ||
|
||
module.exports = api | ||
|
||
if !module.parent | ||
console.log("Buildkite demo") | ||
if !process.env.support__ci_json | ||
throw new Error("Missing support__ci_json in environment") | ||
tokens = JSON.parse(process.env.support__ci_json) | ||
ci = api.configure(tokens) | ||
ci.updateProjectEnv("cypress-io", "bumpercar-test", { | ||
foo: "foo" | ||
}).catch(console.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters