This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
generated from spaceonfire/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from spaceonfire/github-actions
Github Actions
- Loading branch information
Showing
6 changed files
with
246 additions
and
55 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
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,112 @@ | ||
name: Build Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
composer: | ||
runs-on: ubuntu-latest | ||
container: spaceonfire/nginx-php-fpm:latest-7.2 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Validate composer.json | ||
run: composer validate | ||
|
||
codestyle: | ||
runs-on: ubuntu-latest | ||
container: spaceonfire/nginx-php-fpm:latest-7.2 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
env: | ||
COMPOSER_CACHE_KEY: 'composer-7.2' | ||
with: | ||
path: vendor | ||
key: ${{ env.COMPOSER_CACHE_KEY }} | ||
restore-keys: ${{ env.COMPOSER_CACHE_KEY }} | ||
|
||
- name: Install dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Check coding standard | ||
run: vendor/bin/ecs check --no-progress-bar --no-interaction | ||
|
||
phpstan: | ||
runs-on: ubuntu-latest | ||
container: spaceonfire/nginx-php-fpm:latest-7.2 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
env: | ||
COMPOSER_CACHE_KEY: 'composer-7.2' | ||
with: | ||
path: vendor | ||
key: ${{ env.COMPOSER_CACHE_KEY }} | ||
restore-keys: ${{ env.COMPOSER_CACHE_KEY }} | ||
|
||
- name: Install dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: PHPStan | ||
run: vendor/bin/phpstan analyse --no-progress --no-interaction | ||
|
||
phpunit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-version: | ||
- '7.2' | ||
- '7.3' | ||
- '7.4' | ||
container: spaceonfire/nginx-php-fpm:latest-${{ matrix.php-version }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
env: | ||
COMPOSER_CACHE_KEY: 'composer-${{ matrix.php-version }}' | ||
with: | ||
path: vendor | ||
key: ${{ env.COMPOSER_CACHE_KEY }} | ||
restore-keys: ${{ env.COMPOSER_CACHE_KEY }} | ||
|
||
- name: Install dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: PHPUnit | ||
run: | | ||
apk update | ||
docker-php-ext-enable xdebug | ||
vendor/bin/phpunit --no-interaction | ||
cat build/coverage.txt | ||
- name: PHPUnit Artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: phpunit-${{ matrix.php-version }} | ||
path: build/ | ||
|
||
- name: Generate coverage badge | ||
if: matrix.php-version == '7.2' && github.event_name == 'push' && github.ref == 'refs/heads/master' | ||
run: php bin/coverage-badge ${{ github.repository }}.json ${{ secrets.COVERAGE_GIST_ID }} ${{ secrets.COVERAGE_GIST_TOKEN }} |
This file was deleted.
Oops, something went wrong.
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
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,129 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/* | ||
* php bin/coverage-badge <filename> <gist-id> <gist-token> | ||
*/ | ||
|
||
try { | ||
$arguments = $argv; | ||
array_shift($arguments); | ||
|
||
[$filename, $gistId, $gistToken] = $arguments + [null, null, null]; | ||
|
||
if ($filename === null) { | ||
throw new InvalidArgumentException('Badge filename not specified'); | ||
} | ||
if ($gistId === null) { | ||
throw new InvalidArgumentException('Gist id not specified'); | ||
} | ||
if ($gistToken === null) { | ||
throw new InvalidArgumentException('Gist token not specified'); | ||
} | ||
|
||
$filename = str_replace(['/', '_'], '-', $filename); | ||
|
||
$coverageFile = dirname(__DIR__) . '/build/coverage.txt'; | ||
|
||
if (!file_exists($coverageFile)) { | ||
throw new RuntimeException(sprintf('Text coverage report not found at %s', $coverageFile)); | ||
} | ||
|
||
$coverageFileContents = file_get_contents($coverageFile); | ||
|
||
preg_match('/^\s+Lines:\s+(\d+\.\d+)\%/m', $coverageFileContents, $matches); | ||
|
||
if (isset($matches[1]) && is_numeric($matches[1])) { | ||
$coverage = (float)$matches[1]; | ||
|
||
/** @noinspection TypeUnsafeComparisonInspection */ | ||
$message = sprintf( | ||
'%s%%', | ||
(string)$coverage == (int)$coverage | ||
? (string)(int)$coverage | ||
: number_format($coverage, 1) | ||
); | ||
|
||
$color = 'red'; | ||
|
||
if ($coverage >= 30) { | ||
$color = 'orange'; | ||
} | ||
if ($coverage >= 50) { | ||
$color = 'yellow'; | ||
} | ||
if ($coverage >= 65) { | ||
$color = 'yellowgreen'; | ||
} | ||
if ($coverage >= 80) { | ||
$color = 'green'; | ||
} | ||
if ($coverage >= 95) { | ||
$color = 'brightgreen'; | ||
} | ||
} else { | ||
$message = 'N/A'; | ||
$color = 'lightgrey'; | ||
} | ||
|
||
$badgeInfo = [ | ||
'schemaVersion' => 1, | ||
'label' => 'coverage', | ||
'message' => $message, | ||
'color' => $color, | ||
]; | ||
|
||
$postFields = json_encode([ | ||
'files' => [ | ||
$filename => [ | ||
'content' => json_encode($badgeInfo), | ||
], | ||
], | ||
]); | ||
|
||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => sprintf('https://api.github.com/gists/%s', $gistId), | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => '', | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 30, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => 'PATCH', | ||
CURLOPT_POSTFIELDS => $postFields, | ||
CURLOPT_HTTPHEADER => [ | ||
'accept: application/vnd.github.v3+json', | ||
sprintf('authorization: Bearer %s', $gistToken), | ||
'content-type: application/json', | ||
'user-agent: curl', | ||
], | ||
]); | ||
|
||
$response = curl_exec($curl); | ||
$json = json_decode($response, true); | ||
$err = curl_error($curl); | ||
$httpCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); | ||
|
||
curl_close($curl); | ||
|
||
if ($err) { | ||
throw new RuntimeException(sprintf('Curl error: %s', $err)); | ||
} | ||
|
||
if ($httpCode > 399) { | ||
$exceptionMessage = sprintf('Request error: %s', $json['message'] ?? $response); | ||
|
||
if (isset($json['errors'])) { | ||
$exceptionMessage .= PHP_EOL . PHP_EOL . 'Errors: ' . json_encode($json['errors'], JSON_PRETTY_PRINT); | ||
} | ||
|
||
throw new RuntimeException($exceptionMessage); | ||
} | ||
|
||
echo 'Coverage badge info uploaded' . PHP_EOL; | ||
exit(0); | ||
} catch (Throwable $e) { | ||
fwrite(STDERR, $e->getMessage() . PHP_EOL); | ||
exit(1); | ||
} |
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