diff --git a/.github/actions/setup-php-composer/action.yml b/.github/actions/setup-php-composer/action.yml new file mode 100644 index 0000000..1652725 --- /dev/null +++ b/.github/actions/setup-php-composer/action.yml @@ -0,0 +1,88 @@ +name: Setup PHP and Composer +description: Setup PHP with authentication and install Composer dependencies + +inputs: + php-version: + description: The PHP version used to run the workflow. + required: false + default: '8.2' + extensions: + description: Comma-separated PHP extensions. + required: false + default: '' + coverage: + description: Code coverage driver. + required: false + default: none + tools: + description: Comma-separated tools for setup-php. + required: false + default: composer:v2 + use-composer-cache: + description: Whether to restore and save Composer cache. + required: false + default: 'true' + composer-command: + description: Composer install/update command to run. + required: false + default: composer install --prefer-dist --no-interaction + yard-bot-pat: + description: Token used for GitHub API operations in setup-php. + required: true + ypackagist-api-key: + description: Username for packagist.yard.nl. + required: true + ypackagist-password: + description: Password for packagist.yard.nl. + required: true + satis-username: + description: Username for satis.yard.nl. + required: true + satis-password: + description: Password for satis.yard.nl. + required: true + +runs: + using: composite + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + extensions: ${{ inputs.extensions }} + tools: ${{ inputs.tools }} + coverage: ${{ inputs.coverage }} + github-token: ${{ inputs.yard-bot-pat }} + env: + COMPOSER_AUTH_JSON: | + { + "http-basic": { + "packagist.yard.nl": { + "username": "${{ inputs.ypackagist-api-key }}", + "password": "${{ inputs.ypackagist-password }}" + }, + "satis.yard.nl": { + "username": "${{ inputs.satis-username }}", + "password": "${{ inputs.satis-password }}" + } + } + } + + - name: Get Composer cache directory + id: composer-cache + if: ${{ inputs.use-composer-cache == 'true' }} + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Restore Composer cache + if: ${{ inputs.use-composer-cache == 'true' }} + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install composer dependencies + shell: bash + run: ${{ inputs.composer-command }} \ No newline at end of file diff --git a/.github/workflows/format-php.yml b/.github/workflows/format-php.yml index 0745877..8b2aedb 100644 --- a/.github/workflows/format-php.yml +++ b/.github/workflows/format-php.yml @@ -28,30 +28,16 @@ jobs: with: fetch-depth: 0 - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Setup PHP and install Composer dependencies + uses: yardinternet/workflows/.github/actions/setup-php-composer@feat/optimize-composer with: php-version: ${{ inputs.php-version }} - tools: composer:v2 - coverage: none - github-token: ${{ secrets.YARD_BOT_PAT }} - env: - COMPOSER_AUTH_JSON: | - { - "http-basic": { - "packagist.yard.nl": { - "username": "${{ secrets.YPACKAGIST_API_KEY }}", - "password": "${{ secrets.YPACKAGIST_PASSWORD }}" - }, - "satis.yard.nl": { - "username": "${{ secrets.SATIS_USERNAME }}", - "password": "${{ secrets.SATIS_PASSWORD }}" - } - } - } - - - name: Install composer dependencies - run: composer install --prefer-dist --no-interaction + composer-command: composer install --prefer-dist --no-interaction + yard-bot-pat: ${{ secrets.YARD_BOT_PAT }} + ypackagist-api-key: ${{ secrets.YPACKAGIST_API_KEY }} + ypackagist-password: ${{ secrets.YPACKAGIST_PASSWORD }} + satis-username: ${{ secrets.SATIS_USERNAME }} + satis-password: ${{ secrets.SATIS_PASSWORD }} - name: Run PHP CS Fixer run: ./vendor/bin/php-cs-fixer fix diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 1fbada0..df04428 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -14,52 +14,39 @@ concurrency: cancel-in-progress: true jobs: - phpstan: - name: phpstan - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php-version }} - tools: composer:v2 - coverage: none - github-token: ${{ secrets.YARD_BOT_PAT }} - env: - COMPOSER_AUTH_JSON: | - { - "http-basic": { - "packagist.yard.nl": { - "username": "${{ secrets.YPACKAGIST_API_KEY }}", - "password": "${{ secrets.YPACKAGIST_PASSWORD }}" - }, - "satis.yard.nl": { - "username": "${{ secrets.SATIS_USERNAME }}", - "password": "${{ secrets.SATIS_PASSWORD }}" - } - } - } - - - name: Install composer dependencies - run: composer install --prefer-dist --no-interaction - - - name: Dirty fix for previously defined function in packages php stubs - run: | - if [ -f ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php ]; then - sed -i -e 's#function __(#function a__(#' ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php - fi - - if [ -f ./vendor/roots/acorn/src/Illuminate/Foundation/helpers.php ]; then - sed -i -e 's#function __(#function b__(#' ./vendor/roots/acorn/src/Illuminate/Foundation/helpers.php - fi - - if [ -f ./vendor/larastan/larastan/stubs/common/Helpers.stub ]; then - sed -i -e 's#function __(#function c__(#' ./vendor/larastan/larastan/stubs/common/Helpers.stub - fi - - name: Run PHPStan - run: ./vendor/bin/phpstan --error-format=github + phpstan: + name: phpstan + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP and install Composer dependencies + uses: yardinternet/workflows/.github/actions/setup-php-composer@feat/optimize-composer + with: + php-version: ${{ inputs.php-version }} + composer-command: composer install --prefer-dist --no-interaction + yard-bot-pat: ${{ secrets.YARD_BOT_PAT }} + ypackagist-api-key: ${{ secrets.YPACKAGIST_API_KEY }} + ypackagist-password: ${{ secrets.YPACKAGIST_PASSWORD }} + satis-username: ${{ secrets.SATIS_USERNAME }} + satis-password: ${{ secrets.SATIS_PASSWORD }} + + - name: Dirty fix for previously defined function in packages php stubs + run: | + if [ -f ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php ]; then + sed -i -e 's#function __(#function a__(#' ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php + fi + + if [ -f ./vendor/roots/acorn/src/Illuminate/Foundation/helpers.php ]; then + sed -i -e 's#function __(#function b__(#' ./vendor/roots/acorn/src/Illuminate/Foundation/helpers.php + fi + + if [ -f ./vendor/larastan/larastan/stubs/common/Helpers.stub ]; then + sed -i -e 's#function __(#function c__(#' ./vendor/larastan/larastan/stubs/common/Helpers.stub + fi + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-laravel-testbench-tests.yml b/.github/workflows/run-laravel-testbench-tests.yml index ecfdf94..ff3aa26 100644 --- a/.github/workflows/run-laravel-testbench-tests.yml +++ b/.github/workflows/run-laravel-testbench-tests.yml @@ -44,50 +44,24 @@ jobs: with: fetch-depth: 0 - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Setup PHP and install dependencies + uses: yardinternet/workflows/.github/actions/setup-php-composer@feat/optimize-composer with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, xdebug coverage: xdebug - tools: composer:v2 - github-token: ${{ secrets.YARD_BOT_PAT }} - env: - COMPOSER_AUTH_JSON: | - { - "http-basic": { - "packagist.yard.nl": { - "username": "${{ secrets.YPACKAGIST_API_KEY }}", - "password": "${{ secrets.YPACKAGIST_PASSWORD }}" - }, - "satis.yard.nl": { - "username": "${{ secrets.SATIS_USERNAME }}", - "password": "${{ secrets.SATIS_PASSWORD }}" - } - } - } + composer-command: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update && composer update --prefer-dist --no-interaction + yard-bot-pat: ${{ secrets.YARD_BOT_PAT }} + ypackagist-api-key: ${{ secrets.YPACKAGIST_API_KEY }} + ypackagist-password: ${{ secrets.YPACKAGIST_PASSWORD }} + satis-username: ${{ secrets.SATIS_USERNAME }} + satis-password: ${{ secrets.SATIS_PASSWORD }} - name: Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --prefer-dist --no-interaction - - name: List Installed Dependencies run: composer show -D diff --git a/.github/workflows/run-pest-tests.yml b/.github/workflows/run-pest-tests.yml index 330ec30..d55f323 100644 --- a/.github/workflows/run-pest-tests.yml +++ b/.github/workflows/run-pest-tests.yml @@ -34,49 +34,24 @@ jobs: with: fetch-depth: 0 - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Setup PHP and install dependencies + uses: yardinternet/workflows/.github/actions/setup-php-composer@feat/optimize-composer with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, xdebug coverage: xdebug - tools: composer:v2 - github-token: ${{ secrets.YARD_BOT_PAT }} - env: - COMPOSER_AUTH_JSON: | - { - "http-basic": { - "packagist.yard.nl": { - "username": "${{ secrets.YPACKAGIST_API_KEY }}", - "password": "${{ secrets.YPACKAGIST_PASSWORD }}" - }, - "satis.yard.nl": { - "username": "${{ secrets.SATIS_USERNAME }}", - "password": "${{ secrets.SATIS_PASSWORD }}" - } - } - } + composer-command: composer update --prefer-dist --no-interaction + yard-bot-pat: ${{ secrets.YARD_BOT_PAT }} + ypackagist-api-key: ${{ secrets.YPACKAGIST_API_KEY }} + ypackagist-password: ${{ secrets.YPACKAGIST_PASSWORD }} + satis-username: ${{ secrets.SATIS_USERNAME }} + satis-password: ${{ secrets.SATIS_PASSWORD }} - name: Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Install dependencies - run: | - composer update --prefer-dist --no-interaction - - name: List Installed Dependencies run: composer show -D diff --git a/composer-lock-diff/action.yml b/composer-lock-diff/action.yml new file mode 100644 index 0000000..bc96b92 --- /dev/null +++ b/composer-lock-diff/action.yml @@ -0,0 +1,36 @@ +name: Composer Lock Diff +description: Compares two composer.lock files and outputs the differences in a human-readable format. +author: Yard Digital Agency +branding: + icon: "lock" + color: "gray-dark" + +runs: + using: composite + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required to make it possible to compare with PR base branch + + - name: Generate composer diff + id: composer_diff # To reference the output in comment + uses: IonBazan/composer-diff-action@v1 + with: + with-platform: true + with-links: true + with-licenses: true + + - uses: marocchino/sticky-pull-request-comment@v2 + # An empty diff result will break this action. + if: ${{ steps.composer_diff.outputs.composer_diff_exit_code != 0 }} + with: + header: composer-diff # Creates a collapsed comment with the report + message: | +
+ Composer package changes + + ${{ steps.composer_diff.outputs.composer_diff }} + +
+