diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml new file mode 100644 index 0000000..df9b7de --- /dev/null +++ b/.github/workflows/code-standards.yml @@ -0,0 +1,36 @@ +name: PHP Code Standards + +on: + workflow_call: + inputs: + version: + type: string + default: "^3.0" + config: + type: string + default: ".php-cs-fixer.dist.php" + path: + type: string + default: "" + +permissions: + contents: read + +jobs: + php_code_standards: + runs-on: ubuntu-latest + name: PHP Code Standards + steps: + - uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Run PHP CS Fixer + run: | + composer install + composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} + ~/.composer/vendor/bin/php-cs-fixer fix \ + --config=${{ inputs.config }} \ + ${{ inputs.path }} \ + --dry-run --diff diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0fc658b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,11 @@ +name: Lint + +on: + pull_request: + +jobs: + code-standards: + uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow + + static-analysis: + uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..cb831d6 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,37 @@ +name: PHP Static Analysis +on: + workflow_call: + inputs: + version: + type: string + default: "^1.8" + paths: + type: string + default: "src" + autoload-file: + type: string + default: "vendor/autoload.php" + level: + type: number + default: 0 + +permissions: + contents: read + +jobs: + static_analysis: + runs-on: ubuntu-latest + name: PHPStan Static Analysis + steps: + - uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Run Script + run: | + composer install + composer global require phpstan/phpstan:${{ inputs.version }} + ~/.composer/vendor/bin/phpstan analyse ${{ inputs.paths }} \ + --autoload-file=${{ inputs.autoload-file }} \ + --level=${{ inputs.level }}