Skip to content

Commit

Permalink
Add Nexus API deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 19, 2024
1 parent 26040bf commit c56731d
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.* export-ignore
/api/ export-ignore
/bin/ export-ignore
/infection.json5 export-ignore
/phpstan-baseline.php
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/deploy-nexus-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Deploy Nexus API

on:
push:
branches:
- '1.x'
paths:
- src
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-22.04
if: github.repository == 'NexusPHP/framework'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup global variables
id: globals
run: |
echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.globals.outputs.COMPOSER_CACHE_DIR }}
key: ${{ github.workflow }}-PHP_8.3-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ github.workflow }}-PHP_8.3-
- name: Install dependencies
run: |
echo ::group::composer update --ansi
composer update --ansi
echo ::endgroup::
echo ::group::composer update --ansi --working-dir api
composer update --ansi --working-dir api
echo ::endgroup::
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5

- name: Generate Nexus API
run: api/vendor/bin/apigen src --ansi --output api/docs --title Nexus --config api/apigen.neon

- name: Upload pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: api/docs

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-22.04
needs: build

steps:
- name: Deploy Nexus API
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
->files()
->in([
__DIR__.'/.github',
__DIR__.'/api',
__DIR__.'/bin',
__DIR__.'/src',
__DIR__.'/tests',
Expand Down
3 changes: 3 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/docs
/vendor
/composer.lock
13 changes: 13 additions & 0 deletions api/apigen.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
title: Nexus

services:
analyzer.filter:
factory: Nexus\Api\AnalyserFilter
arguments:
excludeProtected: %excludeProtected%
excludePrivate: %excludePrivate%
excludeTagged: %excludeTagged%

renderer.filter:
factory: Nexus\Api\RendererFilter
11 changes: 11 additions & 0 deletions api/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": {
"php": "^8.3",
"apigen/apigen": "dev-master"
},
"autoload": {
"psr-4": {
"Nexus\\Api\\": "src/"
}
}
}
51 changes: 51 additions & 0 deletions api/src/AnalyserFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Nexus framework.
*
* (c) John Paul E. Balandan, CPA <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Nexus\Api;

use ApiGen\Analyzer\Filter;
use ApiGen\Info\ClassLikeInfo;
use ApiGen\Info\MemberInfo;
use PhpParser\Node;

final class AnalyserFilter extends Filter
{
public function filterClassLikeNode(Node\Stmt\ClassLike $node): bool
{
$name = $node->namespacedName?->toString();

if (null === $name) {
return false;
}

return str_starts_with($name, 'Nexus\\');
}

public function filterFunctionNode(Node\Stmt\Function_ $node): bool
{
$name = $node->namespacedName?->toString();

if (null === $name) {
return false;
}

return str_starts_with($name, 'Nexus\\');
}

public function filterMemberInfo(ClassLikeInfo $classLike, MemberInfo $member): bool
{
$name = $classLike->name->full;

return str_starts_with($name, 'Nexus\\');
}
}
80 changes: 80 additions & 0 deletions api/src/RendererFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Nexus framework.
*
* (c) John Paul E. Balandan, CPA <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Nexus\Api;

use ApiGen\Index\NamespaceIndex;
use ApiGen\Info\ClassLikeInfo;
use ApiGen\Renderer\Filter;

final class RendererFilter extends Filter
{
public function filterNamespacePage(NamespaceIndex $namespace): bool
{
foreach ($namespace->children as $child) {
if ($this->filterNamespacePage($child)) {
return true;
}
}

foreach ($namespace->class as $class) {
if ($this->filterClassLikePage($class)) {
return true;
}
}

foreach ($namespace->interface as $interface) {
if ($this->filterClassLikePage($interface)) {
return true;
}
}

foreach ($namespace->trait as $trait) {
if ($this->filterClassLikePage($trait)) {
return true;
}
}

foreach ($namespace->enum as $enum) {
if ($this->filterClassLikePage($enum)) {
return true;
}
}

foreach ($namespace->exception as $exception) {
if ($this->filterClassLikePage($exception)) {
return true;
}
}

foreach ($namespace->function as $function) {
if ($this->filterFunctionPage($function)) {
return true;
}
}

return false;
}

public function filterClassLikePage(ClassLikeInfo $classLike): bool
{
return $this->isClassRendered($classLike);
}

private function isClassRendered(ClassLikeInfo $classLike): bool
{
$name = $classLike->name->full;

return str_starts_with($name, 'Nexus\\');
}
}

0 comments on commit c56731d

Please sign in to comment.