11<?php
22require_once 'server-block.php ' ;
3-
4- /**
5- * Get the GitHub API headers with optional authentication
6- */
7- function get_github_headers (): string {
8- $ headers = 'User-Agent: Nextcloud Documentation Builder ' ;
9- if ($ token = getenv ('GITHUB_TOKEN ' )) {
10- $ headers .= "\r\nAuthorization: token $ token " ;
11- }
12- return $ headers ;
13- }
14-
15- /**
16- * Get the repository name for a given version
17- * Nextcloud moved to nextcloud-releases/server starting with version 32
18- */
19- function get_repo_for_version (int $ version ): string {
20- return $ version >= 32 ? 'nextcloud-releases/server ' : 'nextcloud/server ' ;
21- }
22-
23- /**
24- * Parse the HTTP status code from the response headers populated by file_get_contents.
25- *
26- * @param array $headers The $http_response_header array
27- */
28- function parse_http_status (array $ headers ): int {
29- preg_match ('/HTTP\/[\d.]+ (\d+)/ ' , $ headers [0 ] ?? '' , $ matches );
30- return (int )($ matches [1 ] ?? 0 );
31- }
32-
33- /**
34- * Fetch release info for a given version from the GitHub API.
35- *
36- * Returns an array ['date' => int] if the release exists (HTTP 200).
37- * Returns null if the release does not exist (HTTP 404).
38- * Exits with code 1 on any other HTTP status (rate limit, server error, etc.)
39- * to prevent silently generating empty or incorrect index sections.
40- */
41- function fetch_release_info (int $ version ): ?array {
42- $ repo = get_repo_for_version ($ version );
43- $ url = sprintf ('https://api.github.com/repos/%s/releases/tags/v%d.0.0 ' , $ repo , $ version );
44-
45- $ context = stream_context_create ([
46- 'http ' => [
47- 'header ' => get_github_headers (),
48- 'timeout ' => 10 ,
49- 'ignore_errors ' => true
50- ]
51- ]);
52-
53- $ response = @file_get_contents ($ url , false , $ context );
54-
55- // FIXME: function_exists conditional can be dropped once we don't need to support <8.4.0
56- if (function_exists ('http_get_last_response_headers ' )) {
57- /** @var array|null */
58- $ http_response_header = \http_get_last_response_headers ();
59- }
60-
61- $ status = isset ($ http_response_header ) && is_array ($ http_response_header )
62- ? parse_http_status ($ http_response_header )
63- : 0 ;
64-
65- if ($ status === 200 ) {
66- $ data = json_decode ($ response , true );
67- $ publishedAt = $ data ['published_at ' ] ?? $ data ['created_at ' ] ?? null ;
68- return ['date ' => $ publishedAt ? strtotime ($ publishedAt ) : time ()];
69- }
70-
71- if ($ status === 404 ) {
72- return null ;
73- }
74-
75- // Any non-200/non-404 response (403 rate limit, 429, 5xx, network failure)
76- // must abort so we never deploy an index with empty or wrong sections.
77- fwrite (STDERR , "GitHub API error (HTTP $ status) checking v $ version.0.0 — aborting to avoid deploying incorrect index \n" );
78- exit (1 );
79- }
3+ require_once 'detect-versions.php ' ;
804
815// Parse and validate command-line arguments
826/** @var int[] */
@@ -90,47 +14,16 @@ function fetch_release_info(int $version): ?array {
9014 exit (1 );
9115}
9216
93- // Fetch release information from GitHub
94- $ released_branches = [];
95- $ oneYearAgo = time () - (365 * 24 * 60 * 60 );
96- $ foundOutOfSupport = null ;
97-
98- foreach ($ branches as $ branch ) {
99- if ($ foundOutOfSupport !== null ) {
100- fwrite (STDOUT , "🛑 Version $ branch is unsupported (older than version $ foundOutOfSupport) \n" );
101- $ released_branches [$ branch ] = $ releaseTime ;
102- $ releaseType = $ releaseTime >= $ oneYearAgo ? 'stable ' : 'unsupported ' ;
103- continue ;
104- }
105-
106- $ info = fetch_release_info ($ branch );
107- if ($ info === null ) {
108- fwrite (STDERR , "⏳ Version $ branch is not released (tag v $ branch.0.0 not found) \n" );
109- continue ;
110- }
111-
112- $ releaseTime = $ info ['date ' ];
113- $ released_branches [$ branch ] = $ releaseTime ;
114- if ($ releaseTime < $ oneYearAgo ) {
115- fwrite (STDOUT , "🛑 Version $ branch is unsupported (released on " . date ('Y-m-d ' , $ releaseTime ) . ") \n" );
116- $ foundOutOfSupport = $ branch ;
117- } else {
118- fwrite (STDOUT , "✅ Version $ branch is supported (released on " . date ('Y-m-d ' , $ releaseTime ) . ") \n" );
119- }
120- }
121-
122- // Determine development version
123- if (isset ($ released_branches [$ branches [0 ]])) {
124- $ devVersion = $ branches [0 ] + 1 ;
125- $ devStatus = 'development ' ;
126- } else {
127- $ devVersion = $ branches [0 ];
128- $ devStatus = 'upcoming ' ;
129- }
17+ // Detect version metadata (API calls happen here)
18+ $ versions = detect_versions ($ branches );
19+ $ released_branches = $ versions ['released ' ];
20+ $ devVersion = $ versions ['dev_version ' ];
21+ $ devStatus = isset ($ released_branches [$ branches [0 ]]) ? 'development ' : 'upcoming ' ;
13022
13123fwrite (STDERR , "➡️ Version $ devVersion ( $ devStatus) \n" );
13224
13325// Collect released stable versions within support window
26+ $ oneYearAgo = time () - (365 * 24 * 60 * 60 );
13427$ stableVersions = [];
13528foreach ($ branches as $ branch ) {
13629 if (isset ($ released_branches [$ branch ]) && $ released_branches [$ branch ] >= $ oneYearAgo ) {
0 commit comments