|
| 1 | +name: Release PHP Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +env: |
| 10 | + COMPOSER_ARGS: "--no-interaction --no-progress --ansi" |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + php: ['8.1', '8.2', '8.3', '8.4'] |
| 18 | + |
| 19 | + name: PHP ${{ matrix.php }} Tests |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Setup PHP |
| 26 | + uses: shivammathur/setup-php@v2 |
| 27 | + with: |
| 28 | + php-version: ${{ matrix.php }} |
| 29 | + extensions: json, mbstring, zip |
| 30 | + tools: composer |
| 31 | + |
| 32 | + - name: Cache Composer dependencies |
| 33 | + uses: actions/cache@v3 |
| 34 | + with: |
| 35 | + path: ~/.composer/cache |
| 36 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 37 | + restore-keys: ${{ runner.os }}-composer- |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: composer install ${{ env.COMPOSER_ARGS }} |
| 41 | + |
| 42 | + - name: Run PHPStan |
| 43 | + run: vendor/bin/phpstan analyse --no-progress |
| 44 | + |
| 45 | + - name: Run PHP CodeSniffer |
| 46 | + run: vendor/bin/phpcs |
| 47 | + |
| 48 | + - name: Run PHPUnit tests |
| 49 | + run: vendor/bin/phpunit |
| 50 | + |
| 51 | + release: |
| 52 | + needs: test |
| 53 | + runs-on: ubuntu-latest |
| 54 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + |
| 62 | + - name: Setup PHP |
| 63 | + uses: shivammathur/setup-php@v2 |
| 64 | + with: |
| 65 | + php-version: '8.3' |
| 66 | + extensions: json, mbstring, zip |
| 67 | + tools: composer |
| 68 | + |
| 69 | + - name: Install dependencies |
| 70 | + run: composer install ${{ env.COMPOSER_ARGS }} --no-dev |
| 71 | + |
| 72 | + - name: Check if version changed |
| 73 | + id: version-check |
| 74 | + run: | |
| 75 | + # Get current version from composer.json |
| 76 | + CURRENT_VERSION=$(php -r "echo json_decode(file_get_contents('composer.json'))->version ?? 'unknown';") |
| 77 | + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 78 | + |
| 79 | + # Check if this version already has a git tag |
| 80 | + if git tag -l "v$CURRENT_VERSION" | grep -q "v$CURRENT_VERSION"; then |
| 81 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 82 | + echo "Version $CURRENT_VERSION already released" |
| 83 | + else |
| 84 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 85 | + echo "New version $CURRENT_VERSION ready for release" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Create GitHub Release |
| 89 | + if: steps.version-check.outputs.should_release == 'true' |
| 90 | + uses: softprops/action-gh-release@v1 |
| 91 | + with: |
| 92 | + tag_name: v${{ steps.version-check.outputs.current_version }} |
| 93 | + name: v${{ steps.version-check.outputs.current_version }} |
| 94 | + generate_release_notes: true |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + - name: Publish to Packagist |
| 99 | + if: steps.version-check.outputs.should_release == 'true' |
| 100 | + run: | |
| 101 | + echo "Package will be automatically published to Packagist when the GitHub release is created" |
| 102 | + echo "Make sure your package is registered at https://packagist.org and has the GitHub webhook configured" |
| 103 | +
|
| 104 | + package-test: |
| 105 | + needs: release |
| 106 | + runs-on: ubuntu-latest |
| 107 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Checkout code |
| 111 | + uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: Wait for Packagist |
| 114 | + run: | |
| 115 | + echo "Waiting 30 seconds for Packagist to update..." |
| 116 | + sleep 30 |
| 117 | +
|
| 118 | + - name: Test deployed package |
| 119 | + env: |
| 120 | + LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY }} |
| 121 | + run: | |
| 122 | + cd check-deployed-package |
| 123 | + chmod +x run.sh |
| 124 | + ./run.sh |
0 commit comments