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.
Browse files
Browse the repository at this point in the history
* add appVeyor environment variable update, close #1 * setup semantic release * feat(win): add appveyor variable support, close #1 * add status badges
- Loading branch information
Showing
8 changed files
with
178 additions
and
5 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
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,24 @@ | ||
exports['App Veyor API wrapper merge variables merges non-overlapping lists 1'] = [ | ||
{ | ||
"name": "foo", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "bar", | ||
"value": 2 | ||
} | ||
] | ||
|
||
exports['App Veyor API wrapper merge variables merges overlapping lists giving preference to new variables 1'] = [ | ||
{ | ||
"name": "foo", | ||
"value": "new value" | ||
} | ||
] | ||
|
||
exports['App Veyor API wrapper merge variables combines empty list with new 1'] = [ | ||
{ | ||
"name": "foo", | ||
"value": "new value" | ||
} | ||
] |
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,10 @@ | ||
machine: | ||
node: | ||
version: 8 | ||
|
||
deployment: | ||
prod: | ||
branch: master | ||
commands: | ||
# not every commit is going to be published | ||
- npm run semantic-release || true |
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,50 @@ | ||
Promise = require("bluebird") | ||
axios = require("axios") | ||
inspect = require("util").inspect | ||
R = require("ramda") | ||
|
||
mergeVariables = (existing, newVars) -> | ||
compare = (a, b) -> | ||
a.name == b.name | ||
unchanged = R.differenceWith(compare, existing, newVars) | ||
combined = R.concat(unchanged, newVars) | ||
combined | ||
|
||
toData = R.prop("data") | ||
|
||
module.exports = { | ||
mergeVariables, | ||
|
||
create: (token) -> | ||
throw new Error("AppVeyor requires an access token!") if !token | ||
|
||
api = axios.create({ | ||
baseURL: "https://ci.appveyor.com/api" | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': "Bearer #{token}" | ||
} | ||
}) | ||
|
||
api.setEnvironmentVariables = (projectName, listOfVars) -> | ||
url = "/projects/#{projectName}/settings/environment-variables" | ||
api.put(url, listOfVars) | ||
.then toData | ||
|
||
api.updateEnvironmentVariables = (projectName, listOfVars) -> | ||
## Note: AppVeyor __overwrites__ environment variables | ||
## thus we need to fetch existing ones and merge with new ones | ||
url = "/projects/#{projectName}/settings/environment-variables" | ||
api.get(url) | ||
.then toData | ||
.then (existingVariables) -> | ||
allVariables = mergeVariables(existingVariables, listOfVars) | ||
api.put(url, allVariables) | ||
.then toData | ||
|
||
api.triggerNewBuild = (projectName) -> | ||
throw new Error "Not implemented for AppVeyor yet" | ||
# api.post("/project/#{vcsType}/#{projectName}") | ||
|
||
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,39 @@ | ||
_ = require("lodash") | ||
Promise = require("bluebird") | ||
appVeyorApi = require("./app-veyor-api") | ||
debug = require("debug")("bumper") | ||
|
||
api = | ||
configure: (options={}) -> | ||
api = appVeyorApi.create(options.appVeyorToken) | ||
|
||
return { | ||
updateProjectEnv: (projectName, varsToSet) -> | ||
listOfVars = _.map varsToSet, (value, name) -> | ||
{ | ||
name, | ||
value: { | ||
isEncrypted: false, | ||
value: value | ||
} | ||
} | ||
|
||
debug("setting AppVeyor variables") | ||
debug(listOfVars) | ||
api.updateEnvironmentVariables(projectName, listOfVars) | ||
|
||
runProject: (projectName) -> | ||
api.triggerNewBuild(projectName) | ||
} | ||
|
||
module.exports = api | ||
|
||
if !module.parent | ||
console.log("AppVeyor 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/cypress-example-kitchensink", { | ||
foo: "foo" | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
travisProvider: require("./travis") | ||
circleProvider: require("./circle") | ||
appVeyorProvider: require("./app-veyor") | ||
} |
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
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,26 @@ | ||
require("./spec_helper") | ||
|
||
appVeyprApi = require("../lib/providers/app-veyor-api") | ||
snapshot = require("snap-shot-it") | ||
|
||
describe "App Veyor API wrapper", -> | ||
context "merge variables", -> | ||
mergeVariables = appVeyprApi.mergeVariables | ||
|
||
it "merges non-overlapping lists", -> | ||
existing = [{name: "foo", value: 1}] | ||
newVars = [{name: "bar", value: 2}] | ||
combined = mergeVariables(existing, newVars) | ||
snapshot(combined) | ||
|
||
it "merges overlapping lists giving preference to new variables", -> | ||
existing = [{name: "foo", value: "old value"}] | ||
newVars = [{name: "foo", value: "new value"}] | ||
combined = mergeVariables(existing, newVars) | ||
snapshot(combined) | ||
|
||
it "combines empty list with new", -> | ||
existing = [] | ||
newVars = [{name: "foo", value: "new value"}] | ||
combined = mergeVariables(existing, newVars) | ||
snapshot(combined) |