diff --git a/.github/actions/composer-update/action.yml b/.github/actions/composer-update/action.yml new file mode 100644 index 000000000000..5919dd4228a7 --- /dev/null +++ b/.github/actions/composer-update/action.yml @@ -0,0 +1,62 @@ +name: Composer update +description: Restores the Composer download cache, runs `composer update` with retries and saves the cache for the resolved dependencies. + +inputs: + php-version: + description: PHP version used as part of the cache key + required: true + options: + description: Additional options appended to the `composer update` call + required: false + default: '' + github-token: + description: Token used to authenticate the downloads from GitHub + required: false + default: ${{ github.token }} + +runs: + using: composite + steps: + - name: Get composer cache directory + id: composer-cache + shell: bash + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Restore composer cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} + # Never matches an entry, so the restore always falls back to restore-keys. + key: composer-php-${{ inputs.php-version }}-restore-${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + composer-php-${{ inputs.php-version }}- + composer- + + - name: Install dependencies + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github-token }} + COMPOSER_OPTIONS: ${{ inputs.options }} + run: | + if [ -n "$GITHUB_TOKEN" ]; then + composer config --global github-oauth.github.com "$GITHUB_TOKEN" + fi + + attempt=1 + until composer update --ansi --no-interaction $COMPOSER_OPTIONS; do + if [ "$attempt" -ge 3 ]; then + echo "::error::composer update failed after $attempt attempts." + exit 1 + fi + + delay=$((attempt * 30)) + echo "::warning::composer update failed on attempt $attempt. Retrying in ${delay}s." + sleep "$delay" + attempt=$((attempt + 1)) + done + + - name: Save composer cache + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} + key: composer-php-${{ inputs.php-version }}-${{ hashFiles('composer.lock') }} diff --git a/.github/workflows/reusable-coveralls.yml b/.github/workflows/reusable-coveralls.yml index 687b2a919071..d20902f36e0f 100644 --- a/.github/workflows/reusable-coveralls.yml +++ b/.github/workflows/reusable-coveralls.yml @@ -37,20 +37,6 @@ jobs: run: ls -R working-directory: build/cov - - name: Get composer cache directory - id: composer-cache - run: | - echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ inputs.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ inputs.php-version }}- - composer- - - name: Cache PHPUnit's static analysis cache uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -60,7 +46,9 @@ jobs: phpunit-code-coverage- - name: Install dependencies - run: composer update --ansi + uses: ./.github/actions/composer-update + with: + php-version: ${{ inputs.php-version }} - name: Merge coverage files run: | diff --git a/.github/workflows/reusable-phpunit-test.yml b/.github/workflows/reusable-phpunit-test.yml index 6c5497b67294..7bed0b7e2e2e 100644 --- a/.github/workflows/reusable-phpunit-test.yml +++ b/.github/workflows/reusable-phpunit-test.yml @@ -188,18 +188,8 @@ jobs: - name: Setup global environment variables id: setup-env run: | - echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT echo "ARTIFACT_NAME=${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}-db-${{ inputs.db-platform || 'none' }}${{ inputs.mysql-version || '' }}" >> $GITHUB_OUTPUT - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.setup-env.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ inputs.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ inputs.php-version }}- - composer- - - name: Cache PHPUnit's static analysis cache if: ${{ inputs.enable-artifact-upload }} uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -210,9 +200,10 @@ jobs: phpunit-code-coverage- - name: Install dependencies - run: | - composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} - composer update --ansi ${{ inputs.extra-composer-options }} + uses: ./.github/actions/composer-update + with: + php-version: ${{ inputs.php-version }} + options: ${{ inputs.extra-composer-options }} - name: Compute additional PHPUnit options id: phpunit-options diff --git a/.github/workflows/reusable-serviceless-phpunit-test.yml b/.github/workflows/reusable-serviceless-phpunit-test.yml index 60186d6eaa84..2045da647009 100644 --- a/.github/workflows/reusable-serviceless-phpunit-test.yml +++ b/.github/workflows/reusable-serviceless-phpunit-test.yml @@ -85,18 +85,8 @@ jobs: - name: Setup global environment variables id: setup-env run: | - echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT echo "ARTIFACT_NAME=${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}" >> $GITHUB_OUTPUT - - name: Cache Composer dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.setup-env.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ inputs.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ inputs.php-version }}- - composer- - - name: Cache PHPUnit's static analysis cache if: ${{ inputs.enable-artifact-upload }} uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -107,9 +97,10 @@ jobs: phpunit-code-coverage- - name: Install dependencies - run: | - composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} - composer update --ansi ${{ inputs.extra-composer-options }} + uses: ./.github/actions/composer-update + with: + php-version: ${{ inputs.php-version }} + options: ${{ inputs.extra-composer-options }} - name: Compute additional PHPUnit options id: phpunit-options diff --git a/.github/workflows/test-coding-standards.yml b/.github/workflows/test-coding-standards.yml index 36043268a1d3..af311d2e358a 100644 --- a/.github/workflows/test-coding-standards.yml +++ b/.github/workflows/test-coding-standards.yml @@ -46,21 +46,11 @@ jobs: extensions: tokenizer coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ matrix.php-version }}- - composer- - - name: Install dependencies - run: composer update --ansi --no-interaction ${{ matrix.composer-option }} + uses: ./.github/actions/composer-update + with: + php-version: ${{ matrix.php-version }} + options: ${{ matrix.composer-option }} - name: Run lint run: composer cs diff --git a/.github/workflows/test-phpstan.yml b/.github/workflows/test-phpstan.yml index 995929a42ff4..be5e399ee1fd 100644 --- a/.github/workflows/test-phpstan.yml +++ b/.github/workflows/test-phpstan.yml @@ -67,19 +67,6 @@ jobs: - name: Validate composer.json run: composer validate --strict - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-8.2-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-8.2- - composer- - - name: Create PHPStan result cache directory run: mkdir -p build/phpstan @@ -91,7 +78,9 @@ jobs: restore-keys: phpstan- - name: Install dependencies - run: composer update --ansi --no-interaction + uses: ./.github/actions/composer-update + with: + php-version: '8.2' - name: Run static analysis run: composer phpstan:check diff --git a/.github/workflows/test-psalm.yml b/.github/workflows/test-psalm.yml index d76b74def520..98f824321a54 100644 --- a/.github/workflows/test-psalm.yml +++ b/.github/workflows/test-psalm.yml @@ -57,33 +57,27 @@ jobs: env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache composer dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ matrix.php-version }}- - composer- - - name: Create Psalm cache directory run: mkdir -p build/psalm - - name: Cache Psalm results - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + - name: Restore Psalm results + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: build/psalm key: psalm-${{ hashFiles('**/*.php', 'psalm*.xml', 'composer.json') }} restore-keys: psalm- - name: Install dependencies - run: | - composer require sebastian/diff:^5.0 --ansi --working-dir utils - composer update --ansi --no-interaction + uses: ./.github/actions/composer-update + with: + php-version: ${{ matrix.php-version }} - name: Run Psalm analysis run: utils/vendor/bin/psalm + + - name: Save Psalm results + if: ${{ github.event_name == 'push' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: build/psalm + key: psalm-${{ hashFiles('**/*.php', 'psalm*.xml', 'composer.json') }} diff --git a/.github/workflows/test-random-execution.yml b/.github/workflows/test-random-execution.yml index a98d50cec3ad..74e9ee31c785 100644 --- a/.github/workflows/test-random-execution.yml +++ b/.github/workflows/test-random-execution.yml @@ -181,23 +181,10 @@ jobs: ini-values: opcache.enable_cli=0 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache composer dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ matrix.php-version }}- - composer- - - name: Install project dependencies - run: | - composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} - composer update --ansi + uses: ./.github/actions/composer-update + with: + php-version: ${{ matrix.php-version }} - name: Run random test execution verification run: | diff --git a/.github/workflows/test-rector.yml b/.github/workflows/test-rector.yml index 4e603df49e44..55dc0cd5f33a 100644 --- a/.github/workflows/test-rector.yml +++ b/.github/workflows/test-rector.yml @@ -67,19 +67,6 @@ jobs: - name: Validate composer.json run: composer validate --strict - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ matrix.php-version }}- - composer- - - name: Rector Cache uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -90,7 +77,10 @@ jobs: - run: mkdir -p /tmp/rector - name: Install dependencies - run: composer update --ansi --no-interaction ${{ matrix.composer-option }} + uses: ./.github/actions/composer-update + with: + php-version: ${{ matrix.php-version }} + options: ${{ matrix.composer-option }} - name: Run static analysis run: vendor/bin/rector process --dry-run --no-progress-bar diff --git a/.github/workflows/test-structarmed.yml b/.github/workflows/test-structarmed.yml index b064b8213d07..4f59621501a7 100644 --- a/.github/workflows/test-structarmed.yml +++ b/.github/workflows/test-structarmed.yml @@ -64,19 +64,6 @@ jobs: - name: Validate composer.json run: composer validate --strict - - name: Get composer cache directory - id: composer-cache - run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }} - key: composer-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} - restore-keys: | - composer-php-${{ matrix.php-version }}- - composer- - - name: Structarmed Cache uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -87,7 +74,9 @@ jobs: - run: mkdir -p /tmp/structarmed - name: Install dependencies - run: composer update --ansi --no-interaction + uses: ./.github/actions/composer-update + with: + php-version: ${{ matrix.php-version }} - name: Run static analysis run: vendor/bin/structarmed analyze