Skip to content

Commit

Permalink
Add GHA workflow (#11)
Browse files Browse the repository at this point in the history
* Add GHA worflow

* Add composer.lock

* Add Makefile

* Fix lint errors

* Fix Makefile

* Remove Travis CI config
  • Loading branch information
slavcodev authored Feb 18, 2020
1 parent 4f43dc1 commit 73aedf6
Show file tree
Hide file tree
Showing 8 changed files with 4,233 additions and 38 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests
on: [pull_request]

env:
# see: https://github.com/shivammathur/setup-php
PHP_EXTENSIONS: mbstring, intl, json

jobs:
unit-tests:
runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
php-version: ['7.3', '7.4']

env:
EXECUTE_COVERAGE: ${{ matrix.php-version == '7.3' }}

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Login composer
run: composer config -g github-oauth.github.com ${{ secrets.COMPOSER_TOKEN }}

- name: Install dependencies
run: make install

- name: Run PhpUnit with coverage
if: env.EXECUTE_COVERAGE == 'true'
run: make report-coverage

- name: Run PhpUnit
if: env.EXECUTE_COVERAGE != 'true'
run: make test

- name: Coverage monitor
if: env.EXECUTE_COVERAGE == 'true'
uses: slavcodev/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clover_file: "logs/clover.xml"
comment: false
threshold_alert: 80
threshold_warning: 90

lint:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: ['7.3']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Login composer
run: composer config -g github-oauth.github.com ${{ secrets.COMPOSER_TOKEN }}

- name: Install dependencies
run: make install

- name: Lint code
run: make lint
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vendor/
composer.lock
/phpunit.xml
.php_cs.cache
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CS_FIXER = php vendor/bin/php-cs-fixer fix --config=.php_cs -v --using-cache=no --diff --diff-format=udiff --ansi
PSALM = vendor/bin/psalm --threads=1 --no-cache --find-dead-code=always --show-info=false --config=.psalm/config.xml
PHPUNIT = php vendor/bin/phpunit

PHP_FILES_DIFF = $(shell git diff --name-only --diff-filter=ACMRTUXB $(1) | grep -iE \.php$)
CS_FIXER_TEST = if test "$(1)" ; then $(CS_FIXER) --dry-run $(1) ; else echo "Nothing to fix" ; fi
CS_FIXER_FIX = if test "$(1)" ; then $(CS_FIXER) $(1) ; else echo "Nothing to fix" ; fi

LOGS_DIR = logs
CLOVER_FILE = $(LOGS_DIR)/clover.xml
COVERAGE_REPORT_DIR = $(LOGS_DIR)/report
PSALM_REPORT_FILE = $(LOGS_DIR)/psalm.local.json

.PHONY: all
all: clean install test lint

.PHONY: lint
lint: psalm cs-test

.PHONY: clean
clean:
rm -dfR $(LOGS_DIR)/*

.PHONY: install
install:
composer install -n --no-suggest

.PHONY: cs-test
cs-test:
$(call CS_FIXER_TEST,$(call PHP_FILES_DIFF,"origin/master"))

.PHONY: cs-fix
cs-fix:
$(call CS_FIXER_FIX,$(call PHP_FILES_DIFF,"origin/master"))

.PHONY: cs-test-all
cs-test-all:
$(CS_FIXER) --dry-run

.PHONY: cs-fix-all
cs-fix-all:
$(CS_FIXER)

.PHONY: psalm
psalm:
$(PSALM)

.PHONY: psalm-report
psalm-report:
$(PSALM) --report-show-info=false --report=$(PSALM_REPORT_FILE)

.PHONY: test
test:
$(PHPUNIT)

.PHONY: show-coverage
show-coverage:
$(PHPUNIT) --coverage-text=php://stdout

.PHONY: report-coverage
report-coverage:
$(PHPUNIT) --coverage-clover $(CLOVER_FILE)

.PHONY: report-html-coverage
report-html-coverage:
$(PHPUNIT) --coverage-html $(COVERAGE_REPORT_DIR)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-coveralls]][link-coveralls]
[![GitHub Actions status][ico-github-actions]][link-github]

# Money

Expand Down Expand Up @@ -244,11 +245,13 @@ If you discover a security vulnerability, please report it to security at rebill
The Money library is open-sourced under the [MIT License](./LICENSE) distributed with the software.


[ico-github-actions]: https://github.com/Rebilly/money/workflows/Tests/badge.svg
[ico-version]: https://img.shields.io/packagist/v/Rebilly/money.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/Rebilly/money/master.svg?style=flat-square
[ico-coveralls]: https://img.shields.io/coveralls/github/Rebilly/money.svg?style=flat-square

[link-github]: https://github.com/Rebilly/money
[link-packagist]: https://packagist.org/packages/Rebilly/money
[link-license]: LICENSE
[link-travis]: https://travis-ci.org/Rebilly/money
Expand Down
Loading

0 comments on commit 73aedf6

Please sign in to comment.