diff --git a/.github/workflows/test-structarmed.yml b/.github/workflows/test-structarmed.yml new file mode 100644 index 000000000000..cf0657f32b57 --- /dev/null +++ b/.github/workflows/test-structarmed.yml @@ -0,0 +1,96 @@ +# When a PR is opened or a push is made, perform +# a static analysis check on the code using Structarmed. +name: Structarmed + +on: + pull_request: + branches: + - 'develop' + - '4.*' + paths: + - 'app/**.php' + - 'system/**.php' + - 'tests/**.php' + - 'utils/**.php' + - '.github/workflows/test-structarmed.yml' + - composer.json + - structarmed.php + - '**.neon.dist' + + push: + branches: + - 'develop' + - '4.*' + paths: + - 'app/**.php' + - 'system/**.php' + - 'tests/**.php' + - 'utils/**.php' + - '.github/workflows/test-structarmed.yml' + - composer.json + - structarmed.php + - '**.neon.dist' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + name: PHP ${{ matrix.php-version }} Analyze code (Structarmed) + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + php-version: + - '8.2' + - '8.5' + + steps: + - name: Checkout base branch for PR + if: github.event_name == 'pull_request' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ github.base_ref }} + + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Setup PHP + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 + with: + php-version: ${{ matrix.php-version }} + extensions: intl + tools: composer + + - name: Validate composer.json + run: composer validate --strict + + - name: Get composer cache directory + id: composer-cache + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer update --ansi --no-interaction ${{ matrix.composer-option }} + + - name: Structarmed Cache + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: /tmp/structarmed + key: ${{ runner.os }}-structarmed-${{ github.run_id }} + restore-keys: ${{ runner.os }}-structarmed- + + - run: mkdir -p /tmp/structarmed + + - name: Run static analysis + run: vendor/bin/structarmed analyze diff --git a/composer.json b/composer.json index ea3bf5391bad..d50630ceb136 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "psr/log": "^3.0" }, "require-dev": { + "boundwize/structarmed": "0.4.0", "codeigniter/phpstan-codeigniter": "^1.5", "fakerphp/faker": "^1.24", "kint-php/kint": "^6.1", diff --git a/structarmed.php b/structarmed.php new file mode 100644 index 000000000000..13cbd93af2d2 --- /dev/null +++ b/structarmed.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +use Boundwize\StructArmed\Architecture; +use Boundwize\StructArmed\Preset\Preset; +use Boundwize\StructArmed\Preset\Presets\Psr4Preset; + +return Architecture::define() + ->skip([ + Psr4Preset::CLASSES_MUST_MATCH_COMPOSER => [ + __DIR__ . '/tests/system/Config/fixtures', + ], + ]) + ->cacheDirectory(is_dir('/tmp') ? '/tmp/structarmed' : null) + ->withPreset(Preset::PSR4());