Skip to content

Commit 7b0e443

Browse files
committed
feat: Add reusable workflow for extension testing
Add a reusable workflow that handles database services (PostgreSQL, MySQL) so extensions don't need to define them manually. The workflow accepts individual inputs for rails_versions, ruby_versions, solidus_branches, and databases with sensible defaults. This provides a simpler alternative to the composite action while maintaining backwards compatibility.
1 parent 3000404 commit 7b0e443

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed

.github/workflows/test.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Test Solidus Extension
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
rails_versions:
7+
description: 'Rails versions to test (JSON array)'
8+
type: string
9+
default: '["8.0", "7.2"]'
10+
ruby_versions:
11+
description: 'Ruby versions to test (JSON array)'
12+
type: string
13+
default: '["3.4"]'
14+
solidus_branches:
15+
description: 'Solidus branches to test (JSON array)'
16+
type: string
17+
default: '["v4.6", "v4.5"]'
18+
databases:
19+
description: 'Databases to test (JSON array): postgresql, mysql, sqlite'
20+
type: string
21+
default: '["postgresql", "mysql", "sqlite"]'
22+
23+
jobs:
24+
test:
25+
runs-on: ubuntu-24.04
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
rails_version: ${{ fromJSON(inputs.rails_versions) }}
30+
ruby_version: ${{ fromJSON(inputs.ruby_versions) }}
31+
solidus_branch: ${{ fromJSON(inputs.solidus_branches) }}
32+
database: ${{ fromJSON(inputs.databases) }}
33+
34+
services:
35+
postgres:
36+
image: postgres:16
37+
env:
38+
POSTGRES_HOST_AUTH_METHOD: trust
39+
options: >-
40+
--health-cmd="pg_isready"
41+
--health-interval=10s
42+
--health-timeout=5s
43+
--health-retries=5
44+
ports:
45+
- 5432:5432
46+
mysql:
47+
image: mysql:8
48+
env:
49+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
50+
options: >-
51+
--health-cmd="mysqladmin ping"
52+
--health-interval=10s
53+
--health-timeout=5s
54+
--health-retries=5
55+
ports:
56+
- 3306:3306
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Run extension tests
62+
uses: solidusio/test-solidus-extension@main
63+
with:
64+
database: ${{ matrix.database }}
65+
rails-version: ${{ matrix.rails_version }}
66+
ruby-version: ${{ matrix.ruby_version }}
67+
solidus-branch: ${{ matrix.solidus_branch }}

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
11
# Test Solidus Extension GitHub action
22

3-
A GitHub action for testing Solidus extensions
3+
GitHub actions and workflows for testing Solidus extensions.
44

5-
## Example configuration
5+
## Usage
6+
7+
### Reusable Workflow (Recommended)
8+
9+
The simplest way to test your extension. The reusable workflow handles database services and provides a sensible default test matrix:
10+
11+
```yaml
12+
name: Test
13+
14+
on:
15+
push:
16+
branches: [main]
17+
pull_request:
18+
19+
jobs:
20+
test:
21+
uses: solidusio/test-solidus-extension/.github/workflows/test.yml@main
22+
```
23+
24+
#### Inputs
25+
26+
| Input | Description | Default |
27+
|-------|-------------|---------|
28+
| `rails_versions` | Rails versions (JSON array) | `["8.0", "7.2"]` |
29+
| `ruby_versions` | Ruby versions (JSON array) | `["3.4"]` |
30+
| `solidus_branches` | Solidus branches (JSON array) | `["v4.6", "v4.5"]` |
31+
| `databases` | Databases (JSON array) | `["postgresql", "mysql", "sqlite"]` |
32+
33+
#### Custom Matrix
34+
35+
Override any input to customize the test matrix:
36+
37+
```yaml
38+
jobs:
39+
test:
40+
uses: solidusio/test-solidus-extension/.github/workflows/test.yml@main
41+
with:
42+
rails_versions: '["7.2"]'
43+
databases: '["postgresql", "sqlite"]'
44+
```
45+
46+
### Composite Action
47+
48+
For full control over your workflow, use the composite action directly. This requires you to define database services yourself.
49+
50+
#### Inputs
51+
52+
| Input | Description | Required | Default |
53+
|-------|-------------|----------|---------|
54+
| `ruby-version` | Ruby version to use | Yes | `3.3` |
55+
| `rails-version` | Rails version to use | Yes | `7.2` |
56+
| `solidus-branch` | Solidus branch to use | Yes | `main` |
57+
| `database` | Database to use (`sqlite`, `postgresql`, `mysql`, or `mariadb`) | Yes | `sqlite` |
58+
59+
#### Database Services
60+
61+
The composite GitHub Action **cannot define services directly**. If you need to test against PostgreSQL or MySQL/MariaDB, you must define the database service in your workflow file.
62+
63+
The action will install the necessary database client libraries automatically based on the `database` input.
64+
65+
#### Database Credentials
66+
67+
The action automatically sets the correct `DB_USERNAME` based on the database:
68+
69+
- **PostgreSQL**: `postgres` (default superuser)
70+
- **MySQL/MariaDB**: `root` (default superuser)
71+
72+
Configure your database services with passwordless access for simplicity (see example below).
73+
74+
> [!WARNING]
75+
> Rails 8.0 has a [known issue](https://github.com/rails/rails/issues/53673) with MySQL/MariaDB that causes empty `Mysql2::Error` messages. Until a fix is released, exclude the `mariadb` + Rails 8.0 combination from your test matrix.
76+
77+
#### Example Configuration
678

779
```yaml
880
name: Test

0 commit comments

Comments
 (0)