Skip to content

Commit

Permalink
Issue #508: Add templates for static and functional tests (#652)
Browse files Browse the repository at this point in the history
* Issue #508: Add templates for static and functional tests

* Issue #508: Fix file name

* Fallback to build:dev

* Update README

* Set concurrency
  • Loading branch information
justafish authored Aug 16, 2024
1 parent 4d53653 commit a33924d
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
56 changes: 56 additions & 0 deletions scaffold/github/workflows/TestFunctional.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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
43 changes: 43 additions & 0 deletions scaffold/github/workflows/TestStatic.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down

0 comments on commit a33924d

Please sign in to comment.