This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathic.js
executable file
·91 lines (82 loc) · 2.6 KB
/
ic.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
// or else the Gruntfile from the depending project will run the code!
if (require.main === module) {
const request = require('request-promise-native');
const username = process.env.CIRCLE_TOKEN;
const password = '';
const auth = `Basic ${new Buffer(`${username}:${password}`).toString('base64')}`;
const projectName = process.argv[2] || require('./package.json').name;
const firstCheckToken = {
method: 'GET',
uri: 'https://circleci.com/api/v1.1/me',
headers: {
Authorization: auth,
},
json: true,
resolveWithFullResponse: false,
};
const secondCreateProject = {
method: 'POST',
uri: `https://circleci.com/api/v1/project/Zenika/${projectName}/follow`,
headers: {
Authorization: auth,
},
json: true,
};
const thirdSetEnvVariableGaeServiceAccount = {
method: 'POST',
uri: `https://circleci.com/api/v1/project/Zenika/${projectName}/envvar`,
headers: {
Authorization: auth,
},
body: {
name: 'GAE_SERVICE_ACCOUNT',
value: process.env.GAE_SERVICE_ACCOUNT,
},
json: true,
};
const thirdSetEnvVariableGaeKey = {
method: 'POST',
uri: `https://circleci.com/api/v1/project/Zenika/${projectName}/envvar`,
headers: {
Authorization: auth,
},
body: {
name: 'GAE_KEY_FILE_CONTENT',
value: process.env.GAE_KEY_FILE_CONTENT,
},
json: true,
};
const deleteCache = {
method: 'DELETE',
uri: `https://circleci.com/api/v1/project/Zenika/${projectName}/build-cache`,
headers: {
Authorization: auth,
},
json: true,
};
const retryMasterBuild = () => ({
method: 'POST',
uri: `https://circleci.com/api/v1/project/Zenika/${projectName}/tree/master`,
headers: {
Authorization: auth,
},
json: true,
});
request(firstCheckToken)
.then(data => console.log(`👷 Welcome ${data.login}`))
.then(() => request(secondCreateProject))
.then((data) => {
if (!data.first_build) return console.log(`🚧 Project ${projectName} already exists`);
return console.log(`🚧 Project ${projectName} created`);
})
.then(() => request(thirdSetEnvVariableGaeServiceAccount))
.then(() => request(thirdSetEnvVariableGaeKey))
.then(() => console.log('🔧 Env variables set!'))
.then(() => console.log('💣 Clearing cache...'))
.then(() => request(deleteCache))
.then(() => { console.log('✨ Re-building master'); })
.then(() => request(retryMasterBuild()))
.then(() => console.log('💚 All is done! Wait for a green deployment'))
.catch(err => console.log('💩 AieAieAie!\n', err));
}