This repository has been archived by the owner on Apr 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
build-projects.php
108 lines (86 loc) · 3.66 KB
/
build-projects.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
<?php
/**
* Fetches the projects.yml from the main directory and builds
* a projects.yml with populated information for the pages/source
* directory
*/
use Symfony\Component\Yaml\Yaml;
require_once __DIR__ . "/../vendor/autoload.php";
$file = __DIR__ . "/../projects.yml";
$projects = Yaml::parse($file);
if (!file_exists(__DIR__ . '/../github-token.json')) {
echo "Missing github-token.json!";
exit(1);
}
$tokenData = json_decode(file_get_contents(__DIR__ . '/../github-token.json'), true);
$token = $tokenData['token'];
if (!is_string($token)) {
echo "Invalid github-token.json provided";
exit(1);
}
foreach ($projects as $projectName => $projectData) {
$ch = curl_init("https://api.github.com/repos/doctrine/" . $projectData['repository'] . "/tags");
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token $token"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$tagData = json_decode($response, true);
if ( ! $tagData) {
continue;
}
// Fix versions starting with "v", such as "v1.2.5"
foreach ($tagData as $key => $tag) {
$tagData[$key]['name'] = str_replace('v', '', $tag['name']);
}
usort($tagData, function($a, $b) {
return version_compare($a['name'], $b['name']);
});
foreach ($projectData['versions'] as $version => $versionData) {
// default 'downloadable' to true
if ( !isset($projects[$projectName]['versions'][$version]['downloadable'])) {
$projects[$projectName]['versions'][$version]['downloadable'] = true;
}
$projects[$projectName]['versions'][$version]['releases'] = array();
foreach ($tagData as $tag) {
if (strpos($tag['name'], $version) === 0) {
$release = array(
'package_name' => sprintf($projectData['file'], $projectData['package'], $tag['name']),
'git_checkout_command' => '$ git clone git://github.com/doctrine/' . $projectData['repository'] . '.git ' . $projectData['slug'] . '<br>$ cd ' . $projectData['slug'] . '<br>$ git checkout ' . $tag['name'],
'pear_install_command' => '$ pear channel-discover pear.doctrine-project.org<br>pear install doctrine/' . $projectData['package'].'-' . $tag['name'],
'composer' => !isset($versionData['composer']) || (isset($version['composer']) && $version['composer']),
);
$projects[$projectName]['versions'][$version]['releases'][$tag['name']] = $release;
}
}
}
}
file_put_contents(__DIR__ . "/../site/projects.yml", Yaml::dump($projects, 8, 2));
/**
* Given a package and tag name "tests" how the build file is called
* using HEAD requests.
*
* Not necessary at the moment
*/
function get_package_name($package, $tag)
{
$downloadDir = "http://www.doctrine-project.org/downloads/";
$fileNames = array(
$package . "-" . $tag . "-full.tar.gz",
$package . "-" . strtolower($tag) . "-full.tar.gz",
$package . "-" . $tag . ".tgz"
);
$packageName = null;
$ch = curl_init();
foreach ($fileNames as $fileName) {
curl_setopt($ch, CURLOPT_URL, $downloadDir . "/" . $fileName);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code == 200) {
$packageName = $fileName;
break;
}
}
}