This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdocversions.php
56 lines (47 loc) · 1.53 KB
/
docversions.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
<?php
require('./vendor/autoload.php');
use Aws\S3\S3Client;
const IGNORE_VERSIONS = ['master', 'develop'];
$key = getenv('ARTIFACTS_KEY');
$secret = getenv('ARTIFACTS_SECRET');
$docsBucket = getenv('ARTIFACTS_BUCKET');
$objectPrefix = getenv('TRAVIS_REPO_SLUG');
$projectName = str_replace('serato/', '', $objectPrefix);
$versions = [];
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => $key,
'secret' => $secret,
]
]);
$result = $s3->listObjects([
'Bucket' => $docsBucket,
'Prefix' => $objectPrefix
]);
if (isset($result['Contents'])) {
foreach ($result['Contents'] as $object) {
$version = substr(
str_replace($objectPrefix . '/', '', $object['Key']),
0,
strpos(str_replace($objectPrefix . '/', '', $object['Key']), '/')
);
if (!in_array($version, IGNORE_VERSIONS) && !in_array($version, $versions)) {
$versions[] = $version;
}
}
}
if (count($versions) > 0) {
arsort($versions);
$result = $s3->putObject([
'Bucket' => $docsBucket,
'Key' => 'js/' . $projectName . '.json',
'Body' => json_encode($versions)
]);
echo "Versioned documentation links generateed for $docsBucket/$objectPrefix " .
"for the following versions: " . json_encode($versions) . "\n";
return true;
}
echo "No project versions found at s3://$docsBucket/$objectPrefix\n";
return false;