ci: migrate to wp-env #11
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - develop | |
| - main | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - ready_for_review | |
| paths-ignore: | |
| - 'assets/**' | |
| - 'docs/**' | |
| - '**/*.md' | |
| - '**/*.txt' | |
| # Cancels all previous workflow runs for pull requests that have not completed. | |
| concurrency: | |
| # The concurrency group contains the workflow name and the branch name for pull requests | |
| # or the commit hash for any other events. | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | |
| cancel-in-progress: true | |
| jobs: | |
| # Runs the PHP coding standards checks. | |
| # | |
| # Violations are reported inline with annotations. | |
| # | |
| # Performs the following steps: | |
| # - Checks out the repository. | |
| # - Sets up PHP. | |
| # - Configures caching for PHPCS scans. | |
| # - Installs Composer dependencies. | |
| # - Runs PHPCS on the full codebase. | |
| # - Generate a report for displaying issues as pull request annotations. | |
| phpcs: | |
| name: Run PHPCS coding standards checks | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | |
| persist-credentials: false | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 | |
| with: | |
| php-version: '8.3' | |
| coverage: none | |
| tools: cs2pr | |
| # This date is used to ensure that the PHPCS cache is cleared at least once every week. | |
| # http://man7.org/linux/man-pages/man1/date.1.html | |
| - name: "Get last Monday's date" | |
| id: get-date | |
| run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT" | |
| - name: Cache PHPCS scan cache | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: tests/_output/phpcs-cache.json | |
| key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} | |
| - name: Install Composer dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 | |
| - name: Run PHPCS | |
| id: phpcs | |
| run: composer lint -- --report-full --report-checkstyle=./tests/_output/phpcs-report.xml | |
| - name: Show PHPCS results in PR | |
| if: ${{ always() && steps.phpcs.outcome == 'failure' }} | |
| run: cs2pr ./tests/_output/phpcs-report.xml | |
| # Runs PHP static analysis tests. | |
| # | |
| # Violations are reported inline with annotations. | |
| # | |
| # Performs the following steps: | |
| # - Checks out the repository. | |
| # - Sets up PHP. | |
| # - Gets last Monday's date (for cache invalidation). | |
| # - Configures caching for PHP static analysis scans. | |
| # - Installs Composer dependencies. | |
| # - Makes Composer packages available globally. | |
| # - Sets up Node.js. | |
| # - Installs npm dependencies. | |
| # - Configures caching for Docker images. | |
| # - Sets up WordPress environment. | |
| # - Starts the WordPress Docker testing environment. | |
| # - Starts the Docker testing environment. | |
| # - Runs PHPStan static analysis (with Pull Request annotations). | |
| # - Saves the PHPStan result cache. | |
| phpstan: | |
| name: Run PHP static analysis | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | |
| persist-credentials: false | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 | |
| with: | |
| php-version: 8.3 | |
| coverage: none | |
| tools: cs2pr | |
| # This date is used to ensure that the PHPCS cache is cleared at least once every week. | |
| # http://man7.org/linux/man-pages/man1/date.1.html | |
| - name: "Get last Monday's date" | |
| id: get-date | |
| run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT" | |
| - name: Cache PHP Static Analysis scan cache | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: tests/_output # This is defined in the base.neon file. | |
| key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}' | |
| restore-keys: | | |
| phpstan-result-cache- | |
| - name: Install Composer dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 | |
| - name: Make Composer packages available globally | |
| run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH" | |
| - name: Setup Node | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| cache: 'npm' | |
| node-version-file: '.nvmrc' | |
| - name: Install NPM dependencies | |
| run: npm ci | |
| - name: Cache WordPress downloads | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: ~/.wp-env/downloads | |
| key: ${{ runner.os }}-wp-env-downloads-${{ hashFiles('.wp-env.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-env-downloads- | |
| - name: Cache WordPress Plugins | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: | | |
| tests/_data/plugins | |
| tests/_data/mu-plugins | |
| key: ${{ runner.os }}-wp-plugins-${{ hashFiles('.wp-env.json', 'bin/_lib.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-plugins- | |
| - name: Setup WordPress | |
| run: | | |
| cp .env.dist .env | |
| echo GF_KEY=${{ secrets.GF_KEY }} >> .env | |
| - name: Start the Docker testing environment | |
| uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: | | |
| npm run wp-env start -- ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} | |
| - name: Run PHP static analysis tests | |
| id: phpstan | |
| run: phpstan analyse -vvv --error-format=checkstyle | cs2pr | |
| - name: Save result cache | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| if: ${{ !cancelled() }} | |
| with: | |
| path: tests/_output | |
| key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}' | |
| # Runs GraphQL schema linter checks. | |
| # | |
| # Violations are reported inline with annotations. | |
| # | |
| # Performs the following steps: | |
| # - Checks out the repository. | |
| # - Sets up PHP. | |
| # - Gets last Monday's date (for cache invalidation). | |
| # - Installs Composer dependencies. | |
| # - Makes Composer packages available globally. | |
| # - Sets up Node.js. | |
| # - Installs npm dependencies. | |
| # - Configures caching for Docker images. | |
| # - Sets up WordPress environment. | |
| # - Starts the WordPress Docker testing environment. | |
| # - Starts the Docker testing environment. | |
| # - Setup GraphQL Schema Linter | |
| # - Generate GraphQL schema. | |
| # - Lint the generated schema. | |
| # - Get latest tag version. | |
| # - Get previously released schema. | |
| # - Install Schema Inspector. | |
| # - Run Schema Inspector | |
| schema_linter: | |
| name: Lint GraphQL schema | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | |
| persist-credentials: false | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 | |
| with: | |
| php-version: 8.3 | |
| coverage: none | |
| tools: cs2pr | |
| # This date is used to ensure that the PHPCS cache is cleared at least once every week. | |
| # http://man7.org/linux/man-pages/man1/date.1.html | |
| - name: "Get last Monday's date" | |
| id: get-date | |
| run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT" | |
| - name: Install Composer dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 | |
| - name: Make Composer packages available globally | |
| run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH" | |
| - name: Setup Node | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| cache: 'npm' | |
| node-version-file: '.nvmrc' | |
| - name: Install NPM dependencies | |
| run: npm ci | |
| - name: Cache WordPress downloads | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: ~/.wp-env/downloads | |
| key: ${{ runner.os }}-wp-env-downloads-${{ hashFiles('.wp-env.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-env-downloads- | |
| - name: Cache WordPress Plugins | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: | | |
| tests/_data/plugins | |
| tests/_data/mu-plugins | |
| key: ${{ runner.os }}-wp-plugins-${{ hashFiles('.wp-env.json', 'bin/_lib.sh', 'bin/after-start.sh', 'bin/setup.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-plugins- | |
| - name: Setup WordPress | |
| run: | | |
| cp .env.dist .env | |
| echo GF_KEY=${{ secrets.GF_KEY }} >> .env | |
| - name: Start the Docker testing environment | |
| uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: | | |
| npm run wp-env start -- ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} | |
| - name: Setup GraphQL Schema Linter | |
| run: npm install -g graphql-schema-linter@^3.0 graphql@16 | |
| - name: Generate GraphQL schema | |
| run: | | |
| npm run wp-env -- run cli --env-cwd=wp-content/plugins/wp-graphql-gravity-forms wp graphql generate-static-schema --output=tests/_output/schema.graphql | |
| echo "Schema generated: $(wc -l < tests/_output/schema.graphql) lines" | |
| - name: Lint the generated schema | |
| id: schema-lint | |
| run: | | |
| graphql-schema-linter --rules arguments-have-descriptions,defined-types-are-used,deprecations-have-a-reason,descriptions-are-capitalized,enum-values-all-caps,enum-values-have-descriptions,fields-have-descriptions,input-object-values-have-descriptions,relay-connection-arguments-spec,types-have-descriptions,types-are-capitalized --ignore '{"defined-types-are-used":["MenuItemsWhereArgs","TermObjectUnion","TimezoneEnum"],"fields-have-descriptions":["WPGatsbyPreviewStatus","WPGatsbyPageNode.path","WPGatsbyCompatibility.satisfies"],"enum-values-have-descriptions":["WPGatsbyRemotePreviewStatusEnum","WPGatsbyWPPreviewedNodeStatus"]}' tests/_output/schema.graphql | |
| - name: Display ignored schema linter issues in PR | |
| run: graphql-schema-linter --rules arguments-have-descriptions,defined-types-are-used,deprecations-have-a-reason,descriptions-are-capitalized,enum-values-all-caps,enum-values-have-descriptions,fields-have-descriptions,input-object-values-have-descriptions,relay-connection-arguments-spec,types-have-descriptions,types-are-capitalized tests/_output/schema.graphql || true | |
| - name: Get Latest tag | |
| uses: actions-ecosystem/action-get-latest-tag@b7c32daec3395a9616f88548363a42652b22d435 # v1.6.0 | |
| id: get-latest-tag | |
| - name: Get previously released schema | |
| run: curl 'https://github.com/axewp/wp-graphql-gravity-forms/releases/download/${{ steps.get-latest-tag.outputs.tag }}/schema.graphql' -L --output /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql | |
| # https://github.com/marketplace/actions/graphql-inspector | |
| - name: Install Schema Inspector | |
| run: npm install -g @graphql-inspector/config @graphql-inspector/cli graphql@latest | |
| - name: Run Schema Inspector | |
| run: | | |
| # This schema and previous release schema | |
| graphql-inspector diff /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql tests/_output/schema.graphql | |
| # Runs the Codeception tests for WordPress. | |
| # | |
| # Performs the following steps: | |
| # - Sets environment variables. | |
| # - Checks out the repository. | |
| # - Sets up PHP. | |
| # - Installs Composer dependencies. | |
| # - Sets up Node.js. | |
| # - Installs npm dependencies. | |
| # - Starts the WordPress Docker testing environment (with or without Xdebug coverage). | |
| # - Logs PHP and WordPress versions from the container. | |
| # - Runs Codeception tests (with coverage if enabled). | |
| # - Uploads code coverage report to Codecov.io (if coverage is enabled). | |
| # - Uploads HTML coverage report as an artifact (if coverage is enabled). | |
| codeception: | |
| name: Test PHP ${{ matrix.php }} WP ${{ matrix.wordpress }}${{ matrix.coverage && ' with coverage' || '' }} | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| timeout-minutes: 30 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ## GF 2.9.x only supports from WP 6.5, and we have no way to access earlier versions. | |
| php: ['8.2', '8.1'] | |
| wordpress: ['6.8', '6.7', '6.6', '6.5'] | |
| coverage: [0] | |
| include: | |
| - php: '8.3' | |
| wordpress: '6.8' | |
| coverage: 1 | |
| env: | |
| WP_ENV_PHP_VERSION: ${{ matrix.php }} | |
| WP_ENV_CORE: ${{ matrix.wordpress == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }} | |
| steps: | |
| - name: Configure environment variables | |
| run: | | |
| echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV" | |
| echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV" | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | |
| persist-credentials: false | |
| ## | |
| # This allows Composer dependencies to be installed using a single step. | |
| # | |
| # Since the tests are currently run within the Docker containers where the PHP version varies, | |
| # the same PHP version needs to be configured for the action runner machine so that the correct | |
| # dependency versions are installed and cached. | |
| ## | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 | |
| with: | |
| php-version: '${{ matrix.php }}' | |
| tools: composer:v2 | |
| extensions: json, mbstring | |
| - name: Install Composer dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 | |
| - name: Setup Node | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| cache: 'npm' | |
| node-version-file: '.nvmrc' | |
| - name: Install NPM dependencies | |
| run: npm ci | |
| - name: Cache WordPress downloads | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: ~/.wp-env/downloads | |
| key: ${{ runner.os }}-wp-env-downloads-${{ hashFiles('.wp-env.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-env-downloads- | |
| - name: Cache WordPress Plugins | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| path: | | |
| tests/_data/plugins | |
| tests/_data/mu-plugins | |
| key: ${{ runner.os }}-wp-plugins-${{ hashFiles('.wp-env.json', 'bin/_lib.sh', 'bin/after-start.sh', 'bin/setup.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-wp-plugins- | |
| - name: Setup WordPress | |
| run: | | |
| cp .env.dist .env | |
| echo GF_KEY=${{ secrets.GF_KEY }} >> .env | |
| - name: Start the Docker testing environment | |
| uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: | | |
| npm run wp-env start -- ${{ matrix.coverage && '--xdebug=coverage' || '' }} ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} | |
| - name: Log versions | |
| run: | | |
| npm run wp-env -- run cli php -- -v | |
| npm run wp-env -- run cli wp core version | |
| - name: Run Acceptance Tests | |
| run: | | |
| npm run test:codecept -- run acceptance ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} | |
| - name: Run Unit Tests | |
| run: | | |
| npm run test:codecept -- run unit ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} | |
| - name: Run WPUnit Tests ${{ matrix.coverage && ' with coverage report' || '' }} | |
| run: | | |
| npm run test:codecept -- run wpunit ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }} ${{ matrix.coverage && '--coverage --coverage-xml' || '' }} | |
| - name: Upload test failure artifacts | |
| if: failure() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: test-failures-php${{ matrix.php }}-wp${{ matrix.wordpress }} | |
| path: tests/_output/*.fail.html | |
| if-no-files-found: ignore | |
| - name: Upload HTML coverage report as artifact | |
| if: ${{ matrix.coverage }} | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: wp-code-coverage-${{ matrix.php }}-${{ matrix.wordpress }} | |
| path: tests/_output/html | |
| overwrite: true | |
| - name: Upload code coverage report | |
| continue-on-error: true | |
| if: ${{ matrix.coverage }} | |
| uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: tests/_output/coverage.xml | |
| flags: wpunit | |
| fail_ci_if_error: true | |
| # Runs the WordPress Plugin Check action. | |
| # Performs the following steps: | |
| # - Checks out the repository. | |
| # - Sets up PHP. | |
| # - Installs Composer dependencies. | |
| # - Sets up Node.js. | |
| # - Installs npm dependencies. | |
| # - Runs the WordPress Plugin Check action. | |
| # plugin_check: | |
| # name: Run Plugin Check | |
| # runs-on: ubuntu-24.04 | |
| # permissions: | |
| # contents: read | |
| # timeout-minutes: 20 | |
| # steps: | |
| # - name: Checkout repository | |
| # uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| # with: | |
| # show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | |
| # persist-credentials: false | |
| # - name: Set up PHP | |
| # uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 | |
| # with: | |
| # php-version: 8.3 | |
| # coverage: none | |
| # tools: cs2pr | |
| # # This date is used to ensure that the PHPCS cache is cleared at least once every week. | |
| # # http://man7.org/linux/man-pages/man1/date.1.html | |
| # - name: "Get last Monday's date" | |
| # id: get-date | |
| # run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT" | |
| # - name: Cache PHP Static Analysis scan cache | |
| # uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| # with: | |
| # path: tests/_output # This is defined in the base.neon file. | |
| # key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}' | |
| # restore-keys: | | |
| # phpstan-result-cache- | |
| # - name: Install Composer dependencies | |
| # uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 | |
| # - name: Make Composer packages available globally | |
| # run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH" | |
| # - name: Setup Node | |
| # uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| # with: | |
| # cache: 'npm' | |
| # node-version-file: '.nvmrc' | |
| # - name: Install NPM dependencies | |
| # run: npm ci | |
| # - name: Build and zip | |
| # run: | | |
| # npm run plugin-zip | |
| # mkdir tmp-build | |
| # unzip wp-graphql-gravity-forms.zip -d tmp-build | |
| # - name: Run plugin check | |
| # uses: wordpress/plugin-check-action@ec9b3fe9beaa76bcc4510b7ba2cb5855a5f80f3f # v1.1.4 | |
| # with: | |
| # build-dir: "./tmp-build/wp-graphql-gravity-forms" | |
| # # Exclude file_type because of the dev files present in the repository. | |
| # exclude-checks: | | |
| # file_type | |
| # exclude-directories: | | |
| # .github | |
| # bin | |
| # docs | |
| # phpstan | |
| # tests |