/
release.php
110 lines (80 loc) · 2.61 KB
/
release.php
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
<?php
function UpdateTemplate($templateFile, $outputFile, $templateVariables)
{
$content = file_get_contents($templateFile);
// upgrade template variables
foreach($templateVariables as $key => $value)
{
$content = str_replace('{'. $key . '}', $value, $content);
}
file_put_contents($outputFile, $content);
}
function print_log($message)
{
echo $message . PHP_EOL;
}
function log_error($message)
{
echo 'ERROR : ' . $message . PHP_EOL;
die();
}
function exec_system($command)
{
echo $command . PHP_EOL;
$result = 0;
$output = array();
$output = system($command, $result);
if($result !== 0)
{
echo $output;
log_error('execution of command ' . $command . ' failed');
}
}
function exec_copy($source, $dest)
{
if(!copy($source, $dest))
{
log_error('Cannot copy file ' . $source . ' to ' . $dest);
}
}
function move_chdir($path)
{
echo "cd " . $path . PHP_EOL;
chdir($path);
}
global $argc, $argv;
$nuspecTemplate = "ActionBarSherlock.Standalone.nuspec";
$projectName = "ActionBarSherlock.Standalone";
if($argc < 2)
{
echo "Usage : release.sh <version>";
die;
}
$versionNumber = $argv[$argc - 1];
$nugetDirectory = $versionNumber . "/";
if(!file_exists($nugetDirectory))
{
log_error("Missing directory " . $nugetDirectory . " to create nuget package");
}
print_log("# Ok let's go !");
print_log("# Updating nuspec file for " . $projectName . " in version " . $versionNumber);
$nuspecFile = $nugetDirectory . $nuspecTemplate;
UpdateTemplate($nuspecTemplate, $nuspecFile, array('version' => $versionNumber));
move_chdir($nugetDirectory);
print_log("# Generating nuget package for " . $projectName . " in version " . $versionNumber);
exec_system("nuget pack -Verbosity quiet -NonInteractive");
print_log("# Uploading nuget package " . $projectName . " version " . $versionNumber . " to nuget server");
exec_system("nuget push -Verbosity quiet -NonInteractive *.nupkg");
move_chdir('..');
print_log("# Add new packages to git");
exec_system("git add -f " . $versionNumber . "/*.nupkg");
$commitMessage = "Release nuget package " . $projectName . " in version " . $versionNumber;
$commitMessage = str_replace('"', '\\"', $commitMessage);
print_log("# Commit packages to git");
$tag = 'v_' . $versionNumber;
exec_system('git tag -a ' . $tag . ' -m "Release ' . $projectName . ' in version ' . $versionNumber . '"');
exec_system('git commit -m "' . $commitMessage . '"');
// Push all tags
print_log("# Pushing tags to remote");
exec_system('git push origin ' . $tag);
print_log("# Finished Release ! :)");