Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
feat(ci): add appVeyor environment variable update, close #1 (#3)
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
bahmutov committed Oct 4, 2017
1 parent f7890be commit 826ceab
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Make it easy to bump versions and re-run CI builds across many projects and CI providers.

[![CircleCI](https://circleci.com/gh/cypress-io/bumpercar.svg?style=svg)](https://circleci.com/gh/cypress-io/bumpercar)
[![semantic-release][semantic-image] ][semantic-url]

[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-url]: https://github.com/semantic-release/semantic-release

```coffeescript
bumpercar = require("cypress-bumpercar")

Expand Down Expand Up @@ -36,6 +42,10 @@ car.updateProjectEnv("cypress-io/cypress-download", "circle", {
- `npm test` runs the unit tests once
- `npm run watch` keeps watching for file changes and reruns the tests

## Debugging

Run commands with `DEBUG=bumper` environment variable

## Changelog

#### 1.0.6 - *(04/20/17)*
Expand Down
24 changes: 24 additions & 0 deletions __snapshots__/app_veyor_api_spec.coffee.js
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"
}
]
10 changes: 10 additions & 0 deletions circle.yml
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
50 changes: 50 additions & 0 deletions lib/providers/app-veyor-api.coffee
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
}
39 changes: 39 additions & 0 deletions lib/providers/app-veyor.coffee
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"
})
1 change: 1 addition & 0 deletions lib/providers/index.coffee
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")
}
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "@cypress/bumpercar",
"version": "1.0.6",
"version": "0.0.0-development",
"description": "Easily update settings and trigger builds across projects and CI Providers.",
"main": "index.js",
"scripts": {
"release": "releaser",
"test": "NODE_ENV=test mocha",
"watch": "NODE_ENV=test mocha --watch"
"watch": "NODE_ENV=test mocha --watch",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cypress-io/cypress-bumpercar.git"
"url": "https://github.com/cypress-io/cypress-bumpercar.git"
},
"keywords": [
"deployment",
Expand All @@ -26,14 +27,26 @@
"dependencies": {
"@cypress/coffee-script": "0.1.2",
"axios": "^0.15.3",
"bluebird": "^3.5.0"
"bluebird": "^3.5.0",
"debug": "^3.1.0",
"lodash": "^4.17.4",
"ramda": "^0.24.1"
},
"devDependencies": {
"@cypress/releaser": "0.1.12",
"chai": "^3.5.0",
"condition-circle": "^1.5.0",
"github-post-release": "^1.13.1",
"mocha": "^3.2.0",
"semantic-release": "^8.0.3",
"sinon": "^1.17.7",
"sinon-as-promised": "^4.0.2",
"sinon-chai": "^2.8.0"
"sinon-chai": "^2.8.0",
"snap-shot-it": "^4.0.1"
},
"release": {
"verifyConditions": "condition-circle",
"analyzeCommits": "simple-commit-message",
"generateNotes": "github-post-release"
}
}
26 changes: 26 additions & 0 deletions test/app_veyor_api_spec.coffee
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)

0 comments on commit 826ceab

Please sign in to comment.