Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:

- name: Allow SQL triggers
run: |
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -prootpassword -e "set global log_bin_trust_function_creators=1;"
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] || job.services.mariadb.ports['3306'] }} -u root -prootpassword -e "set global log_bin_trust_function_creators=1;"

- run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ matrix.magento }}" ${{ inputs.magento_directory }} --no-install
shell: bash
Expand Down
46 changes: 23 additions & 23 deletions setup-install/dist/index.js

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions setup-install/src/build-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,27 @@ const MYSQL_SERVICE = {
options: '--health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3',
};

const MYSQL_ARGS = [
const MARIADB_SERVICE = {
image: 'mariadb:11.4',
env: {
MYSQL_DATABASE: 'magento_integration_tests',
MYSQL_USER: 'user',
MYSQL_PASSWORD: 'password',
MYSQL_ROOT_PASSWORD: 'rootpassword',
},
ports: ['3306:3306'],
options: '--health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3',
};

const DB_ARGS = [
'--db-host=127.0.0.1:3306',
'--db-name=magento_integration_tests',
'--db-user=user',
'--db-password=password',
];

const MYSQL_ARGS = DB_ARGS;

const OPENSEARCH_ARGS = [
'--search-engine=opensearch',
'--opensearch-host=localhost',
Expand Down Expand Up @@ -62,10 +76,25 @@ describe('buildInstallArgs', () => {
});
});

describe('mysql', () => {
describe('database', () => {
it('adds db flags when mysql service is present', () => {
const services: Services = { mysql: MYSQL_SERVICE };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...MYSQL_ARGS]);
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...DB_ARGS]);
});

it('adds db flags when mariadb service is present', () => {
const services: Services = { mariadb: MARIADB_SERVICE };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...DB_ARGS]);
});

it('prefers mariadb over mysql when both are present', () => {
const services: Services = {
mariadb: MARIADB_SERVICE,
mysql: { ...MYSQL_SERVICE, ports: ['3307:3306'] },
};
const args = buildInstallArgs(services);
expect(args).toContain('--db-host=127.0.0.1:3306');
expect(args).not.toContain('--db-host=127.0.0.1:3307');
});
});

Expand Down Expand Up @@ -135,7 +164,7 @@ describe('buildInstallArgs', () => {
});

