-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag_version.js
129 lines (104 loc) · 2.95 KB
/
tag_version.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var Q = require("q"),
fs = require("q-io/fs"),
parseString = require('xml2js').parseString,
shell = require('shelljs'),
env = require('env-variable'),
pluginConfigFile = 'addon.xml';
var gitUrl = 'https://github.com/ArabicXBMC/plugin.video.dailytube4u.com.git',
tagMessage = 'This is a tag message',
envName = 'GIT_NAME',
envEmail = 'GIT_EMAIL',
envToken = 'GH_TOKEN',
envXBMCPluginVersion = 'NEW_PLUGIN_VERSION';
Q()
//.then(readPluginConfig)
//.then(xmlToJson)
//.then(readPluginVersion)
// .then(setUserInfo)
// .then(writeGitCredentials)
// .then(setRemoteUrl)
// .then(fetchTags)
// .then(tag)
// .then(pushTags)
.then(writeEnv)
.catch(function(msg){
console.log(msg || 'release failed')
// grunt.fail.warn(msg || 'release failed')
})
.done(function(){
console.log('done', arguments);
});
function readPluginConfig() {
return Q.fcall(function () {
return fs.read(pluginConfigFile)
});
}
function xmlToJson(xml) {
var deferred = Q.defer();
parseString(xml, function (error, result) {
if (error) {
deferred.reject(new Error(error));
}
else {
deferred.resolve(result);
}
});
return deferred.promise;
}
function readPluginVersion(xmlDoc) {
return Q.fcall(function () {
return xmlDoc.addon.$.version;
});
}
function writeEnv() {
return Q.fcall(function () {
run('touch .semaphore');
});
}
function run(cmd, silent){
var silent = typeof silent !== 'undefined' ? silent : false,
deferred = Q.defer();
//grunt.verbose.writeln('Running: ' + cmd);
shell.exec(cmd, { silent: false }, function(code, output){
if (code === 0) {
console.log('->', cmd);
console.log('#', output);
deferred.resolve();
}
else {
deferred.reject('Error: cmd: `' + cmd + '`\n stderr: ' + output);
}
});
return deferred.promise;
}
function setUserInfo() {
var name = shell.env[envName] || 'Hady',
email = shell.env[envEmail] || '[email protected]';
return Q.all([
run('git config --global user.name "' + name + '"'),
run('git config --global user.email "' + email + '"')
]);
}
function writeGitCredentials() {
var token = shell.env[envToken];
return Q()
.then(function(){
return run('git config credential.helper "store --file=.git/credentials"');
})
.then(function(){
return run('echo "https://' + token + ':@github.com" > .git/credentials');
});
}
function setRemoteUrl() {
return run('git remote set-url origin ' + gitUrl);
}
function fetchTags() {
return run('git fetch --tags');
}
function tag(versionNumber){
versionNumber = '2.3.3';
return run('git tag ' + versionNumber + ' -m "'+ tagMessage +'"');
}
function pushTags(){
return run('git push --tags');
}