Skip to content

Commit

Permalink
Implement Deptrac
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Jul 2, 2021
1 parent 0dd3ddf commit bc90263
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/inspect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# When a PR is opened or a push is made, perform an
# architectural inspection on the code using Deptrac.
name: Deptrac

on:
pull_request:
branches:
- 'develop'
paths:
- 'src/**'
- 'tests/**'
- 'composer.**'
- 'phpstan*'
- '.github/workflows/inspect.yml'
push:
branches:
- 'develop'
paths:
- 'src/**'
- 'tests/**'
- 'composer.**'
- 'phpstan*'
- '.github/workflows/inspect.yml'

jobs:
build:
name: PHP ${{ matrix.php-versions }} Architectural Inspection
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phive, phpunit
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Create composer cache directory
run: mkdir -p ${{ steps.composer-cache.outputs.dir }}

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Create Deptrac cache directory
run: mkdir -p build/

- name: Cache Deptrac results
uses: actions/cache@v2
with:
path: build
key: ${{ runner.os }}-deptrac-${{ github.sha }}
restore-keys: ${{ runner.os }}-deptrac-

- name: Install dependencies (limited)
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader

- name: Install dependencies (authenticated)
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Run architectural inspection
run: |
sudo phive install --global qossmic/deptrac --trust-gpg-keys B8F640134AB1782E
deptrac analyze --cache-file=build/deptrac.cache
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"prefer-stable": true,
"scripts": {
"analyze": "phpstan analyze",
"inspect": "deptrac analyze --cache-file=build/deptrac.cache",
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
"test": "phpunit"
Expand Down
107 changes: 107 additions & 0 deletions depfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
paths:
- ./src
- ./vendor/codeigniter4/codeigniter4/system
- ./vendor/tatter
exclude_files:
- '#.*test.*#i'
layers:
- name: Model
collectors:
- type: bool
must:
- type: className
regex: .*[A-Za-z]+Model.*
- type: directory
regex: src/.*
- name: Other Model
collectors:
- type: bool
must:
- type: className
regex: .*[A-Za-z]+Model.*
- type: directory
regex: vendor/.*
- name: Controller
collectors:
- type: bool
must:
- type: className
regex: .*\/Controllers\/.*
- type: directory
regex: src/.*
- name: Other Controller
collectors:
- type: bool
must:
- type: className
regex: .*\/Controllers\/.*
- type: directory
regex: vendor/.*
- name: Config
collectors:
- type: bool
must:
- type: directory
regex: src/Config/.*
must_not:
- type: className
regex: .*Services
- name: Other Config
collectors:
- type: bool
must:
- type: directory
regex: vendor/.*/Config/.*
must_not:
- type: className
regex: .*Services
- name: Entity
collectors:
- type: bool
must:
- type: directory
regex: src/Entities/.*
- name: Other Entity
collectors:
- type: bool
must:
- type: directory
regex: vendor/.*/Entities/.*
- name: View
collectors:
- type: bool
must:
- type: directory
regex: src/Views/.*
- name: Other View
collectors:
- type: bool
must:
- type: directory
regex: vendor/.*/Views/.*
- name: Service
collectors:
- type: className
regex: .*Services.*
ruleset:
Entity:
- Config
- Model
- Service
- Other Config
- Other Model
Config:
- Service
Model:
- Config
- Entity
- Service
- Other Config
- Other Model
Service:
- Config
- Other Config
View:
skip_violations:
Tatter\Workflows\Config\Workflows:
- Tatter\Workflows\Models\JobModel

0 comments on commit bc90263

Please sign in to comment.