describe('buildMysqlPrepArgs', () => {
it('uses root password and port from service config', () => {
it('uses root password and port from mysql service config', () => {
expect(buildMysqlPrepArgs(MYSQL_SERVICE)).toEqual([
'-h127.0.0.1',
'--port=3306',
Expand All @@ -145,6 +174,16 @@ describe('buildInstallArgs', () => {
]);
});

it('uses root password and port from mariadb service config', () => {
expect(buildMysqlPrepArgs(MARIADB_SERVICE)).toEqual([
'-h127.0.0.1',
'--port=3306',
'-uroot',
'-prootpassword',
'-e', 'SET GLOBAL log_bin_trust_function_creators = 1;',
]);
});

it('falls back to default port when ports is absent', () => {
const args = buildMysqlPrepArgs({ image: 'mysql:8.4' });
expect(args).toContain('--port=3306');
Expand Down
21 changes: 13 additions & 8 deletions setup-install/src/build-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ export interface ServiceConfig {

export interface Services {
mysql?: ServiceConfig;
mariadb?: ServiceConfig;
opensearch?: ServiceConfig;
elasticsearch?: ServiceConfig;
rabbitmq?: ServiceConfig;
redis?: ServiceConfig;
valkey?: ServiceConfig;
}

export const getDatabaseService = (services: Services): ServiceConfig | undefined =>
services.mariadb ?? services.mysql;

const BASE_ARGS = [
'--base-url=http://localhost/',
'--admin-user=admin',
Expand All @@ -24,9 +28,9 @@ const BASE_ARGS = [
'--backend-frontname=admin',
];

export const buildMysqlPrepArgs = (mysql: ServiceConfig): string[] => {
const rootPassword = mysql.env?.MYSQL_ROOT_PASSWORD ?? 'rootpassword';
const port = mysql.ports?.[0]?.split(':')[0] ?? '3306';
export const buildMysqlPrepArgs = (database: ServiceConfig): string[] => {
const rootPassword = database.env?.MYSQL_ROOT_PASSWORD ?? 'rootpassword';
const port = database.ports?.[0]?.split(':')[0] ?? '3306';
return ['-h127.0.0.1', `--port=${port}`, '-uroot', `-p${rootPassword}`, '-e', 'SET GLOBAL log_bin_trust_function_creators = 1;'];
};

Expand All @@ -35,13 +39,14 @@ export const buildInstallArgs = (services: Services | null): string[] => {

if (!services) return args;

if (services.mysql) {
const dbPort = services.mysql.ports?.[0]?.split(':')[0] ?? '3306';
const database = getDatabaseService(services);
if (database) {
const dbPort = database.ports?.[0]?.split(':')[0] ?? '3306';
args.push(
`--db-host=127.0.0.1:${dbPort}`,
`--db-name=${services.mysql.env?.MYSQL_DATABASE ?? 'magento'}`,
`--db-user=${services.mysql.env?.MYSQL_USER ?? 'magento'}`,
`--db-password=${services.mysql.env?.MYSQL_PASSWORD ?? 'magento'}`,
`--db-name=${database.env?.MYSQL_DATABASE ?? 'magento'}`,
`--db-user=${database.env?.MYSQL_USER ?? 'magento'}`,
`--db-password=${database.env?.MYSQL_PASSWORD ?? 'magento'}`,
);
}

Expand Down
9 changes: 5 additions & 4 deletions setup-install/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import { buildInstallArgs, buildMysqlPrepArgs, Services } from './build-command';
import { buildInstallArgs, buildMysqlPrepArgs, getDatabaseService, Services } from './build-command';

export async function run(): Promise<void> {
try {
Expand All @@ -14,9 +14,10 @@ export async function run(): Promise<void> {
}

// setup:install creates MySQL triggers, which requires log_bin_trust_function_creators=1
// when binary logging is enabled.
if (services?.mysql) {
await exec.exec('mysql', buildMysqlPrepArgs(services.mysql));
// when binary logging is enabled. The same SQL works against MariaDB.
const database = services ? getDatabaseService(services) : undefined;
if (database) {
await exec.exec('mysql', buildMysqlPrepArgs(database));
}

const args = buildInstallArgs(services);
Expand Down
2 changes: 1 addition & 1 deletion supported-version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See the [action.yml](./action.yml)
| project | The project to return the supported versions for. Allowed values are `mage-os` and `magento-open-source` | false | 'magento-open-source' |
| custom_versions | The versions you want to support, as a comma-separated string, i.e. 'magento/project-community-edition:2.3.7-p3, magento/project-community-edition:2.4.2-p2' | false | '' |
| recent_time_frame | The time frame (from today) used when `kind` is `recent`. Combination of years (y), months (m), and days (d), e.g. `2y 2m 2d`. | false | '2y' |
| include_services | Whether to include a `services` key in each matrix entry with GitHub Actions service container configurations for MySQL, search engine, RabbitMQ, and cache. | false | 'true' |
| include_services | Whether to include a `services` key in each matrix entry with GitHub Actions service container configurations for the database (MySQL or MariaDB), search engine, RabbitMQ, and cache. | false | 'true' |

## Kinds
- `currently-supported` - The currently supported Magento Open Source versions by Adobe.
Expand Down
46 changes: 23 additions & 23 deletions supported-version/dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions supported-version/src/matrix/matrix-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PackageMatrixVersion {
php: string | number,
composer: string | number,
mysql: string,
mariadb: string,
elasticsearch: string,
opensearch: string,
rabbitmq: string,
Expand Down
10 changes: 10 additions & 0 deletions supported-version/src/nightly/amend-matrix-for-next.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -36,6 +37,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand Down Expand Up @@ -63,6 +65,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -88,6 +91,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand Down Expand Up @@ -115,6 +119,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -131,6 +136,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -156,6 +162,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -172,6 +179,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand Down Expand Up @@ -199,6 +207,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand All @@ -224,6 +233,7 @@ describe('amendMatrixForNext', () => {
"php": 8.2,
"composer": "2",
"mysql": "mysql:8.0",
"mariadb": "",
"elasticsearch": "elasticsearch:8.5.3",
"opensearch": "",
"rabbitmq": "rabbitmq:3.11-management",
Expand Down
57 changes: 57 additions & 0 deletions supported-version/src/services/build-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const createTestEntry = (overrides: Partial<PackageMatrixVersion> = {}): Package
php: '8.3',
composer: '2.7.4',
mysql: 'mysql:8.4',
mariadb: '',
elasticsearch: 'elasticsearch:8.11.4',
opensearch: 'opensearchproject/opensearch:2.19.1',
rabbitmq: 'rabbitmq:4.0-management',
Expand All @@ -20,6 +21,62 @@ const createTestEntry = (overrides: Partial<PackageMatrixVersion> = {}): Package
});

describe('buildServicesForEntry', () => {
describe('database selection', () => {
it('should prefer mariadb when both are available', () => {
const entry = createTestEntry({ mariadb: 'mariadb:11.4' });
const services = buildServicesForEntry(entry);

expect(services.mariadb).toBeDefined();
expect(services.mariadb.image).toBe('mariadb:11.4');
expect(services.mysql).toBeUndefined();
});

it('should fall back to mysql when mariadb is empty', () => {
const entry = createTestEntry();
const services = buildServicesForEntry(entry);

expect(services.mysql).toBeDefined();
expect(services.mysql.image).toBe('mysql:8.4');
expect(services.mariadb).toBeUndefined();
});

it('should not include database when neither is available', () => {
const entry = createTestEntry({ mysql: '', mariadb: '' });
const services = buildServicesForEntry(entry);

expect(services.mysql).toBeUndefined();
expect(services.mariadb).toBeUndefined();
});

it('should use healthcheck.sh for mariadb', () => {
const entry = createTestEntry({ mariadb: 'mariadb:11.4' });
const services = buildServicesForEntry(entry);

expect(services.mariadb.options).toContain('--health-cmd');
expect(services.mariadb.options).toContain('healthcheck.sh');
expect(services.mariadb.options).toContain('--innodb_initialized');
});

it('should include correct mariadb env configuration', () => {
const entry = createTestEntry({ mariadb: 'mariadb:11.4' });
const services = buildServicesForEntry(entry);

expect(services.mariadb.env).toEqual({
MYSQL_DATABASE: 'magento_integration_tests',
MYSQL_USER: 'user',
MYSQL_PASSWORD: 'password',
MYSQL_ROOT_PASSWORD: 'rootpassword'
});
});

it('should include correct mariadb ports', () => {
const entry = createTestEntry({ mariadb: 'mariadb:11.4' });
const services = buildServicesForEntry(entry);

expect(services.mariadb.ports).toEqual(['3306:3306']);
});
});

describe('search engine selection', () => {
it('should prefer opensearch when both are available', () => {
const entry = createTestEntry();
Expand Down
33 changes: 29 additions & 4 deletions supported-version/src/services/build-services.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { PackageMatrixVersion, Services } from '../matrix/matrix-type';
import {
mysqlConfig,
mariadbConfig,
elasticsearchConfig,
opensearchConfig,
rabbitmqConfig,
redisConfig,
valkeyConfig
} from './service-config';

interface DatabaseChoice {
type: 'mariadb' | 'mysql';
image: string;
}

interface SearchEngineChoice {
type: 'opensearch' | 'elasticsearch';
image: string;
Expand All @@ -18,6 +24,20 @@ interface CacheChoice {
image: string;
}

/**
* Determines which database to use for a matrix entry.
* Prefers mariadb over mysql.
*/
function getDatabaseChoice(entry: PackageMatrixVersion): DatabaseChoice | null {
if (entry.mariadb && entry.mariadb.trim() !== '') {
return { type: 'mariadb', image: entry.mariadb };
}
if (entry.mysql && entry.mysql.trim() !== '') {
return { type: 'mysql', image: entry.mysql };
}
return null;
}

/**
* Determines which search engine to use for a matrix entry.
* Prefers opensearch over elasticsearch.
Expand Down Expand Up @@ -52,9 +72,14 @@ function getCacheChoice(entry: PackageMatrixVersion): CacheChoice | null {
export function buildServicesForEntry(entry: PackageMatrixVersion): Services {
const services: Services = {};

// MySQL is always included if present
if (entry.mysql && entry.mysql.trim() !== '') {
services.mysql = mysqlConfig.getConfig(entry.mysql);
// Database: prefer mariadb over mysql
const database = getDatabaseChoice(entry);
if (database) {
if (database.type === 'mariadb') {
services.mariadb = mariadbConfig.getConfig(database.image);
} else {
services.mysql = mysqlConfig.getConfig(database.image);
}
}

// Search engine: prefer opensearch over elasticsearch
Expand Down Expand Up @@ -83,4 +108,4 @@ export function buildServicesForEntry(entry: PackageMatrixVersion): Services {
}

return services;
}
}
Loading
Loading