Skip to content

Commit

Permalink
Update test-suite with superlinter
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Mar 12, 2023
1 parent a269a7c commit 6245ed4
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 115 deletions.
15 changes: 15 additions & 0 deletions .gitattributes
@@ -0,0 +1,15 @@
/.github/ export-ignore
/.phpunit.cache/ export-ignore
/tools/ export-ignore
/tests/ export-ignore
codecov.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
psalm.xml export-ignore
psalm-dev.xml export-ignore
phpcs.xml export-ignore
phpunit.xml export-ignore
.php_cs.dist export-ignore
.markdownlintignore export-ignore
.markdownlint.yml export-ignore
9 changes: 4 additions & 5 deletions .github/workflows/documentation.yml
@@ -1,12 +1,12 @@
name: Documentation

on:
on: # yamllint disable-line rule:truthy
push:
branches: [ master, release-* ]
branches: [master, release-*]
paths:
- '**.md'
pull_request:
branches: [ master, release-* ]
branches: [master, release-*]
paths:
- '**.md'

Expand All @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3

- name: Lint markdown files
uses: nosborn/github-action-markdown-cli@v3.1.0
uses: nosborn/github-action-markdown-cli@v3.2.0
with:
files: .
ignore_path: .markdownlintignore
Expand All @@ -30,4 +30,3 @@ jobs:
path: '**/*.md'
check_filenames: true
ignore_words_list: tekst

249 changes: 157 additions & 92 deletions .github/workflows/php.yml
@@ -1,55 +1,63 @@
---

name: CI

on:
on: # yamllint disable-line rule:truthy
push:
branches: [ '**' ]
branches: ['**']
paths-ignore:
- '**.md'
pull_request:
branches: [ master, release-* ]
branches: [master, release-*]
paths-ignore:
- '**.md'

jobs:
basic-tests:
name: Syntax and unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest]
php-versions: ['8.0', '8.1']
linter:
name: Linter
runs-on: ['ubuntu-latest']

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: true
LINTER_RULES_PATH: 'tools/linters'
VALIDATE_CSS: true
VALIDATE_JAVASCRIPT_ES: true
VALIDATE_JSON: true
VALIDATE_PHP_BUILTIN: true
VALIDATE_YAML: true
VALIDATE_XML: true
VALIDATE_GITHUB_ACTIONS: true

quality:
name: Quality control
runs-on: [ubuntu-latest]

steps:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
id: setup-php
# https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, soap, xml
ini-values: error_reporting=E_ALL
# Should be the higest supported version, so we can use the newest tools
php-version: '8.2'
tools: composer:v2
coverage: pcov
# optional performance gain for psalm: opcache
extensions: ctype, date, dom, hash, mbstring, opcache, openssl, pcre, spl, xml

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3

- name: Get composer cache directory (linux)
if: ${{ matrix.operating-system == 'ubuntu-latest' }}
run: echo "COMPOSER_CACHE=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Get composer cache directory (windows)
if: ${{ matrix.operating-system == 'windows-latest' }}
run: echo "COMPOSER_CACHE=$(composer config cache-files-dir)" >> $env:GITHUB_ENV
- name: Get composer cache directory
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"

- name: Cache composer dependencies
uses: actions/cache@v3
Expand All @@ -64,49 +72,62 @@ jobs:
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Syntax check PHP
run: bash vendor/bin/check-syntax-php.sh
- name: PHP Code Sniffer
run: php vendor/simplesamlphp/simplesamlphp-test-framework/tools/phpcs

