diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..984e9d6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +name: CI + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + check_composer: + name: Check composer.json + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: '8.0' + - run: composer validate --strict --no-check-lock + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: '7.4' + - name: Install dependencies + run: composer update --ansi --no-progress --prefer-dist --no-interaction + - run: vendor/bin/phpstan analyze -l 5 src + + psalm: + name: Psalm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: '7.4' + - name: Install dependencies + run: composer update --ansi --no-progress --prefer-dist --no-interaction + - run: vendor/bin/psalm + + tests: + name: "Tests on PHP ${{ matrix.php }}" + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ] + + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: shivammathur/setup-php@v2 + with: + coverage: "none" + php-version: "${{ matrix.php }}" + + - name: Install dependencies + run: composer update --ansi --no-progress --prefer-dist --no-interaction + + - name: Run tests + run: vendor/bin/phpunit --colors=always diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..2a95e36 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,24 @@ +name: Automatic update + +on: + schedule: + - cron: '13 10 * * *' # Update once a day at 10:13 (chosen arbitrarily) + +jobs: + update: + name: "Update regexes" + runs-on: ubuntu-latest + # Don't run it on forks that might enable Actions + if: github.repository == 'ua-parser/uap-php' + + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + coverage: "none" + php-version: "7.4" + + - name: Install dependencies + run: composer update --ansi --no-progress --prefer-dist --no-interaction + + - run: ./ci/update.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bfb0742..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -dist: bionic -os: linux -language: php - -before_script: - - phpenv config-rm xdebug.ini || true - -cache: - directories: - - $HOME/.composer/cache/files - - vendor - -jobs: - allow_failures: - - php: nightly - include: - - php: 7.4 - - php: 7.3 - - php: 7.2 - if: branch = master AND fork = false - env: - - UPDATE_RESOURCES=true - - secure: "KdRIoeVMAjv63erXmG3EkOnE/UrIsgIJ7/S3yZwJq3y+c6jd7Xax6lNWRF6PcfKtNHJNhreIKA/skW5CkPktKIKqOrHrJVx5GsIQX3OqW1z2LF/qqDr7zxNWWrCCI13t7uy4GkPNU0xMwauk+5GCoyBrsxwjwf3/Lm3SA7xZTrE=" - - php: nightly - install: - - composer self-update --preview - - composer install --ignore-platform-req=php - -install: - - composer install - -script: - - ./vendor/bin/phpunit || travis_terminate 1 - - ./vendor/bin/psalm || travis_terminate 1 - - ./vendor/bin/phpstan analyse -l 5 src || travis_terminate 1 - - ./ci/update.sh diff --git a/README.md b/README.md index 417dbb9..77c2727 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ua-parser PHP Library # -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ua-parser/uap-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/ua-parser/uap-php.svg?branch=master)](https://travis-ci.org/ua-parser/uap-php) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/ua-parser/uap-php.svg)](http://isitmaintained.com/project/ua-parser/uap-php "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/ua-parser/uap-php.svg)](http://isitmaintained.com/project/ua-parser/uap-php "Percentage of issues still open") +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ua-parser/uap-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://github.com/ua-parser/uap-php/actions/workflows/ci.yml/badge.svg)](https://github.com/ua-parser/uap-php/actions/workflows/ci.yml) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/ua-parser/uap-php.svg)](http://isitmaintained.com/project/ua-parser/uap-php "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/ua-parser/uap-php.svg)](http://isitmaintained.com/project/ua-parser/uap-php "Percentage of issues still open") [![Latest Stable Version](https://poser.pugx.org/ua-parser/uap-php/v/stable)](https://packagist.org/packages/ua-parser/uap-php) [![Total Downloads](https://poser.pugx.org/ua-parser/uap-php/downloads)](https://packagist.org/packages/ua-parser/uap-php) [![License](https://poser.pugx.org/ua-parser/uap-php/license)](https://packagist.org/packages/ua-parser/uap-php) diff --git a/ci/update.sh b/ci/update.sh index 541a0ed..a50527f 100755 --- a/ci/update.sh +++ b/ci/update.sh @@ -2,16 +2,6 @@ set -x set -e -if [ "$UPDATE_RESOURCES" != "true" ]; then - echo "Skip updating resources. UPDATE_RESOURCES not set to true" - exit 0 -fi - -test_prefix="" -if [ "$TRAVIS_BRANCH" != "master" ]; then - test_prefix=test- -fi - git submodule foreach git pull origin master --ff-only bin/uaparser ua-parser:convert uap-core/regexes.yaml @@ -20,21 +10,20 @@ if [[ ! `git status --porcelain` ]]; then else ./vendor/bin/phpunit - git config --global user.email travis@travis-ci.org - git config --global user.name "Travis CI" + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git config --global user.name "github-actions[bot]" - git remote add upstream https://${GITHUB_TOKEN}@github.com/ua-parser/uap-php.git - git fetch upstream --tags + git fetch --tags git status git commit -m "Automatic resource update" uap-core resources/regexes.php - git push upstream ${TRAVIS_BRANCH} + git push - new_version=$test_prefix`git tag | sort --version-sort | tail -n 1 | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'` + new_version=`git tag | sort --version-sort | tail -n 1 | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'` git tag $new_version - git push upstream $new_version + git push --tags echo "$new_version published" fi