-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
675e2c8
commit 39fe366
Showing
2 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
/** | ||
* Get the list of DokuWiki versions from the download server | ||
* | ||
* @return array | ||
*/ | ||
function getVersions() | ||
{ | ||
$data = file_get_contents('https://download.dokuwiki.org/version'); | ||
return json_decode($data, true); | ||
} | ||
|
||
/** | ||
* Get the last commit of a branch | ||
* | ||
* @param string $branch | ||
* @return string | ||
*/ | ||
function getLastCommit($branch) | ||
{ | ||
$opts = [ | ||
'http' => [ | ||
'method' => "GET", | ||
'header' => join("\r\n", [ | ||
"Accept: application/vnd.github.v3+json", | ||
"User-Agent: PHP" | ||
]) | ||
] | ||
]; | ||
$context = stream_context_create($opts); | ||
|
||
$data = file_get_contents('https://api.github.com/repos/dokuwiki/dokuwiki/commits/' . $branch, false, $context); | ||
$json = json_decode($data, true); | ||
return $json['sha']; | ||
} | ||
|
||
/** | ||
* Get the image id of a given PHP image tag | ||
* | ||
* @param string $tag | ||
* @return string | ||
*/ | ||
function getImageId($tag) | ||
{ | ||
$repo = 'library/php'; | ||
$data = file_get_contents('https://auth.docker.io/token?service=registry.docker.io&scope=repository:' . $repo . ':pull'); | ||
$token = json_decode($data, true)['token']; | ||
|
||
|
||
$opts = [ | ||
'http' => [ | ||
'method' => "GET", | ||
'header' => join("\r\n", [ | ||
"Authorization: Bearer $token", | ||
"Accept: application/vnd.docker.distribution.manifest.v2+json", | ||
]) | ||
] | ||
]; | ||
$context = stream_context_create($opts); | ||
|
||
$data = file_get_contents('https://index.docker.io/v2/' . $repo . '/manifests/' . $tag, false, $context); | ||
$json = json_decode($data, true); | ||
return $json['config']['digest']; | ||
} | ||
|
||
/** | ||
* Get the image tag used in the current Dockerfile | ||
* | ||
* @return string | ||
*/ | ||
function getImageTag() | ||
{ | ||
$df = file_get_contents('Dockerfile'); | ||
preg_match('/FROM php:(?<tag>\S*)/', $df, $matches); | ||
return $matches['tag']; | ||
} | ||
|
||
|
||
$result = []; | ||
$self = $_ENV['GITHUB_SHA'] ?? 'unknown'; | ||
$upstreamTag = getImageTag(); | ||
$image = getImageId($upstreamTag); | ||
|
||
foreach (getVersions() as $release => $info) { | ||
$branch = $release === 'oldstable' ? 'old-stable' : $release; | ||
$commit = getLastCommit($branch); | ||
$ident = join('-', [$release, $commit, $image, $self]); | ||
$cache = '.github/matrix.cache/' . $release; | ||
|
||
fwrite(STDERR, "Ident: $ident\n"); | ||
$last = @file_get_contents($cache); | ||
if ($last === $ident) { | ||
// this combination has been built before | ||
fwrite(STDERR, "No change. Skipping $release\n"); | ||
continue; | ||
} | ||
|
||
// this branch needs to be built | ||
$result[] = [ | ||
'version' => $info['version'], | ||
'date' => $info['date'], | ||
'name' => $info['name'], | ||
'type' => $release, | ||
]; | ||
// update the cache | ||
if (!is_dir('.github/matrix.cache')) { | ||
mkdir('.github/matrix.cache'); | ||
} | ||
file_put_contents($cache, $ident); | ||
} | ||
|
||
// output the result | ||
if ($result) { | ||
echo "matrix=" . json_encode(['release' => $result]); | ||
} else { | ||
echo "matrix=[]"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Test Limit | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "23 0 * * *" | ||
push: | ||
branches: | ||
- limit | ||
|
||
jobs: | ||
buildmatrix: | ||
name: Create Build Matrix | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
- name: Cache Setup | ||
id: cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: .github/matrix.cache/ | ||
key: ${{ runner.os }}-matrix-${{ hashFiles('.github/matrix.php') }} | ||
- name: Set up matrix | ||
id: set-matrix | ||
run: | | ||
php .github/matrix.php >> $GITHUB_OUTPUT | ||
build: | ||
needs: buildmatrix | ||
name: Build Docker Image for ${{ matrix.release.type }} | ||
runs-on: ubuntu-latest | ||
if: ${{ needs.buildmatrix.outputs.matrix != '[]' }} | ||
strategy: | ||
matrix: ${{fromJson(needs.buildmatrix.outputs.matrix)}} | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
|
||
workflow-keepalive: | ||
if: github.event_name == 'schedule' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: write | ||
steps: | ||
- uses: liskin/gh-workflow-keepalive@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |