diff --git a/.gitignore b/.gitignore index 2c8d939..d898263 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -.github +/.github +/scaffold/.github/actions/drainpipe \ No newline at end of file diff --git a/README.md b/README.md index ecc52ed..cabbce7 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,72 @@ -# ten7/github-code-testing +# GitHub Code Testing A Composer plugin that scaffolds TEN7's GitHub Actions and workflow files into Drupal projects. -Requires [lullabot/drainpipe](https://github.com/lullabot/drainpipe) as a -dependency — even on projects not using drainpipe workflows, as it provides the -build tooling the actions depend on. + +This is a transitional project, allowing TEN7 to build testing infrastructure for +existing lullabot/drainpipe projects and preparing for the switch to Pantheon-based +deployments on GitHub. + +This will install [lullabot/drainpipe](https://github.com/lullabot/drainpipe) as a dependency, but Drainpipe +actions are only installed on sites that use Drainpipe. Because this depends +on a certain version of Drainpipe, it is best to run `composer remove --dev +lullabot/drainpipe-dev -W` and `composer remove lullabot/drainpipe` so that +the version constraint equals what is installed by this repo. + +🗒️The intent is that this repo should be updated regularly to the latest +version of Drainpipe. All Drainpipe features are available to the site if +that is desired, however, most Pantheon-related functionality is +incorporated into the equivalent workflows on this project. + +# Requirements + +This tool is predicated on the assumption that you want to run code tests +with your GitHub deployments to Pantheon. + +Most important is a [Playwright](https://playwright.dev/docs/intro) test setup +in a directory called `test/playwright`. + +If you have a BrowserStack account, you can install the +[browserstack-node-sdk](https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs/integrate-your-tests?fw-lang=nodejs) +which will install a browserstack.yml file in the `test/playwright` directory. + +For the `CodeTests`, it is also important to have a phpunit configuration on +your site. In most Drupal setups, this will be at least partly set up on +installation. If there are no tests, Unit and ExistingSite steps will be +skipped. +As is mentioned below, This is not necessary as the tests can be run locally; +however, if your site has php-based tests you want run, these can be a +useful check on every run. ## Installation -```bash -composer require "ten7/github-code-testing" +This repo is not listed at packagist so you need to add the following to +your "repositories[]" in composer.json. + + +```json +{ + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/ten7/github-code-testing" + } + ] +} +``` + +Then you can run the following, though nothing will change in your codebase +until you define "GitHub" in "extras" explained below. + +⚠️ You may need to adjust your minimum stability if installation results in +a message that it cannot find the repo to install. + +Note: It is best to use the latest version when requiring this. Check the tags +at https://github.com/ten7/github-code-testing. + + +```shell +composer require "ten7/github-code-testing^1.0.7-beta" ``` ⚠️If you have lullabot/drainpipe and/or lullabot/drainpipe-dev you will need @@ -25,126 +82,248 @@ context key and a list of workflow names. ##### Secrets -* SSH_PRIVATE_KEY is needed for all actions. -* SSH_KNOWN_HOSTS is also needed for all actions. -* TERMINUS_MACHINE_TOKEN is required for all actions -* PANTHEON_REVIEW_RUN_INSTALLER is required for drainpipe actions -* BROWSERSTACK_USERNAME is the short key indicating the username (should be +* `SSH_PRIVATE_KEY` is needed for all actions. +* `SSH_KNOWN_HOSTS` is also needed for all actions. +* `TERMINUS_MACHINE_TOKEN` is required for all actions +* `PANTHEON_REVIEW_RUN_INSTALLER` is required for Drainpipe actions +* `PANTHEON_SITE_NAME` is the required by Drainpipe actions. It is the UUID + for the site. It's annoying to have this in both variables and secrets. It + really should just be a variable unless at some point Pantheon allows + renaming a site and the UUID serves it's real purpose of being the + constant identifier. +* `BROWSERSTACK_USERNAME` is the short key indicating the username (should be the company-wide/repo-holder's username at browserstack.com) -* BROWSERSTACK_ACCESS_KEY is the hash at the same account at browserstack.com +* `BROWSERSTACK_ACCESS_KEY` is the hash at the same account at browserstack.com ##### Variables -* BROWSERSTACK_PRIMARY_BRANCH is the branch (edge or main) that browserstack -* tests should be run on. -* BROWSERSTACK_TESTS_ENABLED is a boolean that indicates if browserstack +* `BROWSERSTACK_PRIMARY_BRANCH` is the branch (edge, main, master) that + browserstack tests should be run on. +* `BROWSERSTACK_TESTS_ENABLED` is a boolean that indicates if browserstack tests should be run at all. -* TESTING_NEEDS_SEARCH_INDEXING is a boolean that determines if tests run on - the site require a build to run the search_api index. -* PANTHEON_SITE_NAME is the human-friendly site name that is used in +* `TESTING_NEEDS_SEARCH_INDEXING` is a boolean that determines if tests run on + the site require a build to run the search_api index. This should be set + to either `true` or `false` (which is the same as not having it) +* `PANTHEON_SITE_NAME` is the human-friendly site name that is used in multi-dev URLs: https:/dev-[site-name].pantheonsite.io ##### PR Labels On PRs some labels can be used for triggering actions these include -* skip-wipe which prevents a build from wiping the files and db and starting +* `skip-wipe` which prevents a build from wiping the files and db and starting from scratch on every push -* build multidev which is required to actually run drainpipePantheonReviewApps -* test renovate is useful if you want to reduce testRenovate's time to run - even more. See below. +* `build multidev` is required to build a Pantheon review app for the PR at + all. It only controls whether the multidev environment gets built - whether + tests actually run against it once built is a separate check (see + `browserstack` below). +* `test renovate` is required for testRenovate to run at all. The workflow's + job is gated on this label, so without it nothing runs - it's not just a + time-saving option. See below. +* `browserstack` By default browserstack tests are never run on PRs even if + `BROWSERSTACK_TESTS_ENABLED`=true. Add this label if a PR should also run + browserstack tests. This is useful if a PR includes significant + theme changes. Less "expensive" standard CodeTests or Playwright tests. So + use this with care. + ⚠️ This label currently gates Playwright tests on PR review apps too, not + just BrowserStack. Both workflows call the same `decide-test-run` action, + which defaults its PR-label check to `browserstack`. Without the label, + neither suite runs against the review app. This gate does not apply to the + edge/main push path, where both suites always run. ### Drainpipe Example This automatically loads all the lullabot/drainpipe actions that are needed -for the specific tasks. There is no need to call drainpipe separately unless +for the specific tasks. There is no need to call Drainpipe separately unless you have specific additional requirements for those. Just be sure not to overlap functionality. +⚠️ Note that the PlaywrightTests and BrowserstackTests must be merged to the +root branch of the repo before they can be run on any PR. This is a +fundamental requirement of GitHub. This is generally acceptable especially +for Browserstack since it should be used sparingly. + ```json { - "code_testing": { - "github": { - "drainpipe": [ - "PlaywrightTests", - "BrowserStackTests", - "PantheonBuildEdge", - "PantheonBuildMain", - "PantheonReviewApps", - "CodeTests", - "LockDiff" - ] + "extras": [ + { + "code_testing": { + "github": { + "drainpipe": [ + "PlaywrightTests", + "BrowserStackTests", + "PantheonBuildEdge", + "PantheonBuildMain", + "PantheonReviewApps", + "CodeTests", + "LockDiff" + ] + } + } } - } + ] } ``` +#### Anatomy of the Workflows + +##### Playwright and Browserstack Tests + +Playwright and BrowserStack tests depend on at least one of the "Pantheon*" +workflows completing, and run against a Pantheon environment. There are two +independent paths: + +- **Push to edge/main**: the matching `Pantheon Build` workflow deploys, then + tests run automatically against that environment. A push to `main` tests + against the `dev` multidev, not a `main` one - that's Pantheon's own + environment naming, not something this plugin adds. +- **Pull requests**: `Pantheon Review Apps` only builds a multidev if the PR + has the `build multidev` label, and tests then only run against it if the + PR also has the `browserstack` label (see PR Labels above). + +⚠️ The push path matches on the literal workflow `name:` string ("Pantheon +Build " plus the configured primary branch). If you rename +`drainpipePantheonBuildEdge.yml` or `drainpipePantheonBuildMain.yml`, update +`decide-test-run`'s `build-workflow-prefix` input to match, or tests will +silently stop running after every deploy. + +These are set up to use two different scripts in your +tests/playwright/package.json file described below. PlaywrightTests is +expecting a script called `test:ci-playwright` and the BrowserStackTests +expect a script called `test:browserstack` (see below). + +CodeTests and LockDiff can be run independently of a build. + +##### CodeTests + +CodeTests is not necessary as all of what it does can be run locally. ⚠️**It +is, however, the only workflow that runs PHP-based tests.** Adding +it to your repo, can be a fairly inexpensive way to verify that code is +working at a bare level. It runs the full suite of tests a site may have +from Unit to ExistingSite tests, a code check, and any playwright tests +against a DDEV environment on GitHub. This workflow expects a playwright +test called `test:ci-ddev` (see below). To run this on a PR you must add the +label `playwright-tests`. + +Writing php existing-site and unit tests are beyond the scope of this README +but here are some expectations you will need to set up. You can learn more +at [Running PHPUnit Tests](https://www.drupal.org/docs/develop/automated-testing/phpunit-in-drupal/running-phpunit-tests) + +The CodeTests workflow expects the following tasks: + +* test:existing-site +* test:unit + +The assumption is that _all_ your custom modules are annotated with at least +one common group. Replace [your_group] in the code below with whatever that +group name is. + + +```yml +tasks: + test:existing-site: + desc: "Runs the test suite in development mode" + cmds: + - echo "🔬 Running existing-site tests in development mode..." + - exec ./vendor/bin/phpunit --testsuite existing-site --group [your_group] + + test:unit: + desc: "Runs the unit tests in development mode" + cmds: + - echo "🔬 Running unit tests in development mode..." + - exec ./vendor/bin/phpunit --testsuite unit --group [your_group] +``` + +You also need to run the following (or, at a bare minimum, `drupal/core-dev`). + +```shell +composer require --dev drupal/core-dev --with-all-dependencies +composer require --dev weitzman/drupal-test-traits --with-all-dependencies +composer require --dev weitzman/logintrait --with-all-dependencies +``` + #### testRenovate -This is required by drainpipe, but may not actually get installed. If you -want to use this and you have instructions in a renovate.json and have it -configured on Github, you need to add the following to `extra.code_testing`. +This is installed by Drainpipe, but may not actually get installed. If you +want to use this, and you have instructions in a renovate.json and have it +configured on GitHub, you need to add the following to `extra.code_testing`. + +testRenovate runs on pull requests (opened, synchronized, reopened, or +labeled), and its job only runs if the PR also carries the `test renovate` +label - without it, the job is skipped entirely. ```json { - "test": [ - "Renovate", - ] + "extras": [ + { + "code_testing": { + "github": { + "test": [ + "Renovate" + ] + } + } + } + ] } ``` ### Deployment Example -For sites that use a deployment solution such as pantheon's github builder, +For sites that use a deployment solution such as pantheon's GitHub builder, the options are simpler. ```json { - "code_testing": { - "github": { - "deployment": [ - "PlaywrightTests", - "BrowserStackTests", - "CodeTests", - "LockDiff" - ] +"extras":[ + { + "code_testing": { + "github": { + "deployment": [ + "PlaywrightTests", + "BrowserStackTests", + "CodeTests", + "LockDiff" + ] + } } - } -} + }]} ``` +### Workflow file patterns + Each entry maps to a workflow file using the pattern `{context}{Name}.yml`. The example above would scaffold: - `drainpipePlaywrightTests.yml` -- `deploymmentBrowserStackTests.yml` +- `deploymentBrowserStackTests.yml` - `deploymentCodeTests.yml` - `testRenovate.yml` -It's entirely possible to skip the extras:code_testing" section and just copy -the desired files from ./vendor/ten7/scaffold/.github/workflows, but this +It's entirely possible to skip the "extras:code_testing" section and just copy +the desired files from `./vendor/ten7/scaffold/.github/workflows`, but this should not be necessary. If there need to be new changes, they should be made here with broadly abstracted steps and making use of updates users can make in their repos (secrets/variables/labels) or with specifically required -scripts test/playwright/package.json +scripts `test/playwright/package.json` ## Workflow contexts | Context | Use when | |--------------|--------------------------------------------------------------| -| `drainpipe` | The project uses drainpipe for its build and deploy pipeline | -| `deployment` | The project uses a non-drainpipe deployment pipeline | +| `drainpipe` | The project uses Drainpipe for its build and deploy pipeline | +| `deployment` | The project uses a non-Drainpipe deployment pipeline | | `test` | Standalone test utilities (e.g., Renovate) | ## Available workflows -See the directory scaffold/.github/workflows +See the directory `scaffold/.github/workflows`. ## Actions All actions under `.github/actions/code-testing/` are scaffolded unconditionally. They have no effect unless referenced by a workflow. Each -action has a description defining what it does +action has a description defining what it does. This plugin also installs certain lullabot/drainpipe actions as needed. @@ -152,13 +331,33 @@ This plugin also installs certain lullabot/drainpipe actions as needed. Workflows not declared in `code_testing` are never written to `.github/workflows/`, so they never appear in the GitHub Actions tab. This keeps -Pantheon-specific or drainpipe-specific workflows out of projects that don't use +Pantheon-specific or Drainpipe-specific workflows out of projects that don't use them. ## How to use with Playwright and BrowserStack testing. -This project expects tests to be in a directory `./test/playwright`. In the -package.json file you will need to create scripts that you want to run as +This project expects tests to be in a directory `./test/playwright`. + +To install playwright, create a directory in the repo root: + +```shell +mkdir -p test/playwright +``` + +Switch to the new directory and run: + +```shell +npm init playwright@latest +``` + +Don't add the GitHub action if requested. This repo handles that work. For best +results, answer all other questions with the defaults. + +Specifics on how to write your tests and what to test for is beyond the +scope for this repo. Each site may have different requirements and levels of +thoroughness. + +In the package.json file you will need to create scripts that you want to run as follows: * test:ci-ddev @@ -169,12 +368,29 @@ These tests should define what should be run by npm. An example might be: ```json { - "test:ci-ddev": "playwright test --project=func-chromium", - "test:ci-pantheon": "playwright test --grep='@smoke' --project=func-chromium", - "test:browserstack": "BROWSERSTACK_BUILD=true browserstack-node-sdk playwright test --grep='@browserstack'" + "scripts": { + "test:ci-ddev": "playwright test --project=func-chromium", + "test:ci-pantheon": "playwright test --grep='@smoke' --project=func-chromium", + "test:browserstack": "BROWSERSTACK_BUILD=true browserstack-node-sdk playwright test --grep='@browserstack'" + } } - ``` -The test:browserstack should be configured differently based on the rules for -developing with BrowserStack that are beyond the scope of this repo. \ No newline at end of file +The `test:browserstack` should be configured differently based on the rules for +developing with BrowserStack that are beyond the scope of this repo. + +### Testing suggestions + +These are some simple guidelines to help you with making the best use of +this tool. + +* If you have a paid Browserstack Automate account, you probably don't need to +include the `PlaywrightTests` workflow. +* It is unlikely to be useful to run both `PlaywrightTests` and include + `playwright-tests` as a label in your repo to run them on `CodeTests` as + well. +* Visual regression tests are notoriously flaky. It may be useful to include in +each test a warming function to load the page before actually testing it. +* Visual regression tests can also be very time-consuming as both the GitHub +runner VMs and the Pantheon Multidevs are much slower than a live site or your +local DDEV environment. \ No newline at end of file diff --git a/composer.json b/composer.json index 62dcc94..1962f43 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "composer-plugin", "license": "GPL-2.0-or-later", "require": { - "php": ">=8.1", + "php": ">=8.3", "composer-plugin-api": "^2.0", "lullabot/drainpipe": "^6.0" }, diff --git a/scaffold/.github/actions/code-testing/browserstack/test/action.yml b/scaffold/.github/actions/code-testing/browserstack/test/action.yml index 8f3925d..39ada18 100644 --- a/scaffold/.github/actions/code-testing/browserstack/test/action.yml +++ b/scaffold/.github/actions/code-testing/browserstack/test/action.yml @@ -14,28 +14,17 @@ inputs: target-url: description: "The name of the Pantheon site to test against." required: true - pantheon-review-username: + basic-auth-user: description: "Username for basic auth to access Pantheon review apps. Should be set as a secret named PANTHEON_REVIEW_USERNAME." required: true - pantheon-review-password: + basic-auth-pass: description: "Password for basic auth to access Pantheon review apps. Should be set as a secret named PANTHEON_REVIEW_PASSWORD." required: true runs: using: composite steps: - - name: Checkout actions - uses: actions/checkout@v6 - - - name: Verify site name is set - shell: bash - run: | - if [ -z "$PANTHEON_SITE_NAME" ]; then - echo "::error::PANTHEON_SITE_NAME is empty. Set it under Settings → Secrets and variables → Actions (either tab)." - exit 1 - fi - echo "Using PANTHEON_SITE_NAME=$PANTHEON_SITE_NAME" - name: Setup Node.js - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version-file: '.nvmrc' cache: 'npm' @@ -46,18 +35,24 @@ runs: run: | cd test/playwright npm ci - npx playwright install --with-deps chromium chromium-headless-shell + + - name: Ensure BrowserStack config directory exists + shell: bash + run: mkdir -p "$HOME/.browserstack" - name: Run BrowserStack tests shell: bash run: | + echo "running tests on ${BASE_URL}" cd test/playwright mkdir -p test-results - npm run test:browserstack -- --ignore-snapshots + npm run test:browserstack env: NODE_OPTIONS: --disable-warning=DEP0205 BASE_URL: ${{ inputs.target-url }} - BASIC_AUTH_USER: ${{ inputs.pantheon-review-username }} - BASIC_AUTH_PASS: ${{ inputs.patheon-review-password }} - BROWSERSTACK_USERNAME: ${{ inputs.browserstack-user-name}} + BASIC_AUTH_USER: ${{ inputs.basic-auth-user }} + BASIC_AUTH_PASS: ${{ inputs.basic-auth-pass }} + BROWSERSTACK_USERNAME: ${{ inputs.browserstack-username }} BROWSERSTACK_ACCESS_KEY: ${{ inputs.browserstack-access-key }} + BROWSERSTACK_BUILD_NAME: ${{ inputs.target-url }} + BROWSERSTACK_LOCAL: false diff --git a/scaffold/.github/actions/code-testing/drupal/index-search/action.yml b/scaffold/.github/actions/code-testing/drupal/index-search/action.yml index ac91526..6016249 100644 --- a/scaffold/.github/actions/code-testing/drupal/index-search/action.yml +++ b/scaffold/.github/actions/code-testing/drupal/index-search/action.yml @@ -4,8 +4,8 @@ inputs: pantheon-site-name: description: 'The site name, such as bps-district' required: true - pr-number: - description: "The Pull Request number" + multidev-name: + description: "The name of the environment: dev, edge, pr-[x]" required: true machine-token: description: "The machine token needed to authorize terminus" @@ -18,10 +18,11 @@ runs: id: search-indexing env: PANTHEON_SITE_NAME: ${{ inputs.pantheon-site-name }} - PR_NUMBER: ${{ inputs.pr-number }} + MULTIDEV_NAME: ${{ inputs.multidev-name }} MACHINE_TOKEN: ${{ inputs.machine-token }} shell: bash run: | - drainpipe_exec "terminus auth:login --machine-token="${{env.MACHINE_TOKEN}}" && \ - terminus remote:drush ${{env.PANTHEON_SITE_NAME}}.pr-${{ env.PR_NUMBER }} -- search-api:reset-tracker && \ - terminus remote:drush ${{env.PANTHEON_SITE_NAME}}.pr-${{ github.event.pull_request.number }} -- search-api:index" + source .github/actions/drainpipe/set-env/bash_aliases + terminus auth:login --machine-token="${{ env.MACHINE_TOKEN }}" + drainpipe_exec "terminus remote:drush ${{ env.PANTHEON_SITE_NAME }}.${{ env.MULTIDEV_NAME }} -- search-api:reset-tracker" + drainpipe_exec "terminus remote:drush ${{ env.PANTHEON_SITE_NAME }}.${{ env.MULTIDEV_NAME }} -- search-api:index" diff --git a/scaffold/.github/actions/code-testing/github/decide-test-run/action.yml b/scaffold/.github/actions/code-testing/github/decide-test-run/action.yml new file mode 100644 index 0000000..e6d7b27 --- /dev/null +++ b/scaffold/.github/actions/code-testing/github/decide-test-run/action.yml @@ -0,0 +1,62 @@ +name: 'Decide if Tests Should Run' +description: 'Decides whether a workflow_run-triggered test job should proceed: always for the configured primary branch, or gated on a PR label for any other branch' + +inputs: + github-token: + description: 'GitHub token used to look up PR labels' + required: true + primary-branch: + description: 'The git branch to always test (e.g. main or edge)' + required: false + default: 'main' + pr-label: + description: 'Label required on a PR before tests run against its review app' + required: false + default: 'browserstack' + +outputs: + should-run: + description: 'Whether the calling job should proceed with testing' + value: ${{ steps.decide.outputs.should-run }} + multidev-name: + description: 'Pantheon multidev name to test against' + value: ${{ steps.decide.outputs.multidev-name }} + +runs: + using: composite + steps: + - name: Decide whether to run tests + id: decide + shell: bash + env: + GH_TOKEN: ${{ inputs.github-token }} + GH_REPO: ${{ github.repository }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + PRIMARY_BRANCH: ${{ inputs.primary-branch }} + PR_LABEL: ${{ inputs.pr-label }} + PULL_REQUESTS_JSON: ${{ toJSON(github.event.workflow_run.pull_requests) }} + run: | + if [[ "$HEAD_BRANCH" == "$PRIMARY_BRANCH" ]]; then + echo "should-run=true" >> "$GITHUB_OUTPUT" + if [[ "$PRIMARY_BRANCH" == "main" ]]; then + echo "multidev-name=dev" >> "$GITHUB_OUTPUT" + else + echo "multidev-name=$PRIMARY_BRANCH" >> "$GITHUB_OUTPUT" + fi + else + PR_NUMBER=$(echo "$PULL_REQUESTS_JSON" | jq -r '.[0].number // empty') + if [[ -z "$PR_NUMBER" ]]; then + echo "::notice::No pull request associated with branch $HEAD_BRANCH, skipping." + echo "should-run=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name') + if echo "$LABELS" | grep -qx "$PR_LABEL"; then + echo "should-run=true" >> "$GITHUB_OUTPUT" + echo "multidev-name=pr-${PR_NUMBER}" >> "$GITHUB_OUTPUT" + else + echo "::notice::PR #$PR_NUMBER is missing the '$PR_LABEL' label, skipping." + echo "should-run=false" >> "$GITHUB_OUTPUT" + fi + fi diff --git a/scaffold/.github/actions/code-testing/playwright/test/action.yml b/scaffold/.github/actions/code-testing/playwright/test/action.yml index 8faa746..79ee357 100644 --- a/scaffold/.github/actions/code-testing/playwright/test/action.yml +++ b/scaffold/.github/actions/code-testing/playwright/test/action.yml @@ -3,20 +3,16 @@ description: "Run Playwright tests against a remote environment." inputs: target-url: description: "The url to be used as BASE_URL for the scripts" - environment-username: - description: "Username for basic auth to access any site that is behind a server-level username/password. If it is not needed it will be ignored." + basic-auth-user: + description: "Username for basic auth to access Pantheon review apps. Should be set as a secret named PANTHEON_REVIEW_USERNAME." required: true - environment-password: - description: "Password for basic auth to access any site that is behind a server-level username/password. If it is not needed it will be ignored." + basic-auth-pass: + description: "Password for basic auth to access Pantheon review apps. Should be set as a secret named PANTHEON_REVIEW_PASSWORD." required: true test-script: description: "The npm script to run (defined in test/playwright/package.json). Defaults to 'test'." required: false default: "test" - test-args: - description: "Additional arguments to pass to the Playwright test. For instance --ignore-snapshots --project=func-chromium. Prefer test-script for CI contexts." - required: false - default: "" runs: using: composite @@ -32,17 +28,50 @@ runs: run: | cd test/playwright npm ci - npx playwright install --with-deps chromium chromium-headless-shell + + - name: Get installed Playwright version + id: playwright-version + shell: bash + run: | + cd test/playwright + echo "version=$(node -e "console.log(require('@playwright/test/package.json').version)")" >> $GITHUB_OUTPUT + + - name: Cache Playwright browser binaries + id: playwright-cache + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }} + + - name: Install Playwright browsers and OS dependencies + if: steps.playwright-cache.outputs.cache-hit != 'true' + shell: bash + run: | + cd test/playwright + npx playwright install --with-deps + + - name: Install OS dependencies for cached browsers + if: steps.playwright-cache.outputs.cache-hit == 'true' + shell: bash + run: | + cd test/playwright + npx playwright install-deps - name: Run Playwright tests shell: bash env: NODE_OPTIONS: --disable-warning=DEP0205 - run: cd test/playwright && mkdir -p test-results && npm run ${{ inputs.test-script }} -- ${{ inputs.test-args }} + BASE_URL: ${{ inputs.target-url }} + BASIC_AUTH_USER: ${{ inputs.basic-auth-user }} + BASIC_AUTH_PASS: ${{ inputs.basic-auth-pass }} + run: | + cd test/playwright + mkdir -p test-results + npm run ${{ inputs.test-script }} - name: Upload test results - if: ${{ !cancelled() }} - uses: actions/upload-artifact@v4 + if: ${{ always() }} + uses: actions/upload-artifact@v6 with: name: playwright-report path: test/playwright/playwright-report/ - retention-days: 10 + retention-days: 5 diff --git a/scaffold/.github/workflows/deploymentBrowserStackTests.yml b/scaffold/.github/workflows/deploymentBrowserStackTests.yml index 0cf2a87..54c3bad 100644 --- a/scaffold/.github/workflows/deploymentBrowserStackTests.yml +++ b/scaffold/.github/workflows/deploymentBrowserStackTests.yml @@ -1,27 +1,73 @@ -name: "Run Browserstack tests on Pantheon" - +name: "Run BrowserStack tests on Pantheon" +run-name: "${{ github.event.deployment_status.environment }} by @${{ github.actor }}" on: deployment_status: { } jobs: + detect-php-version: + name: Detect PHP Version + runs-on: ubuntu-latest + if: github.event.deployment_status.state == 'success' + outputs: + php-version: ${{ steps.php-version.outputs.php-version }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Read php_version from Pantheon config + id: php-version + uses: ./.github/actions/code-testing/detect-php-version Decide-If-Tests-Should-Run: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + if: github.event.deployment_status.state == 'success' outputs: should-run: ${{ steps.decide.outputs.should-run }} - multidev-name: ${{ steps.decide.outputs.multidev-name }} + multidev-name: ${{ steps.multidev.outputs.name }} steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Set multidev name + id: multidev + run: echo "name=${{ github.event.deployment_status.environment }}" | sed 's/pantheon-//' >> $GITHUB_OUTPUT - name: Decide whether to run BrowserStack tests id: decide - uses: ./.github/actions/code-testing/github/decide-test-run - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - primary-branch: ${{ vars.BROWSERSTACK_PRIMARY_BRANCH || 'main' }} - Set-Up-Tests: + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + MULTIDEV_NAME: ${{ steps.multidev.outputs.name }} + BROWSERSTACK_TESTS_ENABLED: ${{ vars.BROWSERSTACK_TESTS_ENABLED }} + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + PR_LABEL: browserstack + run: | + if [[ "$BROWSERSTACK_TESTS_ENABLED" != "true" ]]; then + echo "::notice::BrowserStack tests are disabled (BROWSERSTACK_TESTS_ENABLED is not 'true')." + echo "should-run=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if [[ -z "$BROWSERSTACK_USERNAME" || -z "$BROWSERSTACK_ACCESS_KEY" ]]; then + echo "::warning::BrowserStack credentials are not set." + echo "should-run=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if [[ "$MULTIDEV_NAME" =~ ^pr-([0-9]+)$ ]]; then + PR_NUMBER="${BASH_REMATCH[1]}" + LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name') + if echo "$LABELS" | grep -qx "$PR_LABEL"; then + echo "::notice::PR #$PR_NUMBER has the '$PR_LABEL' label, running BrowserStack tests." + echo "should-run=true" >> "$GITHUB_OUTPUT" + else + echo "::notice::PR #$PR_NUMBER is missing the '$PR_LABEL' label, skipping BrowserStack tests." + echo "should-run=false" >> "$GITHUB_OUTPUT" + fi + else + echo "::notice::$MULTIDEV_NAME is not a PR multidev, running BrowserStack tests." + echo "should-run=true" >> "$GITHUB_OUTPUT" + fi + Set-Up-and-Run-Tests: runs-on: ubuntu-latest - needs: Decide-If-Tests-Should-Run + needs: [detect-php-version, Decide-If-Tests-Should-Run] if: ${{ needs.Decide-If-Tests-Should-Run.outputs.should-run == 'true' }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -29,28 +75,28 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.4" + php-version: ${{ needs.detect-php-version.outputs.php-version }} - name: Install Terminus uses: pantheon-systems/terminus-github-actions@v1 with: pantheon-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} terminus-version: 4.3.1 - - name: Set multidev name - id: multidev - run: echo "name=${{ github.event.deployment_status.environment }}" | sed 's/pantheon-//' >> $GITHUB_OUTPUT - name: Wait for review app to respond uses: ./.github/actions/code-testing/terminus/wait-for-build with: site-name: ${{ vars.PANTHEON_SITE_NAME }} - multidev-name: ${{ steps.multidev.outputs.name }} + multidev-name: ${{ needs.Decide-If-Tests-Should-Run.outputs.multidev-name }} # Browserstack test steps go here - name: Checkout actions uses: actions/checkout@v6 + with: + ref: ${{ github.event.workflow_run.head_sha }} - name: Validate browserstack connection + id: validate-browserstack uses: ./.github/actions/code-testing/browserstack/validate with: enabled: ${{ vars.BROWSERSTACK_TESTS_ENABLED }} @@ -73,7 +119,6 @@ jobs: with: browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }} - pantheon-review-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} - pantheon-review-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} - pantheon-site-name: ${{ vars.PANTHEON_SITE_NAME }} - target-url: '' \ No newline at end of file + basic-auth-pass: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + basic-auth-user: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + target-url: ${{ steps.set-url.outputs.target_url }} \ No newline at end of file diff --git a/scaffold/.github/workflows/deploymentCodeTests.yml b/scaffold/.github/workflows/deploymentCodeTests.yml index f3acd2d..8aea4b3 100644 --- a/scaffold/.github/workflows/deploymentCodeTests.yml +++ b/scaffold/.github/workflows/deploymentCodeTests.yml @@ -1,4 +1,6 @@ name: "Run Unit, Code Quality and Existing-Site Tests" +run-name: "${{ github.event.deployment_status.environment }} by @${{ github.actor }}" + on: deployment_status: {} @@ -8,6 +10,7 @@ concurrency: jobs: detect-php-version: + if: github.event.deployment_status.state == 'success' name: Detect PHP Version runs-on: ubuntu-latest outputs: @@ -153,19 +156,41 @@ jobs: path: | test-results/phpunit/ web/sites/simpletest/browser_output/ + - name: Check if Playwright should run + id: check-playwright + env: + GH_TOKEN: ${{ github.token }} + run: | + # Run Playwright on the default branch, or when the PR + # associated with this deployment has the playwright-tests label. + if [ "${{ github.event.deployment.ref }}" = "${{ github.event.repository.default_branch }}" ]; then + echo "Deployment is for the default branch." + echo "run=true" >> $GITHUB_OUTPUT + exit 0 + fi + LABELS=$(gh api "repos/${{ github.repository }}/commits/${{ github.event.deployment.sha }}/pulls" \ + --jq '[.[].labels[].name] | join(" ")') + echo "PR labels: ${LABELS}" + if echo "${LABELS}" | grep -qw 'playwright-tests'; then + echo "run=true" >> $GITHUB_OUTPUT + else + echo "run=false" >> $GITHUB_OUTPUT + fi # --- Playwright E2E Tests against DDEV environment --- - name: Get DDEV URL id: ddev-url + if: steps.check-playwright.outputs.run == 'true' run: | DDEV_URL=$(ddev describe -j | jq -r '.raw.primary_url') echo "url=${DDEV_URL}" >> $GITHUB_OUTPUT echo "DDEV URL: ${DDEV_URL}" - name: Run Playwright tests in DDEV + if: steps.check-playwright.outputs.run == 'true' uses: ./.github/actions/code-testing/playwright/test with: - environment-password: '' - environment-username: '' + basic-auth-pass: '' + basic-auth-user: '' target-url: ${{ steps.ddev-url.outputs.url }} - test-script: 'ci-ddev' + test-script: 'test:ci-ddev' diff --git a/scaffold/.github/workflows/deploymentLockDiff.yml b/scaffold/.github/workflows/deploymentLockDiff.yml index 646c1e7..e6057c0 100644 --- a/scaffold/.github/workflows/deploymentLockDiff.yml +++ b/scaffold/.github/workflows/deploymentLockDiff.yml @@ -1,4 +1,5 @@ name: "Composer Lock Diff" +run-name: "${{ github.event.deployment_status.environment }} by @${{ github.actor }}" on: deployment_status: {} diff --git a/scaffold/.github/workflows/deploymentPlaywrightTests.yml b/scaffold/.github/workflows/deploymentPlaywrightTests.yml index 2d20a37..6e9751f 100644 --- a/scaffold/.github/workflows/deploymentPlaywrightTests.yml +++ b/scaffold/.github/workflows/deploymentPlaywrightTests.yml @@ -1,4 +1,5 @@ -name: "Run playwright tests on Pantheon" +name: "Run Playwright Tests on Pantheon" +run-name: "${{ github.event.deployment_status.environment }} by @${{ github.actor }}" on: deployment_status: {} @@ -9,6 +10,8 @@ jobs: if: github.event.deployment_status.state == 'success' steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ github.event.workflow_run.head_sha }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -38,6 +41,6 @@ jobs: uses: ./.github/actions/code-testing/playwright/test with: target-url: ${{ github.event.deployment_status.environment_url }} - environment-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} - environment-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} - test-script: 'ci-pantheon' \ No newline at end of file + basic-auth-user: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + basic-auth-pass: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + test-script: 'test:ci-pantheon' \ No newline at end of file diff --git a/scaffold/.github/workflows/drainpipeBrowserStackTests.yml b/scaffold/.github/workflows/drainpipeBrowserStackTests.yml index f37ce46..7b2fd21 100644 --- a/scaffold/.github/workflows/drainpipeBrowserStackTests.yml +++ b/scaffold/.github/workflows/drainpipeBrowserStackTests.yml @@ -1,10 +1,11 @@ -name: "Run Browserstack tests on Pantheon" +name: "Run BrowserStack Tests on Pantheon" +run-name: "${{ github.event.workflow_run.head_branch }} by @${{ github.event.workflow_run.actor.login }}" on: workflow_run: workflows: - - "Pantheon Build edge" - - "Pantheon Build main" + - "Pantheon Build Edge" + - "Pantheon Build Main" - "Pantheon Review Apps" types: - completed @@ -22,6 +23,8 @@ jobs: multidev-name: ${{ steps.decide.outputs.multidev-name }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ github.event.workflow_run.head_sha }} - name: Decide whether to run BrowserStack tests id: decide @@ -36,11 +39,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 with: - php-version: "8.4" + ref: ${{ github.event.workflow_run.head_sha }} - name: Install Terminus uses: pantheon-systems/terminus-github-actions@v1 @@ -78,6 +78,6 @@ jobs: with: browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }} - pantheon-review-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} - pantheon-review-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + basic-auth-pass: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + basic-auth-user: ${{ secrets.PANTHEON_REVIEW_USERNAME }} target-url: ${{ steps.set-url.outputs.target_url }} \ No newline at end of file diff --git a/scaffold/.github/workflows/drainpipeCodeTests.yml b/scaffold/.github/workflows/drainpipeCodeTests.yml index dc41974..700bdc2 100644 --- a/scaffold/.github/workflows/drainpipeCodeTests.yml +++ b/scaffold/.github/workflows/drainpipeCodeTests.yml @@ -1,4 +1,5 @@ name: "Run Unit, Code Quality and Existing-Site Tests" +run-name: "${{ github.event_name == 'pull_request' && format('PR #{0} ({1})', github.event.pull_request.number, github.head_ref) || github.ref_name }} by @${{ github.actor }}" on: pull_request: @@ -160,17 +161,25 @@ jobs: web/sites/simpletest/browser_output/ # --- Playwright E2E Tests against DDEV environment --- + # Run Playwright on pushes to the default branch, or when the PR + # has the playwright-tests label. + - name: Check if Playwright should run + id: check-playwright + run: echo "run=${{ (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) || contains(github.event.pull_request.labels.*.name, 'playwright-tests') }}" >> $GITHUB_OUTPUT + - name: Get DDEV URL id: ddev-url + if: steps.check-playwright.outputs.run == 'true' run: | DDEV_URL=$(ddev describe -j | jq -r '.raw.primary_url') echo "url=${DDEV_URL}" >> $GITHUB_OUTPUT echo "DDEV URL: ${DDEV_URL}" - name: Run Playwright tests in DDEV + if: steps.check-playwright.outputs.run == 'true' uses: ./.github/actions/code-testing/playwright/test with: - environment-password: '' - environment-username: '' + basic-auth-pass: '' + basic-auth-user: '' target-url: ${{ steps.ddev-url.outputs.url }} - test-script: 'ci-ddev' + test-script: 'test:ci-ddev' diff --git a/scaffold/.github/workflows/drainpipeLockDiff.yml b/scaffold/.github/workflows/drainpipeLockDiff.yml index cdf118a..2099ea7 100644 --- a/scaffold/.github/workflows/drainpipeLockDiff.yml +++ b/scaffold/.github/workflows/drainpipeLockDiff.yml @@ -1,4 +1,5 @@ name: "Composer Lock Diff" +run-name: "PR #${{ github.event.pull_request.number }} (${{ github.head_ref }}) by @${{ github.actor }}" on: pull_request: diff --git a/scaffold/.github/workflows/drainpipePantheonBuildEdge.yml b/scaffold/.github/workflows/drainpipePantheonBuildEdge.yml index 0155130..f86e877 100644 --- a/scaffold/.github/workflows/drainpipePantheonBuildEdge.yml +++ b/scaffold/.github/workflows/drainpipePantheonBuildEdge.yml @@ -1,4 +1,5 @@ -name: "Pantheon Build edge" +name: "Pantheon Build Edge" +run-name: "${{ github.ref_name }} by @${{ github.actor }}" on: push: @@ -63,6 +64,12 @@ jobs: site-name: ${{ secrets.PANTHEON_SITE_NAME }} branch: edge + - name: Import configuration and run updates + uses: ./.github/actions/drainpipe/pantheon/update + with: + site-name: ${{ secrets.PANTHEON_SITE_NAME }} + environment: edge + - name: Install Terminus uses: pantheon-systems/terminus-github-actions@v1 with: @@ -75,9 +82,9 @@ jobs: multidev-name: edge - name: Run indexing if it is needed. - if: ${{ env.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} + if: ${{ vars.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} uses: ./.github/actions/code-testing/drupal/index-search with: machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} pantheon-site-name: ${{ secrets.PANTHEON_SITE_NAME }} - pr-number: edge \ No newline at end of file + multidev-name: edge \ No newline at end of file diff --git a/scaffold/.github/workflows/drainpipePantheonBuildMain.yml b/scaffold/.github/workflows/drainpipePantheonBuildMain.yml index aa7a65c..8d9d9fe 100644 --- a/scaffold/.github/workflows/drainpipePantheonBuildMain.yml +++ b/scaffold/.github/workflows/drainpipePantheonBuildMain.yml @@ -1,4 +1,5 @@ -name: "Pantheon Build main" +name: "Pantheon Build Main" +run-name: "${{ github.ref_name }} by @${{ github.actor }}" on: push: @@ -58,6 +59,12 @@ jobs: site-name: ${{ secrets.PANTHEON_SITE_NAME }} branch: master + - name: Import configuration and run updates + uses: ./.github/actions/drainpipe/pantheon/update + with: + site-name: ${{ secrets.PANTHEON_SITE_NAME }} + environment: dev + - name: Install Terminus uses: pantheon-systems/terminus-github-actions@v1 with: @@ -70,9 +77,9 @@ jobs: multidev-name: dev - name: Run indexing if it is needed. - if: ${{ env.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} + if: ${{ vars.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} uses: ./.github/actions/code-testing/drupal/index-search with: machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} pantheon-site-name: ${{ secrets.PANTHEON_SITE_NAME }} - pr-number: dev \ No newline at end of file + multidev-name: dev \ No newline at end of file diff --git a/scaffold/.github/workflows/drainpipePantheonReviewApps.yml b/scaffold/.github/workflows/drainpipePantheonReviewApps.yml index b1e20b9..b371c90 100644 --- a/scaffold/.github/workflows/drainpipePantheonReviewApps.yml +++ b/scaffold/.github/workflows/drainpipePantheonReviewApps.yml @@ -1,4 +1,5 @@ name: "Pantheon Review Apps" +run-name: "PR #${{ github.event.pull_request.number }} (${{ github.head_ref }}) by @${{ github.actor }}" on: pull_request: @@ -28,6 +29,15 @@ jobs: ${{ runner.os }}-composer- - uses: ./.github/actions/drainpipe/set-env + - name: Add Multidev URL to PR + uses: ./.github/actions/code-testing/github/add-pr-url + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + pr-number: ${{ github.event.pull_request.number }} + site-name: ${{ vars.PANTHEON_SITE_NAME }} + lock-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + lock-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + - uses: ./.github/actions/drainpipe/validate-terminus-timeout with: terminus_timeout_limit: ${{ vars.TERMINUS_TIMEOUT_LIMIT }} @@ -66,7 +76,7 @@ jobs: - name: Configure review app for testing env: - SITE_NAME: ${{ vars.PANTHEON_SITE_NAME || secrets.PANTHEON_SITE_NAME }} + SITE_NAME: ${{ vars.PANTHEON_SITE_NAME }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | MULTIDEV_ENV="pr-${PR_NUMBER}" @@ -84,18 +94,10 @@ jobs: site-name: ${{ secrets.PANTHEON_SITE_NAME }} - name: Run indexing if it is needed. - if: ${{ env.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} + if: ${{ vars.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} uses: ./.github/actions/code-testing/drupal/index-search with: machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} pantheon-site-name: ${{ secrets.PANTHEON_SITE_NAME }} - pr-number: pr-${{ github.event.pull_request.number }} + multidev-name: pr-${{ github.event.pull_request.number }} - - name: Add Multidev URL to PR - uses: ./.github/actions/code-testing/github/add-pr-url - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - pr-number: ${{ github.event.pull_request.number }} - site-name: ${{ vars.PANTHEON_SITE_NAME || secrets.PANTHEON_SITE_NAME }} - lock-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} - lock-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} diff --git a/scaffold/.github/workflows/drainpipePlaywrightTests.yml b/scaffold/.github/workflows/drainpipePlaywrightTests.yml index 8106c35..71aaf2e 100644 --- a/scaffold/.github/workflows/drainpipePlaywrightTests.yml +++ b/scaffold/.github/workflows/drainpipePlaywrightTests.yml @@ -1,176 +1,63 @@ -name: "Run Unit, Code Quality and Existing-Site Tests" +name: "Run Playwright Tests on Pantheon" +run-name: "${{ github.event.workflow_run.head_branch }} by @${{ github.event.workflow_run.actor.login }}" on: - pull_request: - types: [opened, synchronize, reopened] - push: - branches: - - edge - - main + workflow_run: + workflows: + - "Pantheon Build Edge" + - "Pantheon Build Main" + - "Pantheon Review Apps" + types: + - completed concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true +permissions: + contents: read + pull-requests: read + jobs: - detect-php-version: - name: Detect PHP Version + get-multidev-name: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} outputs: - php-version: ${{ steps.php-version.outputs.php-version }} - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Read php_version from Pantheon config - id: php-version - uses: ./.github/actions/code-testing/detect-php-version - - # These jobs run in parallel - they don't need the deployment. Just composer. - unit-tests: - name: Unit Tests - runs-on: ubuntu-latest - needs: detect-php-version + should-run: ${{ steps.name.outputs.should-run }} + multidev-name: ${{ steps.name.outputs.multidev-name }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 with: - php-version: ${{ needs.detect-php-version.outputs.php-version }} - extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, dom, filter, gd, json, mbstring, pdo - coverage: none - - # Install composer dependencies to ensure autoloader - # is up to date and vendor/bin/phpunit is available - - name: Install Composer dependencies - run: composer install --no-progress --prefer-dist --optimize-autoloader - - - name: Run Unit Tests - run: | - mkdir -p test-results - ./vendor/bin/phpunit -c phpunit.xml --testsuite=unit --log-junit test-results/phpunit-unit.xml + ref: ${{ github.event.workflow_run.head_sha }} - - name: Upload Test Results - uses: actions/upload-artifact@v6 - if: always() + - name: Get multidev name + id: name + uses: ./.github/actions/code-testing/github/decide-test-run with: - name: unit-test-results - path: test-results/unit/ - - code-quality: - name: Code Quality + github-token: ${{ secrets.GITHUB_TOKEN }} + primary-branch: ${{ vars.BROWSERSTACK_PRIMARY_BRANCH || 'main' }} + pr-label: 'build multidev' + run-playwright-tests: runs-on: ubuntu-latest - needs: detect-php-version + needs: get-multidev-name + if: needs.get-multidev-name.outputs.should-run == 'true' steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ needs.detect-php-version.outputs.php-version }} - extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, dom, filter, gd, json, mbstring, pdo - coverage: none - - - name: Install Composer dependencies - run: composer install --no-progress --prefer-dist --optimize-autoloader - - - name: Run PHPCS - run: ./vendor/bin/phpcs --report=checkstyle --report-file=phpcs-report.xml || true - - - name: Upload PHPCS Report - uses: actions/upload-artifact@v6 - if: always() - with: - name: phpcs-report - path: phpcs-report.xml - - # ExistingSite tests require a full Drupal environment with database - # This runs in parallel with deployment - uses synced DB, not multidev. - existing-site-tests: - name: ExistingSite Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: ${{ github.workspace }}/.ddev/.drainpipe-composer-cache - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Install and Start DDEV - uses: ./.github/actions/drainpipe/ddev - with: - git-name: Drainpipe Bot - git-email: no-reply@example.com - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }} - - - name: Install Dependencies - run: ddev composer install --no-progress --prefer-dist --optimize-autoloader - - - name: Configure Pantheon Credentials - run: | - # Add Pantheon credentials to DDEV web environment - ddev config --web-environment-add="PANTHEON_TOKEN=${{ secrets.TERMINUS_MACHINE_TOKEN }}" - ddev config --web-environment-add="PANTHEON_SITE_ID=${{ secrets.PANTHEON_SITE_NAME }}" - ddev config --web-environment-add="TERMINUS_MACHINE_TOKEN=${{ secrets.TERMINUS_MACHINE_TOKEN }}" - ddev restart - - - name: Sync Database from Pantheon - run: ddev task sync - - - name: Run Drupal Updates - run: ddev drush deploy - - - name: Enable Stage File Proxy - run: | - # Enable stage_file_proxy so tests can access images from remote site - ddev drush pm:enable stage_file_proxy -y - # Verify it's enabled - ddev drush pm:list --filter=stage_file_proxy --status=enabled - - - name: Reindex Solr - if: ${{ vars.TESTING_NEEDS_SEARCH_INDEXING == 'true' }} - run: | - # Reindex Solr so search tests have fresh data - ddev drush search-api:reset-tracker - ddev drush search-api:index - - - name: Install theme dependencies - run: ddev task assets:prod - - - name: Run ExistingSite Tests - run: ddev task test:existing-site - - - name: Upload ExistingSite Test Results - uses: actions/upload-artifact@v6 - if: always() - with: - name: existing-site-test-results - path: test-results/phpunit/ - - - name: Upload Browser Output on Failure - uses: actions/upload-artifact@v6 - if: failure() with: - name: existing-site-browser-output - path: | - test-results/phpunit/ - web/sites/simpletest/browser_output/ + ref: ${{ github.event.workflow_run.head_sha }} - # --- Playwright E2E Tests against DDEV environment --- - - name: Get DDEV URL - id: ddev-url + - name: Set target URL + shell: bash + id: set-url + env: + PANTHEON_SITE_NAME: ${{ vars.PANTHEON_SITE_NAME }} + MULTIDEV_NAME: ${{ needs.get-multidev-name.outputs.multidev-name }} run: | - DDEV_URL=$(ddev describe -j | jq -r '.raw.primary_url') - echo "url=${DDEV_URL}" >> $GITHUB_OUTPUT - echo "DDEV URL: ${DDEV_URL}" + echo "target_url=https://${MULTIDEV_NAME}-${PANTHEON_SITE_NAME}.pantheonsite.io" >> "$GITHUB_OUTPUT" - - name: Run Playwright tests in DDEV + - name: Run Playwright tests in Pantheon environment. uses: ./.github/actions/code-testing/playwright/test with: - environment-password: '' - environment-username: '' - target-url: ${{ steps.ddev-url.outputs.url }} + basic-auth-pass: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + basic-auth-user: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + target-url: ${{ steps.set-url.outputs.target_url }} test-script: 'test:ci-pantheon' \ No newline at end of file diff --git a/scaffold/.github/workflows/testRenovate.yml b/scaffold/.github/workflows/testRenovate.yml index c9b519a..3e12086 100644 --- a/scaffold/.github/workflows/testRenovate.yml +++ b/scaffold/.github/workflows/testRenovate.yml @@ -1,8 +1,9 @@ -name: Test Renovate settings +name: "Test Renovate Settings" +run-name: "${{ github.ref_name }} by @${{ github.actor }}" + on: - push: - branches: - - main + pull_request: + types: [opened, synchronize, reopened, labeled] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}