|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, main ] |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + php-version: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4] |
| 17 | + #php-version: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4] |
| 18 | + include: |
| 19 | + - php-version: nightly |
| 20 | + fail-fast: false |
| 21 | + |
| 22 | + services: |
| 23 | + docker: |
| 24 | + image: docker:20.10.16 |
| 25 | + options: --privileged |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up PHP ${{ matrix.php-version }} |
| 31 | + uses: shivammathur/setup-php@v2 |
| 32 | + with: |
| 33 | + php-version: ${{ matrix.php-version }} |
| 34 | + |
| 35 | + - name: "Remove ': void' return type hint for older PHP versions" |
| 36 | + run: | |
| 37 | + # if php version < 7.1, remove ': void' return type hint |
| 38 | + if [[ "${{ matrix.php-version }}" < "7.1" ]]; then |
| 39 | + echo "Removing ': void' return type hint for PHP version ${{ matrix.php-version }}" |
| 40 | + # Find and replace ': void' in all PHP files |
| 41 | + find . -type f -name "*.php" -exec sed -i 's/: void//g' {} + |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Install Composer dependencies (${{ matrix.php-version }}) |
| 45 | + run: composer install --no-interaction --prefer-dist --no-progress |
| 46 | + |
| 47 | + - name: Run tests (${{ matrix.php-version }}) |
| 48 | + run: make test |
| 49 | + |
| 50 | + - name: Run Docker tests |
| 51 | + run: docker run --rm test_phpmetrics |
| 52 | + |
| 53 | + build: |
| 54 | + if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/') |
| 55 | + needs: test |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Set up PHP |
| 61 | + uses: shivammathur/setup-php@v2 |
| 62 | + with: |
| 63 | + php-version: 7.0 |
| 64 | + |
| 65 | + - name: Build project |
| 66 | + run: make build |
| 67 | + |
| 68 | + - name: Add build artifact |
| 69 | + run: git add -f build/phpmetrics.phar |
| 70 | + |
| 71 | + - name: Upload release asset |
| 72 | + uses: softprops/action-gh-release@v2 |
| 73 | + with: |
| 74 | + files: build/phpmetrics.phar |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments