From 384ca6d6e65c50416c9fdab2ba9ea0d1f2696899 Mon Sep 17 00:00:00 2001 From: deepakpathania <68396823+deepakpathania@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:37:13 +0530 Subject: [PATCH] Extract minimum supported PHP version from plugin file for GH actions (#7179) --- .github/actions/e2e/env-setup/action.yml | 8 ++------ .github/actions/setup-php/action.yml | 19 +++++++++++++++++++ .github/actions/setup-repo/action.yml | 19 +++++-------------- .github/workflows/check-changelog.yml | 7 ++----- .github/workflows/i18n-weekly-release.yml | 8 ++------ .github/workflows/php-compatibility.yml | 7 ++----- .github/workflows/php-lint-test.yml | 7 ++----- changelog/dev-update-workflows | 4 ++++ 8 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 .github/actions/setup-php/action.yml create mode 100644 changelog/dev-update-workflows diff --git a/.github/actions/e2e/env-setup/action.yml b/.github/actions/e2e/env-setup/action.yml index dabaa752c3e..863ad27e75b 100644 --- a/.github/actions/e2e/env-setup/action.yml +++ b/.github/actions/e2e/env-setup/action.yml @@ -10,12 +10,8 @@ runs: run: echo -e "machine github.com\n login $E2E_GH_TOKEN" > ~/.netrc # PHP setup - - name: PHP Setup - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer - coverage: none + - name: "Set up PHP" + uses: ./.github/actions/setup-php # Composer setup - name: Setup Composer diff --git a/.github/actions/setup-php/action.yml b/.github/actions/setup-php/action.yml new file mode 100644 index 00000000000..44e797aeb6d --- /dev/null +++ b/.github/actions/setup-php/action.yml @@ -0,0 +1,19 @@ +name: "Set up PHP" +description: "Extracts the required PHP version from plugin file and uses it to build PHP." + +runs: + using: composite + steps: + - name: "Get minimum PHP version" + shell: bash + id: get_min_php_version + run: | + MIN_PHP_VERSION=$(sed -n 's/.*PHP: //p' woocommerce-payments.php) + echo "MIN_PHP_VERSION=$MIN_PHP_VERSION" >> $GITHUB_OUTPUT + + - name: "Setup PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ steps.get_min_php_version.outputs.MIN_PHP_VERSION }} + tools: composer + coverage: none diff --git a/.github/actions/setup-repo/action.yml b/.github/actions/setup-repo/action.yml index 28741b60920..890fe95963f 100644 --- a/.github/actions/setup-repo/action.yml +++ b/.github/actions/setup-repo/action.yml @@ -1,29 +1,20 @@ name: "Setup WooCommerce Payments repository" description: "Handles the installation, building, and caching of the projects within the repository." -inputs: - php-version: - description: "The version of PHP that the action should set up." - default: "7.4" - runs: using: composite steps: - name: "Setup Node" uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: ".nvmrc" + cache: "npm" - name: "Enable composer dependencies caching" uses: actions/cache@v3 with: path: ~/.cache/composer/ key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} - - - name: "Setup PHP" - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php-version }} - tools: composer - coverage: none + + - name: "Set up PHP" + uses: ./.github/actions/setup-php diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 55f7391fb90..25cf89903ca 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -22,11 +22,8 @@ jobs: path: ~/.cache/composer/ key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} # setup PHP, but without debug extensions for reasonable performance - - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer - coverage: none + - name: "Set up PHP" + uses: ./.github/actions/setup-php # Install composer packages. - run: composer self-update && composer install --no-progress # Fetch the target branch before running the check. diff --git a/.github/workflows/i18n-weekly-release.yml b/.github/workflows/i18n-weekly-release.yml index 197213dec1c..c2abf63e34c 100644 --- a/.github/workflows/i18n-weekly-release.yml +++ b/.github/workflows/i18n-weekly-release.yml @@ -27,12 +27,8 @@ jobs: path: ~/.npm/ key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} # setup PHP, but without debug extensions for reasonable performance - - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer - coverage: none - + - name: "Set up PHP" + uses: ./.github/actions/setup-php - name: Build release run: | npm ci diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index 8c0e7d73b37..8161804f6a2 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -14,9 +14,6 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer - coverage: none + - name: "Set up PHP" + uses: ./.github/actions/setup-php - run: bash bin/phpcs-compat.sh diff --git a/.github/workflows/php-lint-test.yml b/.github/workflows/php-lint-test.yml index 0399a22735c..5b397ab30d4 100644 --- a/.github/workflows/php-lint-test.yml +++ b/.github/workflows/php-lint-test.yml @@ -27,11 +27,8 @@ jobs: path: ~/.cache/composer/ key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} # setup PHP, but without debug extensions for reasonable performance - - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer - coverage: none + - name: "Set up PHP" + uses: ./.github/actions/setup-php # install dependencies and run linter - run: composer self-update && composer install --no-progress && ./vendor/bin/phpcs --standard=phpcs.xml.dist $(git ls-files | grep .php$) && ./vendor/bin/psalm diff --git a/changelog/dev-update-workflows b/changelog/dev-update-workflows new file mode 100644 index 00000000000..cdab2b4fa9f --- /dev/null +++ b/changelog/dev-update-workflows @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Comment: Update GH workflows to use PHP version from plugin file.