diff --git a/.github/workflows/reusable-regenerate-readme.yml b/.github/workflows/reusable-regenerate-readme.yml index 7fcda0a..add0c99 100644 --- a/.github/workflows/reusable-regenerate-readme.yml +++ b/.github/workflows/reusable-regenerate-readme.yml @@ -9,10 +9,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true - jobs: - regenerate-readme: #---------------------------------------------------------- + regenerate-readme: name: Regenerate README.md file runs-on: ubuntu-latest if: ${{ github.repository_owner == 'wp-cli' && ! contains(fromJson('[".github", "wp-cli", "wp-cli-bundle", "wp-super-cache-cli", "php-cli-tools", "wp-config-transformer", "wp-cli.github.com"]'), github.event.repository.name) }} @@ -21,26 +20,27 @@ jobs: uses: actions/checkout@v3 - name: Set up PHP envirnoment - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: shivammathur/setup-php@v2 + with: + php-version: "7.4" - name: Check existence of composer.json file id: check_composer_file uses: andstor/file-existence-action@v2 with: - files: "composer.json" + files: composer.json - name: Install Composer dependencies & cache dependencies - if: steps.check_composer_file.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" + if: ${{ steps.check_composer_file.outputs.files_exists == 'true' }} env: COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} + uses: ramsey/composer-install@v2 with: # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") + custom-cache-suffix: | + $(date --utc "+%Y-%m") - name: Configure git user run: | @@ -48,24 +48,27 @@ jobs: git config --global user.name "Alain Schlesser" - name: Check if remote branch exists - run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin regenerate-readme) ]] && echo "0" || echo "1")" >> $GITHUB_ENV - + id: check_remote_branch + run: > + echo "exists=$(git ls-remote --exit-code --heads origin regenerate-readme &>/dev/null + && echo "true" || echo "false")" >>"${GITHUB_OUTPUT}" + - name: Create branch to base pull request on - if: env.REMOTE_BRANCH_EXISTS == 0 + if: ${{ steps.check_remote_branch.outputs.exists == 'false' }} run: | git checkout -b regenerate-readme - name: Fetch existing branch to add commits to - if: env.REMOTE_BRANCH_EXISTS == 1 + if: ${{ steps.check_remote_branch.outputs.exists == 'true' }} run: | git fetch --all --prune git checkout regenerate-readme git pull --no-rebase - - name: Install WP-CLI + - name: Install WP-CLI nightly run: | curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar - sudo mv wp-cli-nightly.phar /usr/local/bin/wp + sudo mv --verbose wp-cli-nightly.phar /usr/local/bin/wp sudo chmod +x /usr/local/bin/wp - name: Regenerate README.md file @@ -74,25 +77,31 @@ jobs: wp scaffold package-readme --branch=${{ github.event.repository.default_branch }} --force . - name: Check if there are changes - run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV + id: check_changes + run: > + echo "detected=$(test -n "$(git status --porcelain 2>/dev/null)" + && echo "true" || echo "false")" >>"${GITHUB_OUTPUT}" - name: Commit changes - if: env.CHANGES_DETECTED == 1 + if: ${{ steps.check_changes.outputs.detected == 'true' }} run: | git add README.md git commit -m "Regenerate README file - $(date +'%Y-%m-%d')" git push origin regenerate-readme - name: Create pull request - if: | - env.CHANGES_DETECTED == 1 && - env.REMOTE_BRANCH_EXISTS == 0 + if: > + ${{ steps.check_changes.outputs.detected == 'true' + && steps.check_remote_branch.outputs.exists == 'false' }} uses: repo-sync/pull-request@v2 with: source_branch: regenerate-readme destination_branch: ${{ github.event.repository.default_branch }} github_token: ${{ secrets.GITHUB_TOKEN }} pr_title: Regenerate README file - pr_body: "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code." + pr_body: | + **This is an automated pull-request** + + Refreshes the `README.md` file with the latest changes to the docblocks in the source code. pr_reviewer: schlessera pr_label: scope:documentation diff --git a/.github/workflows/reusable-testing.yml b/.github/workflows/reusable-testing.yml index 52d2a15..3701d3e 100644 --- a/.github/workflows/reusable-testing.yml +++ b/.github/workflows/reusable-testing.yml @@ -11,12 +11,7 @@ concurrency: jobs: - unit: #----------------------------------------------------------------------- - name: Unit test / PHP ${{ matrix.php }} - strategy: - fail-fast: false - matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + has_unit_tests: runs-on: ubuntu-20.04 steps: @@ -29,8 +24,26 @@ jobs: with: files: "composer.json, phpunit.xml.dist" + outputs: + exists: ${{ steps.check_files.outputs.files_exists }} + + unit: + name: Unit tests on PHP ${{ matrix.php }} + needs: + - has_unit_tests + if: ${{ needs.has_unit_tests.outputs.exists == 'true' }} + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + runs-on: ubuntu-20.04 + + steps: + - name: Check out source code + uses: actions/checkout@v3 + - name: Set up PHP environment (PHP 5.6 - 7.1) - if: ${{ matrix.php < '7.2' && steps.check_files.outputs.files_exists == 'true'}} + if: ${{ matrix.php < '7.2' }} uses: shivammathur/setup-php@v2 with: php-version: '${{ matrix.php }}' @@ -41,35 +54,52 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Set up PHP environment (PHP 7.2+) - if: ${{ matrix.php >= '7.2' && steps.check_files.outputs.files_exists == 'true'}} + if: ${{ matrix.php >= '7.2' }} + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: shivammathur/setup-php@v2 with: php-version: '${{ matrix.php }}' coverage: none tools: composer,cs2pr - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install Composer dependencies & cache dependencies - if: steps.check_files.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" env: COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} + uses: "ramsey/composer-install@v2" with: # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") + custom-cache-suffix: | + $(date -u "+%Y-%m") - name: Setup problem matcher to provide annotations for PHPUnit - if: steps.check_files.outputs.files_exists == 'true' run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit - if: steps.check_files.outputs.files_exists == 'true' - continue-on-error: ${{ matrix.php == '8.2' }} run: composer phpunit + continue-on-error: ${{ matrix.php == '8.2' }} + + has_functional_tests: + runs-on: ubuntu-20.04 - functional: #---------------------------------------------------------------------- + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Check existence of composer.json & behat.yml files + id: check_files + uses: andstor/file-existence-action@v2 + with: + files: "composer.json, behat.yml" + + outputs: + exists: ${{ steps.check_files.outputs.files_exists }} + + functional: name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }} + needs: + - has_functional_tests + if: ${{ needs.has_functional_tests.outputs.exists == 'true' }} strategy: fail-fast: false matrix: @@ -114,55 +144,45 @@ jobs: image: mysql:${{ matrix.mysql }} ports: - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=15s --health-timeout=10s --health-retries=5 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + options: | + --health-cmd="mysqladmin ping" --health-interval=15s --health-timeout=10s --health-retries=5 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" steps: - name: Check out source code uses: actions/checkout@v3 - - name: Check existence of composer.json & behat.yml files - id: check_files - uses: andstor/file-existence-action@v2 - with: - files: "composer.json, behat.yml" - - name: Install Ghostscript - if: steps.check_files.outputs.files_exists == 'true' run: | sudo apt-get update - sudo apt-get install ghostscript -y + sudo apt-get install -y ghostscript - name: Set up PHP environment - if: steps.check_files.outputs.files_exists == 'true' + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: shivammathur/setup-php@v2 with: php-version: '${{ matrix.php }}' extensions: gd, imagick, mysql, zip coverage: none tools: composer - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Change ImageMagick policy to allow pdf->png conversion. - if: steps.check_files.outputs.files_exists == 'true' run: | sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml - name: Install Composer dependencies & cache dependencies - if: steps.check_files.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" env: COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} + uses: "ramsey/composer-install@v2" with: # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") + custom-cache-suffix: | + $(date -u "+%Y-%m") - name: Start MySQL server - if: steps.check_files.outputs.files_exists == 'true' run: sudo systemctl start mysql - name: Configure DB environment - if: steps.check_files.outputs.files_exists == 'true' run: | echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV @@ -174,18 +194,15 @@ jobs: echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV - name: Prepare test database - if: steps.check_files.outputs.files_exists == 'true' run: composer prepare-tests - name: Check Behat environment - if: steps.check_files.outputs.files_exists == 'true' env: WP_VERSION: '${{ matrix.wp }}' run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat - name: Run Behat - if: steps.check_files.outputs.files_exists == 'true' - continue-on-error: ${{ matrix.php == '8.2' }} env: WP_VERSION: '${{ matrix.wp }}' run: composer behat || composer behat-rerun + continue-on-error: ${{ matrix.php == '8.2' }} diff --git a/.github/workflows/sync-workflows.yml b/.github/workflows/sync-workflows.yml index 33d6964..38928cc 100644 --- a/.github/workflows/sync-workflows.yml +++ b/.github/workflows/sync-workflows.yml @@ -11,7 +11,7 @@ on: jobs: - sync-workflows: #------------------------------------------------------------- + sync-workflows: name: Sync GitHub Actions workflows runs-on: ubuntu-latest if: ${{ github.repository_owner == 'wp-cli' }} @@ -68,7 +68,7 @@ jobs: wp-cli/wp-super-cache-cli GITHUB_TOKEN: ${{ secrets.ACTIONS_BOT }} - sync-dependabot: #------------------------------------------------------------ + sync-dependabot: name: Sync Dependabot configuration runs-on: ubuntu-latest if: ${{ github.repository_owner == 'wp-cli' }}