From a33924d268f964edda39b880046875ec5515cd43 Mon Sep 17 00:00:00 2001 From: Sally Young Date: Fri, 16 Aug 2024 16:46:34 +0100 Subject: [PATCH] Issue #508: Add templates for static and functional tests (#652) * Issue #508: Add templates for static and functional tests * Issue #508: Fix file name * Fallback to build:dev * Update README * Set concurrency --- README.md | 19 +++++++ scaffold/github/workflows/TestFunctional.yml | 56 ++++++++++++++++++++ scaffold/github/workflows/TestStatic.yml | 43 +++++++++++++++ src/ScaffoldInstallerPlugin.php | 8 +++ 4 files changed, 126 insertions(+) create mode 100644 scaffold/github/workflows/TestFunctional.yml create mode 100644 scaffold/github/workflows/TestStatic.yml diff --git a/README.md b/README.md index 1e8fc04e..90bf23b6 100644 --- a/README.md +++ b/README.md @@ -391,6 +391,25 @@ They are composite actions which can be used in any of your workflows e.g. Tests can be run locally with [act](https://github.com/nektos/act): `act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:runner-latest -j Static-Tests` +### Tests +Workflows for running static and functional tests can be added with the following +configuration: +```json +"extra": { + "drainpipe": { + "github": ["TestStatic", "TestFunctional"] + } +} +``` + +The build process for the functional tests will use `task build:ci:functional`, +falling back to `task build:dev`, and then `task build`. The static tests +should not require a build step. + +These workflow flies will continue to be managed by Drainpipe and cannot be +overridden. If you wish to do so then it's recommended you maintain your own +workflows for testing. + ### Security ```json "extra": { diff --git a/scaffold/github/workflows/TestFunctional.yml b/scaffold/github/workflows/TestFunctional.yml new file mode 100644 index 00000000..d47129a2 --- /dev/null +++ b/scaffold/github/workflows/TestFunctional.yml @@ -0,0 +1,56 @@ +name: "Functional Tests" + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Functional-Tests: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.ddev/.drainpipe-composer-cache + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - uses: ./.github/actions/drainpipe/set-env + + - 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: Build Project + run: | + ddev composer install + if ddev task --list | grep -q "build:ci:functional"; then + ddev task build:ci:functional + elif ddev task --list | grep -q "build:dev"; then + ddev task build:dev + else + ddev task build + fi + + - name: Run Functional Tests + run: ddev task test:functional + + - name: Upload test artifacts + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: test_result + path: test_result diff --git a/scaffold/github/workflows/TestStatic.yml b/scaffold/github/workflows/TestStatic.yml new file mode 100644 index 00000000..dc7eb88a --- /dev/null +++ b/scaffold/github/workflows/TestStatic.yml @@ -0,0 +1,43 @@ +name: "Static Tests" + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Static-Tests: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.ddev/.drainpipe-composer-cache + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - uses: ./.github/actions/drainpipe/set-env + + - name: Install and Start DDEV + uses: ./.github/actions/drainpipe/ddev + + - name: Install Project + run: ddev composer install + + - name: Run Static Tests + run: ddev task test:static + + - name: Upload test artifacts + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: test_result + path: test_result diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index 91735ebe..6283de4e 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -337,6 +337,14 @@ private function installGitHubActions(string $scaffoldPath): void { $fs->ensureDirectoryExists('./.github/workflows'); $fs->copy("$scaffoldPath/github/workflows/Security.yml", './.github/workflows/Security.yml'); } + else if ($github === 'TestStatic') { + $fs->ensureDirectoryExists('./.github/workflows'); + $fs->copy("$scaffoldPath/github/workflows/TestStatic.yml", './.github/workflows/TestStatic.yml'); + } + else if ($github === 'TestFunctional') { + $fs->ensureDirectoryExists('./.github/workflows'); + $fs->copy("$scaffoldPath/github/workflows/TestFunctional.yml", './.github/workflows/TestFunctional.yml'); + } } }