From 677793ed99056429c53f3e7cc924cd21ea0afa8e Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 22 Nov 2022 14:40:12 -0600 Subject: [PATCH] CI GitHub Action (#17) * phpunit upgrade * allowed plugins * BUGFIX SponsorTest * phpcs --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++ .github/workflows/ci.yml | 75 +++++++++++++++++++++++ composer.json | 30 +++++---- tests/Model/SponsorTest.php | 2 +- 5 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/ci.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b8a66b7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: 'BUG ' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..8fd1720 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: 'FEATURE ' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6a86de3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +on: + push: + branches: [ '**' ] + pull_request: + branches: [ '**' ] + +name: "CI" + +jobs: + tests: + name: "Tests" + + runs-on: "ubuntu-latest" + + env: + php_extensions: ctype, dom, fileinfo, hash, intl, mbstring, session, simplexml, tokenizer, xml, pdo, mysqli, gd, zip + + services: + mysql: + image: "mysql:5.7" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_ROOT_PASSWORD: + MYSQL_DATABASE: test_db + ports: + - 3306/tcp + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + strategy: + fail-fast: false + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP with extensions" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.php_extensions }}" + coverage: "xdebug" + + - name: "Start mysql service" + run: "sudo /etc/init.d/mysql start" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1" + with: + path: "~/.composer/cache" + key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}" + restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" + + - name: "Install dependencies with composer" + run: "composer install --no-ansi --no-interaction --no-progress" + + - name: "Run tests with phpunit/phpunit" + env: + SS_DATABASE_PORT: ${{ job.services.mysql.ports['3306'] }} + run: "vendor/bin/phpunit --coverage-clover=coverage.xml" + + - name: "Upload coverage results to CodeCov" + uses: codecov/codecov-action@v1 + with: + files: ./coverage.xml # optional + flags: unittests # optional + + - name: "Run tests with squizlabs/php_codesniffer" + run: "vendor/bin/phpcs -s --report=summary --standard=phpcs.xml.dist --extensions=php,inc --ignore=autoload.php --ignore=vendor/ src/ tests/" diff --git a/composer.json b/composer.json index ab31ecf..61a808d 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { "name": "dynamic/silverstripe-elemental-sponsors", - "type": "silverstripe-vendormodule", "description": "Display a list of sponsor logos with links.", + "license": "BSD-3-Clause", + "type": "silverstripe-vendormodule", "keywords": [ "silverstripe", "sponsors", "elemental" ], - "license": "BSD-3-Clause", "authors": [ { "name": "Dynamic", @@ -22,23 +22,27 @@ "symbiote/silverstripe-gridfieldextensions": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^5.7", - "squizlabs/php_codesniffer": "*" + "silverstripe/recipe-testing": "^2" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "autoload": { + "psr-4": { + "Dynamic\\Elements\\Sponsors\\": "src/", + "Dynamic\\Elements\\Sponsors\\Test\\": "tests/" + } }, "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/vendor-plugin": true, + "silverstripe/recipe-plugin": true + }, "process-timeout": 600 }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } - }, - "autoload": { - "psr-4": { - "Dynamic\\Elements\\Sponsors\\": "src/", - "Dynamic\\Elements\\Sponsors\\Test\\": "tests/" - } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/tests/Model/SponsorTest.php b/tests/Model/SponsorTest.php index 2d62622..b0d8292 100644 --- a/tests/Model/SponsorTest.php +++ b/tests/Model/SponsorTest.php @@ -38,7 +38,7 @@ public function testValidate() $this->assertFalse($result->isValid()); $this->assertContains([ 'message' => 'A logo is required before you can save', - 'fieldName' => '', + 'fieldName' => null, 'messageType' => 'error', 'messageCast' => 'text',