Skip to content

Commit 8988a37

Browse files
committed
Pull support information from endoflife.date
1 parent d6da9f8 commit 8988a37

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Provides API endpoints for support information for PHP major/minor versions and releases 5.6 and later.
66

77

8-
This is a Laravel-based application that leverages the GitHub Repositories API to stream release tags from the `php/php-src` repo. We are then parsing out old and irrelevant tags (ex: alpha, beta and release candidates) and storing them along with support dates.
8+
This is a Laravel-based application that leverages the GitHub Repositories API to stream release tags from the `php/php-src` repo. We are then parsing out old and irrelevant tags (ex: alpha, beta and release candidates) and storing them along with support dates from [endoflife.date](https://endoflife.date/).
99

1010
The following endpoints are currently available, along with the optional `/versions` route alias:
1111
- GET `/releases`: Returns all PHP releases 5.6+.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Actions;
4+
5+
use Illuminate\Support\Collection;
6+
use Illuminate\Support\Facades\Http;
7+
8+
class FetchEolDatesFromEndOfLifeDate
9+
{
10+
public function __invoke(): Collection
11+
{
12+
return cache()->remember('endoflife::php', HOUR_IN_SECONDS, function () {
13+
$response = Http::get('https://endoflife.date/api/php.json');
14+
15+
if (! $response->ok()) {
16+
abort($response->status(), 'Error fetching EOL data from endoflife.date');
17+
}
18+
19+
return collect($response->json())->keyBy('cycle');
20+
});
21+
}
22+
}

app/Console/Commands/SyncPhpReleases.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Actions\FetchEolDatesFromEndOfLifeDate;
56
use App\Actions\FetchReleasesFromGitHub;
67
use App\Models\Release;
78
use Carbon\Carbon;
@@ -21,6 +22,7 @@ public function handle(): int
2122
{
2223
Log::info('Syncing PHP Releases');
2324

25+
$eolDates = $this->fetchEolDates();
2426
$releases = $this->filterToUsefulReleases($this->fetchReleasesFromGitHub());
2527

2628
// Map into arrays containing major, minor, and release numbers
@@ -39,35 +41,36 @@ public function handle(): int
3941
'minor' => $pieces[1],
4042
'release' => $pieces[2],
4143
'tagged_at' => Carbon::parse($tagDate),
42-
'released_at' => Carbon::parse($tagDate)->addDays(2),
43-
'active_support_until' => Carbon::parse($tagDate)->addDays(2)->addYears(2),
44-
'security_support_until' => Carbon::parse($tagDate)->addDays(2)->addYears(3),
4544
];
4645
});
4746

48-
$releases->each(function ($item) use ($releases) {
49-
// fetch the initial release of the minor version so we access the support dates
50-
$initialRelease = $releases
51-
->where('major', $item['major'])
52-
->where('minor', $item['minor'])
53-
->where('release', 0)
54-
->firstOrFail();
47+
$releases->each(function ($item) use ($releases, $eolDates) {
48+
$cycle = "{$item['major']}.{$item['minor']}";
49+
$eol = $eolDates->get($cycle);
5550

56-
$release = Release::firstOrCreate(
51+
if (! $eol) {
52+
$this->warn("No EOL data found for PHP {$cycle}, skipping {$cycle}.{$item['release']}");
53+
54+
return;
55+
}
56+
57+
$release = Release::updateOrCreate(
5758
[
5859
'major' => $item['major'],
5960
'minor' => $item['minor'],
6061
'release' => $item['release'],
6162
],
6263
[
6364
'tagged_at' => $item['tagged_at'],
64-
'active_support_until' => $initialRelease['active_support_until'],
65-
'security_support_until' => $initialRelease['security_support_until'],
65+
'active_support_until' => Carbon::parse($eol['support']),
66+
'security_support_until' => Carbon::parse($eol['eol']),
6667
]
6768
);
6869

6970
if ($release->wasRecentlyCreated) {
7071
$this->info('Created PHP release ' . $release);
72+
} elseif ($release->wasChanged()) {
73+
$this->info('Updated PHP release ' . $release);
7174
}
7275

7376
return $release;
@@ -78,6 +81,11 @@ public function handle(): int
7881
return self::SUCCESS;
7982
}
8083

84+
private function fetchEolDates()
85+
{
86+
return (new FetchEolDatesFromEndOfLifeDate)();
87+
}
88+
8189
private function fetchReleasesFromGitHub()
8290
{
8391
return (new FetchReleasesFromGitHub)();

resources/views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@section('content')
44

55
<p class="mt-4 text-gray-500">This is a Laravel-based application that leverages the GitHub Repositories API to stream release tags from the
6-
<a class="text-indigo-700 hover:text-indigo-900 underline" href="https://github.com/php/php-src">php/php-src</a> repo.
6+
<a class="text-indigo-700 hover:text-indigo-900 underline" href="https://github.com/php/php-src">php/php-src</a> repo, and <a class="text-indigo-700 hover:text-indigo-900 underline" href="https://endoflife.date/">endoflife.date</a> to store support info.
77
</p>
88

99
<p class="mt-4 text-gray-500">This project is heavily inspired by <a class="text-indigo-700 hover:text-indigo-900 underline" href="https://laravelversions.com/">LaravelVersions</a>.</p>

0 commit comments

Comments
 (0)