-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
66 lines (58 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** Copyright (c) 2017 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fetch = require('node-fetch');
module.exports = robot => {
robot.on('release.published', released);
async function released(context) {
const {github} = context;
const {release} = context.payload;
github.repos.createForAuthenticatedUserDeployment(
context.repo({
ref: release.tag_name,
auto_merge: false,
// Bypass required context checking when creating a deployment
required_contexts: [],
}),
);
// Kick off a deployment through buildkite
const {login} = release.author;
const {name, ssh_url} = context.payload.repository;
let output;
try {
const payload = {
commit: 'HEAD',
branch: 'master',
message: `Deploy ${name}`,
author: {
name: login,
},
env: {
PUBLISH_REPO: ssh_url,
TARGET_COMMITISH: release.tag_name,
},
};
if (process.env.PUBLISH_ARGS) {
payload.env.PUBLISH_ARGS = process.env.PUBLISH_ARGS;
}
const res = await fetch(
'https://api.buildkite.com/v2/organizations/uberopensource/pipelines/npm-deploy/builds',
{
method: 'POST',
body: JSON.stringify(payload),
headers: {
Authorization: `Bearer ${process.env.BUILDKITE_TOKEN}`,
},
},
);
output = await res.json();
// eslint-disable-next-line no-console
console.log('Buildkite triggered', output);
} catch (err) {
// eslint-disable-next-line no-console
console.warn(err);
}
}
};