Skip to content
237 changes: 237 additions & 0 deletions .github/workflows/lint-and-codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
name: Lint and Code Style

on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened

concurrency:
group: lint-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-php-codestyle:
name: PHP Code Style
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ["7.4"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/actions/checkout/releases is currently at major version 6.
But v4 is working fine, and we can easily bump it later.

with:
fetch-depth: 0

- name: Check if changes affect PHP
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
php:
- '**/*.php'
- '!tests/acceptance/**'
- '!build/**'

- name: Setup PHP
if: steps.changes.outputs.php == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: curl, gd, json, xml, zip
ini-values: "memory_limit=1024M"
tools: phpstan, codesniffer

- name: Cache Composer dependencies
if: steps.changes.outputs.php == 'true'
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
if: steps.changes.outputs.php == 'true'
run: |
composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader

- name: Install vendor-bin dependencies
if: steps.changes.outputs.php == 'true'
run: |
composer install --no-progress --no-interaction --prefer-dist --working-dir=vendor-bin/owncloud-codestyle
composer install --no-progress --no-interaction --prefer-dist --working-dir=vendor-bin/phpstan
composer install --no-progress --no-interaction --prefer-dist --working-dir=vendor-bin/phan

- name: Run PHP Code Sniffer
if: steps.changes.outputs.php == 'true'
run: make test-php-style
continue-on-error: true

phpstan-analysis:
name: PHPStan Static Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ["7.4"]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if changes affect PHP
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
php:
- '**/*.php'
- '!tests/acceptance/**'
- '!build/**'

- name: Setup PHP
if: steps.changes.outputs.php == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: curl, gd, json, xml, zip
ini-values: "memory_limit=1024M"

- name: Cache Composer dependencies
if: steps.changes.outputs.php == 'true'
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
if: steps.changes.outputs.php == 'true'
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader

- name: Install vendor-bin dependencies
if: steps.changes.outputs.php == 'true'
run: composer install --no-progress --no-interaction --prefer-dist --working-dir=vendor-bin/phpstan

- name: Install server dependencies
if: steps.changes.outputs.php == 'true'
run: make install-server

- name: Run PHPStan
if: steps.changes.outputs.php == 'true'
run: make test-php-phpstan
continue-on-error: true

phan-analysis:
name: Phan Static Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ["7.4"]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if changes affect PHP
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
php:
- '**/*.php'
- '!tests/acceptance/**'
- '!build/**'

- name: Setup PHP
if: steps.changes.outputs.php == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: curl, gd, json, xml, zip
ini-values: "memory_limit=1024M"

- name: Cache Composer dependencies
if: steps.changes.outputs.php == 'true'
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
if: steps.changes.outputs.php == 'true'
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader

- name: Install vendor-bin dependencies
if: steps.changes.outputs.php == 'true'
run: composer install --no-progress --no-interaction --prefer-dist --working-dir=vendor-bin/phan

- name: Install server dependencies
if: steps.changes.outputs.php == 'true'
run: make install-server

- name: Run Phan
if: steps.changes.outputs.php == 'true'
run: make test-php-phan
continue-on-error: true

javascript-lint:
name: JavaScript Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if changes affect JavaScript
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
javascript:
- '**/*.js'
- 'package.json'
- 'package-lock.json'

- name: Setup Node.js
if: steps.changes.outputs.javascript == 'true'
uses: actions/setup-node@v3
with:
node-version: "14"
cache: npm

- name: Install Node dependencies
if: steps.changes.outputs.javascript == 'true'
run: npm ci

- name: Run JavaScript linting
if: steps.changes.outputs.javascript == 'true'
run: npm run lint
continue-on-error: true

git-commit-messages:
name: Git Commit Messages
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Validate commit messages
uses: aevea/commitsar@v1.0.2

Loading