-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_api_clients.php
executable file
·150 lines (131 loc) · 6.73 KB
/
publish_api_clients.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
$gitComment = "";
$workingDirectory = "/Users/lachlan/Desktop/ChronoSheetsClients/WorkingDirectory/";
$chronosheetsApiJsonUrl = "https://www.chronosheets.com/swagger/docs/v1";
$gitHubUserName = "ChronoSheets";
$swaggerLibTypes = [
"csharp",
"android",
"java",
"javascript",
"php",
"python",
"ruby",
"swift4",
"typescript-angular"
];
$gitHubRepoNames = [
"ChronoSheets-CSharp-Client",
"ChronoSheets-Android-Client",
"ChronoSheets-Java-Client",
"ChronoSheets-Javascript-Client",
"ChronoSheets-PHP-Client",
"ChronoSheets-Python-Client",
"ChronoSheets-Ruby-Client",
"ChronoSheets-Swift4-Client",
"ChronoSheets-Angular-Client"
];
$libCommonNames = [
"CSharp",
"Android",
"Java",
"Javascript",
"PHP",
"Python",
"Ruby",
"Swift4",
"TypeScriptAngular"
];
$subfolders = [
"",
"",
"",
"",
"ChronoSheetsAPI",
"",
"",
"",
""
];
echo "Starting generation\r\n";
exec("chmod -R ugo+w ".$workingDirectory."*");
exec("rm -rf ".$workingDirectory."_Archived/*");
foreach($swaggerLibTypes as $key => $value)
{
echo "Start generating '".$value."' library\r\n";
echo "Cleaning...\r\n";
$filesToDelete = new DirectoryIterator($workingDirectory.$gitHubRepoNames[$key]);
if($subfolders[$key] != ""){
$filesToDelete = new DirectoryIterator($workingDirectory.$gitHubRepoNames[$key]."/".$subfolders[$key]);
}
foreach ($filesToDelete as $fileInfo) {
$name = $fileInfo->getFilename();
if ($name != ".git" && $name != ".gitignore" && $name != "." && $name != "..")
{
if($subfolders[$key] != ""){
exec("rm -rf ".$workingDirectory.$gitHubRepoNames[$key]."/".$subfolders[$key]."/".$name);
}else{
exec("rm -rf ".$workingDirectory.$gitHubRepoNames[$key]."/".$name);
}
}
}
echo "Generating api client files...\r\n";
exec("swagger-codegen generate -i ".$chronosheetsApiJsonUrl." -l ".$value." -o ".$workingDirectory.$gitHubRepoNames[$key]."/ -c configs/config-".$value.".json --model-name-prefix CS");
echo "Setting permissions on git push script\r\n";
if($subfolders[$key] != ""){
exec("chmod u+x ".$workingDirectory.$gitHubRepoNames[$key]."/".$subfolders[$key]."/git_push.sh");
}else{
exec("chmod u+x ".$workingDirectory.$gitHubRepoNames[$key]."/git_push.sh");
}
echo "Pusing to git...\r\n";
if($subfolders[$key] != ""){
$scriptFileName = $workingDirectory.$gitHubRepoNames[$key]."/".$subfolders[$key]."/git_push.sh";
$contents = file_get_contents($scriptFileName);
$contents = str_replace("git pull origin master", "git pull origin master --allow-unrelated-histories", $contents);
file_put_contents($scriptFileName, $contents);
exec("cd ".$workingDirectory.$gitHubRepoNames[$key]."/".$subfolders[$key]."; ".$scriptFileName." ChronoSheets ".$gitHubRepoNames[$key]." \"".$gitComment."\"; cd ../../../");
}else{
$scriptFileName = $workingDirectory.$gitHubRepoNames[$key]."/git_push.sh";
$contents = file_get_contents($scriptFileName);
$contents = str_replace("git pull origin master", "git pull origin master --allow-unrelated-histories", $contents);
file_put_contents($scriptFileName, $contents);
exec("cd ".$workingDirectory.$gitHubRepoNames[$key]."; ".$scriptFileName." ChronoSheets ".$gitHubRepoNames[$key]." \"".$gitComment."\"; cd ../../");
}
echo "Creating ZIP archives...\r\n";
$zipFile = new ZipArchive();
$zipFile->open($workingDirectory."_Archived/".$libCommonNames[$key].".zip",ZipArchive::CREATE|ZipArchive::OVERWRITE);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($workingDirectory.$gitHubRepoNames[$key]), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
$relPath = str_replace($workingDirectory.$gitHubRepoNames[$key], "", $name);
if(
substr( $relPath, 0, 5 ) !== "/.git" &&
substr( $relPath, 0, 11 ) !== "/.gitignore" &&
substr( $relPath, 0, 17 ) !== "/.swagger-codegen" &&
substr( $relPath, 0, 24 ) !== "/.swagger-codegen-ignore" &&
$relPath !== "/." &&
$relPath !== "/..."
)
{
$bSkip = false;
if($subfolders[$key] != ""){
$subfolderLen = strlen($subfolders[$key]);
if(substr($relPath, 0, $subfolderLen + 6) === "/".$subfolders[$key]."/.git"){ $bSkip = true; }
if(substr($relPath, 0, $subfolderLen + 12) === "/".$subfolders[$key]."/.gitignore"){ $bSkip = true; }
if(substr($relPath, 0, $subfolderLen + 18) === "/".$subfolders[$key]."/.swagger-codegen"){ $bSkip = true; }
if(substr($relPath, 0, $subfolderLen + 25) === "/".$subfolders[$key]."/.swagger-codegen-ignore"){ $bSkip = true; }
}
if(!$bSkip){
if(is_dir($name)){
//$zipFile->addEmptyDir(ltrim($relPath));
}else{
//$name = substr($name, 1, strlen($name));
$zipFile->addFile($name, ltrim($relPath, '/'));
}
}
}
}
$zipFile->close();
echo "Uploading to S3 cloud...\r\n";
exec("aws s3 cp ".$workingDirectory."_Archived/".$libCommonNames[$key].".zip"." s3://chronoapiclients/v1/".$libCommonNames[$key].".zip --acl public-read");
}
?>