forked from Automattic/vip-go-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latest-release.php
executable file
·68 lines (49 loc) · 1.34 KB
/
latest-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
#!/usr/bin/php
<?php
/**
* Look for the latest release of vip-go-ci
* on GitHub, and output the release-number
* to STDOUT. In the process, do sanity-checking.
*
* @package Automattic/vip-go-ci
*/
declare(strict_types=1);
$github_url = 'https://api.github.com/repos/automattic/vip-go-ci/releases';
$client_id = 'automattic-vip-go-ci-release-checker';
$github_api_version = 'X-GitHub-Api-Version: 2022-11-28'; // If updated, update defines.php too.
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $github_url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $ch, CURLOPT_USERAGENT, $client_id );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $github_api_version ) );
$resp_data_raw = curl_exec( $ch );
/*
* If cURL fails, abort.
*/
if ( false === $resp_data_raw ) {
exit( 255 );
}
$resp_data = json_decode(
$resp_data_raw
);
unset( $resp_data_raw );
/*
* If JSON-decode fails, abort
*/
if ( null === $resp_data ) {
exit( 255 );
}
/*
* Sanity-check: Is version defined and
* is it a number?
*/
if (
( ! isset( $resp_data[0]->tag_name ) ) ||
( ! preg_match( '/^(\d+\.)?(\d+\.)?(\*|\d+)$/', $resp_data[0]->tag_name ) )
) {
exit( 255 );
}
echo $resp_data[0]->tag_name;