- name: Decide whether to run code coverage or not
if: ${{ matrix.php-versions != '8.0' || matrix.operating-system != 'ubuntu-latest' }}
- name: Psalm
continue-on-error: true
run: |
echo "NO_COVERAGE=--no-coverage" >> $GITHUB_ENV
php vendor/simplesamlphp/simplesamlphp-test-framework/tools/psalm \
-c psalm.xml \
--show-info=true \
--shepherd \
--php-version=${{ steps.setup-php.outputs.php-version }}
- name: Run unit tests
- name: Psalm (testsuite)
run: |
echo $NO_COVERAGE
./vendor/bin/phpunit $NO_COVERAGE
php vendor/simplesamlphp/simplesamlphp-test-framework/tools/psalm \
-c psalm-dev.xml \
--show-info=true \
--shepherd \
--php-version=${{ steps.setup-php.outputs.php-version }}
- name: Save coverage data
if: ${{ matrix.php-versions == '8.0' && matrix.operating-system == 'ubuntu-latest' }}
uses: actions/upload-artifact@v3
with:
name: build-data
path: ${{ github.workspace }}/build
- name: Psalter
run: |
php vendor/simplesamlphp/simplesamlphp-test-framework/tools/psalm \
--alter \
--issues=UnnecessaryVarAnnotation \
--dry-run \
--php-version=${{ steps.setup-php.outputs.php-version }}
security:
name: Security checks
runs-on: [ubuntu-latest]
steps:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
# https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mbstring, xml
tools: composer:v2
coverage: none
# Should be the lowest supported version
php-version: '8.0'
extensions: ctype, date, dom, hash, mbstring, openssl, pcre, spl, xml
tools: composer:v2
coverage: none

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- uses: actions/checkout@v3

- name: Get composer cache directory
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
Expand All @@ -120,85 +141,129 @@ jobs:
- name: Security check for updated dependencies
run: composer audit

sanity-check:
name: Sanity checks
runs-on: [ubuntu-latest]
unit-tests-linux:
name: "Syntax and unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
runs-on: ${{ matrix.operating-system }}
needs: [linter, quality, security]
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1', '8.2']

steps:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
# https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mbstring, xml
php-version: ${{ matrix.php-versions }}
extensions: ctype, date, dom, hash, mbstring, openssl, pcre, spl, xml
tools: composer:v2
coverage: none
ini-values: error_reporting=E_ALL
coverage: pcov

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3

- name: Get composer cache directory
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Syntax check YAML / XML / JSON
run: |
bash vendor/bin/check-syntax-yaml.sh
bash vendor/bin/check-syntax-xml.sh
bash vendor/bin/check-syntax-json.sh
- name: Run unit tests with coverage
if: ${{ matrix.php-versions == '8.2' }}
run: vendor/bin/phpunit

quality:
name: Quality control
runs-on: [ubuntu-latest]
needs: [basic-tests]
- name: Run unit tests (no coverage)
if: ${{ matrix.php-versions != '8.2' }}
run: vendor/bin/phpunit --no-coverage

- name: Save coverage data
if: ${{ matrix.php-versions == '8.2' }}
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: ${{ github.workspace }}/build

unit-tests-windows:
name: "Syntax and unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
runs-on: ${{ matrix.operating-system }}
needs: [linter, quality, security]
strategy:
fail-fast: true
matrix:
operating-system: [windows-latest]
php-versions: ['8.0', '8.1', '8.2']

steps:
- name: Setup PHP, with composer and extensions
id: setup-php
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
# https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: ${{ matrix.php-versions }}
extensions: ctype, date, dom, hash, mbstring, openssl, pcre, spl, xml
tools: composer:v2
extensions: mbstring, xml
ini-values: error_reporting=E_ALL
coverage: none

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3

- name: Get composer cache directory
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
path: $COMPOSER_CACHE
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Run unit tests
run: vendor/bin/phpunit --no-coverage

coverage:
name: Code coverage
runs-on: [ubuntu-latest]
needs: [unit-tests-linux]
steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: build-data
name: coverage-data
path: ${{ github.workspace }}/build

- name: Codecov
uses: codecov/codecov-action@v3

- name: PHP Code Sniffer
continue-on-error: true
run: php vendor/bin/phpcs

- name: Psalm
continue-on-error: true
run: php vendor/bin/psalm --show-info=true --shepherd --php-version=${{ steps.setup-php.outputs.php-version }}

- name: Psalter
continue-on-error: true
run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run --php-version=${{ steps.setup-php.outputs.php-version }}
4 changes: 4 additions & 0 deletions .markdownlint.yml
@@ -0,0 +1,4 @@
---
default: true

MD013: false

0 comments on commit 6245ed4

Please sign in to comment.