Skip to content

Commit c433da4

Browse files
committed
Add Nexus API deployment
1 parent 26040bf commit c433da4

File tree

8 files changed

+244
-0
lines changed

8 files changed

+244
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Deploy Nexus API
2+
3+
on:
4+
push:
5+
branches:
6+
- '1.x'
7+
paths:
8+
- src
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: pages
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-22.04
23+
if: github.repository == 'NexusPHP/framework'
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: '8.3'
33+
coverage: none
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Setup global variables
38+
id: globals
39+
run: |
40+
echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_OUTPUT
41+
42+
- name: Cache Composer dependencies
43+
uses: actions/cache@v4
44+
with:
45+
path: ${{ steps.globals.outputs.COMPOSER_CACHE_DIR }}
46+
key: ${{ github.workflow }}-PHP_8.3-${{ hashFiles('**/composer.json') }}
47+
restore-keys: |
48+
${{ github.workflow }}-PHP_8.3-
49+
50+
- name: Install dependencies
51+
run: |
52+
echo ::group::composer update --ansi
53+
composer update --ansi
54+
echo ::endgroup::
55+
56+
echo ::group::composer update --ansi --working-dir api
57+
composer update --ansi --working-dir api
58+
echo ::endgroup::
59+
60+
- name: Setup Pages
61+
id: pages
62+
uses: actions/configure-pages@v5
63+
64+
- name: Generate Nexus API
65+
run: api/vendor/bin/apigen src --ansi --output api/docs --title Nexus --config api/apigen.neon
66+
67+
- name: Upload pages artifact
68+
uses: actions/upload-pages-artifact@v3
69+
with:
70+
path: api/docs
71+
72+
deploy:
73+
environment:
74+
name: github-pages
75+
url: ${{ steps.deployment.outputs.page_url }}
76+
77+
runs-on: ubuntu-22.04
78+
needs: build
79+
80+
steps:
81+
- name: Deploy Nexus API
82+
id: deployment
83+
uses: actions/deploy-pages@v4

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
->files()
3030
->in([
3131
__DIR__.'/.github',
32+
__DIR__.'/api',
3233
__DIR__.'/bin',
3334
__DIR__.'/src',
3435
__DIR__.'/tests',

api/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/docs
2+
/vendor
3+
/composer.lock

api/apigen.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
title: Nexus
3+
4+
services:
5+
analyzer.filter:
6+
factory: Nexus\Api\AnalyserFilter
7+
arguments:
8+
excludeProtected: %excludeProtected%
9+
excludePrivate: %excludePrivate%
10+
excludeTagged: %excludeTagged%
11+
12+
renderer.filter:
13+
factory: Nexus\Api\RendererFilter

api/composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"require": {
3+
"php": "^8.3",
4+
"apigen/apigen": "dev-master"
5+
},
6+
"autoload": {
7+
"psr-4": {
8+
"Nexus\\Api\\": "src/"
9+
}
10+
}
11+
}

api/src/AnalyserFilter.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Nexus framework.
7+
*
8+
* (c) John Paul E. Balandan, CPA <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Nexus\Api;
15+
16+
use ApiGen\Analyzer\Filter;
17+
use ApiGen\Info\ClassLikeInfo;
18+
use ApiGen\Info\MemberInfo;
19+
use PhpParser\Node;
20+
21+
final class AnalyserFilter extends Filter
22+
{
23+
public function filterClassLikeNode(Node\Stmt\ClassLike $node): bool
24+
{
25+
$name = $node->namespacedName?->toString();
26+
27+
if (null === $name) {
28+
return false;
29+
}
30+
31+
return str_starts_with($name, 'Nexus\\');
32+
}
33+
34+
public function filterFunctionNode(Node\Stmt\Function_ $node): bool
35+
{
36+
$name = $node->namespacedName?->toString();
37+
38+
if (null === $name) {
39+
return false;
40+
}
41+
42+
return str_starts_with($name, 'Nexus\\');
43+
}
44+
45+
public function filterMemberInfo(ClassLikeInfo $classLike, MemberInfo $member): bool
46+
{
47+
$name = $classLike->name->full;
48+
49+
return str_starts_with($name, 'Nexus\\');
50+
}
51+
}

api/src/RendererFilter.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Nexus framework.
7+
*
8+
* (c) John Paul E. Balandan, CPA <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Nexus\Api;
15+
16+
use ApiGen\Index\NamespaceIndex;
17+
use ApiGen\Info\ClassLikeInfo;
18+
use ApiGen\Renderer\Filter;
19+
20+
final class RendererFilter extends Filter
21+
{
22+
public function filterNamespacePage(NamespaceIndex $namespace): bool
23+
{
24+
foreach ($namespace->children as $child) {
25+
if ($this->filterNamespacePage($child)) {
26+
return true;
27+
}
28+
}
29+
30+
foreach ($namespace->class as $class) {
31+
if ($this->filterClassLikePage($class)) {
32+
return true;
33+
}
34+
}
35+
36+
foreach ($namespace->interface as $interface) {
37+
if ($this->filterClassLikePage($interface)) {
38+
return true;
39+
}
40+
}
41+
42+
foreach ($namespace->trait as $trait) {
43+
if ($this->filterClassLikePage($trait)) {
44+
return true;
45+
}
46+
}
47+
48+
foreach ($namespace->enum as $enum) {
49+
if ($this->filterClassLikePage($enum)) {
50+
return true;
51+
}
52+
}
53+
54+
foreach ($namespace->exception as $exception) {
55+
if ($this->filterClassLikePage($exception)) {
56+
return true;
57+
}
58+
}
59+
60+
foreach ($namespace->function as $function) {
61+
if ($this->filterFunctionPage($function)) {
62+
return true;
63+
}
64+
}
65+
66+
return false;
67+
}
68+
69+
public function filterClassLikePage(ClassLikeInfo $classLike): bool
70+
{
71+
return $this->isClassRendered($classLike);
72+
}
73+
74+
private function isClassRendered(ClassLikeInfo $classLike): bool
75+
{
76+
$name = $classLike->name->full;
77+
78+
return str_starts_with($name, 'Nexus\\');
79+
}
80+
}

phpstan.dist.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ parameters:
99
tmpDir: build/phpstan
1010
paths:
1111
- .github
12+
- api
1213
- bin
1314
- src
1415
- tests
@@ -18,6 +19,7 @@ parameters:
1819
- tests/**/data/**
1920
- tests/PHPStan/**/data/**
2021
analyse:
22+
- api/vendor/**
2123
- tools/vendor/**
2224
bootstrapFiles:
2325
- vendor/autoload.php

0 commit comments

Comments
 (0)