mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
feat(setup-install): add new setup-install action (#237)
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
name: Setup Install Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch: {}
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "_test/demo-package/**"
|
||||||
|
- "setup-install/**"
|
||||||
|
- ".github/workflows/_internal-setup-install.yaml"
|
||||||
|
- "supported-version/**"
|
||||||
|
- "!(**/*.md)"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "_test/demo-package/**"
|
||||||
|
- "setup-install/**"
|
||||||
|
- ".github/workflows/_internal-setup-install.yaml"
|
||||||
|
- "supported-version/**"
|
||||||
|
- "!(**/*.md)"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compute_matrix:
|
||||||
|
if: "!startsWith(github.head_ref, 'release-please')"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.supported-version.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: ./supported-version
|
||||||
|
id: supported-version
|
||||||
|
with:
|
||||||
|
kind: currently-supported
|
||||||
|
include_services: true
|
||||||
|
|
||||||
|
setup-install:
|
||||||
|
needs: compute_matrix
|
||||||
|
strategy:
|
||||||
|
matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }}
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
services: ${{ matrix.services }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- uses: ./setup-magento
|
||||||
|
id: setup-magento
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
tools: composer:v${{ matrix.composer }}
|
||||||
|
mode: extension
|
||||||
|
magento_version: ${{ matrix.magento }}
|
||||||
|
magento_repository: "https://mirror.mage-os.org/"
|
||||||
|
composer_auth: ${{ secrets.COMPOSER_AUTH }}
|
||||||
|
|
||||||
|
- uses: ./cache-magento
|
||||||
|
with:
|
||||||
|
composer_cache_key: ${{ matrix.magento }}
|
||||||
|
|
||||||
|
- name: Add extension repository
|
||||||
|
working-directory: ${{ steps.setup-magento.outputs.path }}
|
||||||
|
run: composer config repositories.local path ${{ github.workspace }}/_test/demo-package
|
||||||
|
|
||||||
|
- name: Get package name
|
||||||
|
id: package
|
||||||
|
run: echo "name=$(jq -r .name ${{ github.workspace }}/_test/demo-package/composer.json)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Require extension
|
||||||
|
working-directory: ${{ steps.setup-magento.outputs.path }}
|
||||||
|
run: composer require "${{ steps.package.outputs.name }}:@dev" --no-install
|
||||||
|
|
||||||
|
- name: Composer install
|
||||||
|
working-directory: ${{ steps.setup-magento.outputs.path }}
|
||||||
|
run: composer install
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
|
||||||
|
COMPOSER_MIRROR_PATH_REPOS: 1
|
||||||
|
|
||||||
|
- uses: ./setup-install
|
||||||
|
with:
|
||||||
|
services: ${{ toJSON(matrix.services) }}
|
||||||
|
path: ${{ steps.setup-magento.outputs.path }}
|
||||||
@@ -33,3 +33,4 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain
|
|||||||
| [Coding Standard](./coding-standard/README.md) | A Github Action that runs the Magento Coding Standard. |
|
| [Coding Standard](./coding-standard/README.md) | A Github Action that runs the Magento Coding Standard. |
|
||||||
| [Semver Compare](./semver-compare/README.md) | A Github Action that semantically compares two versions |
|
| [Semver Compare](./semver-compare/README.md) | A Github Action that semantically compares two versions |
|
||||||
| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 |
|
| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 |
|
||||||
|
| [Setup Install](./setup-install/README.md) | A Github Action that runs `bin/magento setup:install` from the supported-version services matrix |
|
||||||
|
|||||||
Generated
+21
-5
@@ -9,7 +9,8 @@
|
|||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1"
|
"@actions/core": "^1.11.1",
|
||||||
|
"@actions/exec": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
"@actions/http-client": "^2.0.1"
|
"@actions/http-client": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/core/node_modules/@actions/exec": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
|
||||||
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
|
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
|
||||||
@@ -42,6 +43,21 @@
|
|||||||
"@actions/io": "^1.0.1"
|
"@actions/io": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@actions/core/node_modules/@actions/io": {
|
||||||
|
"version": "1.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
|
||||||
|
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@actions/exec": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/io": "^3.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
|
||||||
@@ -53,9 +69,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/io": {
|
"node_modules/@actions/io": {
|
||||||
"version": "1.1.3",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz",
|
||||||
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
|
"integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
|
|||||||
+3
-2
@@ -3,7 +3,7 @@
|
|||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"description": "Github Actions for Magento 2",
|
"description": "Github Actions for Magento 2",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "cd supported-version && npm run test && cd -",
|
"test": "cd supported-version && npm run test && cd - && cd setup-install && npm run test && cd -",
|
||||||
"release": "standard-version"
|
"release": "standard-version"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/graycoreio/github-actions-magento2#readme",
|
"homepage": "https://github.com/graycoreio/github-actions-magento2#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1"
|
"@actions/core": "^1.11.1",
|
||||||
|
"@actions/exec": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
# Setup Install
|
||||||
|
|
||||||
|
A GitHub Action that runs `bin/magento setup:install` using the services configuration from the [`supported-version`](../supported-version/README.md) matrix output. Database and service credentials are read directly from the service configuration of `supported-version`, so they stay in sync with the running containers automatically.
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
| Input | Required | Default | Description |
|
||||||
|
| ------------ | -------- | ------- | ----------------------------------------------------------- |
|
||||||
|
| `services` | No | `null` | JSON services object from `supported-version` matrix output |
|
||||||
|
| `path` | No | `.` | Path to the Magento root directory |
|
||||||
|
| `extra_args` | No | `""` | Additional arguments to append to `setup:install` |
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| Output | Description |
|
||||||
|
| --------- | --------------------------------------------------------- |
|
||||||
|
| `command` | The full `bin/magento setup:install` command that was run |
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This action is designed to work with [`supported-version`](../supported-version/README.md) (with `include_services: true`) and [`setup-magento`](../setup-magento/README.md).
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Install Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compute_matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.supported-version.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: graycoreio/github-actions-magento2/supported-version@main
|
||||||
|
id: supported-version
|
||||||
|
with:
|
||||||
|
include_services: "true"
|
||||||
|
|
||||||
|
install:
|
||||||
|
needs: compute_matrix
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
services: ${{ matrix.services }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- uses: graycoreio/github-actions-magento2/setup-magento@main
|
||||||
|
id: setup-magento
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
tools: composer:v${{ matrix.composer }}
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
|
||||||
|
|
||||||
|
- run: composer install
|
||||||
|
working-directory: ${{ steps.setup-magento.outputs.path }}
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
|
||||||
|
|
||||||
|
- uses: graycoreio/github-actions-magento2/setup-install@main
|
||||||
|
with:
|
||||||
|
services: ${{ toJSON(matrix.services) }}
|
||||||
|
path: ${{ steps.setup-magento.outputs.path }}
|
||||||
|
```
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
name: "Magento setup:install"
|
||||||
|
author: "Graycore"
|
||||||
|
description: "A GitHub Action that runs bin/magento setup:install, deriving service flags from the supported-version services matrix."
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
services:
|
||||||
|
required: false
|
||||||
|
default: "null"
|
||||||
|
description: "JSON string of the services key from the supported-version matrix entry (toJSON(matrix.services))."
|
||||||
|
|
||||||
|
path:
|
||||||
|
required: false
|
||||||
|
default: "."
|
||||||
|
description: "Path to the Magento root directory. Accepts the output of the setup-magento action."
|
||||||
|
|
||||||
|
extra_args:
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
description: "Additional raw flags to append to the setup:install command."
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
command:
|
||||||
|
description: "The full bin/magento setup:install command that was run."
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "node24"
|
||||||
|
main: "dist/index.js"
|
||||||
|
|
||||||
|
branding:
|
||||||
|
icon: "tool"
|
||||||
|
color: "orange"
|
||||||
Vendored
+69
File diff suppressed because one or more lines are too long
@@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
testMatch: ['**/*.spec.ts'],
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
verbose: true
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "@graycoreio/github-actions-magento2-setup-install",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A Github Action that runs bin/magento setup:install from the supported-version services matrix",
|
||||||
|
"main": "index.js",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "npx esbuild --outfile=dist/index.js --platform=node --bundle --minify src/index.ts",
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "0.0.0-PLACEHOLDER",
|
||||||
|
"@actions/exec": "0.0.0-PLACEHOLDER"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "0.0.0-PLACEHOLDER",
|
||||||
|
"jest": "0.0.0-PLACEHOLDER",
|
||||||
|
"ts-jest": "0.0.0-PLACEHOLDER"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
import { buildInstallArgs, buildMysqlPrepArgs, Services } from './build-command';
|
||||||
|
|
||||||
|
const BASE_ARGS = [
|
||||||
|
'--base-url=http://localhost/',
|
||||||
|
'--admin-user=admin',
|
||||||
|
'--admin-password=admin123',
|
||||||
|
'--admin-email=admin@example.com',
|
||||||
|
'--admin-firstname=Admin',
|
||||||
|
'--admin-lastname=User',
|
||||||
|
'--backend-frontname=admin',
|
||||||
|
];
|
||||||
|
|
||||||
|
const MYSQL_SERVICE = {
|
||||||
|
image: 'mysql:8.4',
|
||||||
|
env: {
|
||||||
|
MYSQL_DATABASE: 'magento_integration_tests',
|
||||||
|
MYSQL_USER: 'user',
|
||||||
|
MYSQL_PASSWORD: 'password',
|
||||||
|
MYSQL_ROOT_PASSWORD: 'rootpassword',
|
||||||
|
},
|
||||||
|
ports: ['3306:3306'],
|
||||||
|
options: '--health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3',
|
||||||
|
};
|
||||||
|
|
||||||
|
const MYSQL_ARGS = [
|
||||||
|
'--db-host=127.0.0.1:3306',
|
||||||
|
'--db-name=magento_integration_tests',
|
||||||
|
'--db-user=user',
|
||||||
|
'--db-password=password',
|
||||||
|
];
|
||||||
|
|
||||||
|
const OPENSEARCH_ARGS = [
|
||||||
|
'--search-engine=opensearch',
|
||||||
|
'--opensearch-host=localhost',
|
||||||
|
'--opensearch-port=9200',
|
||||||
|
];
|
||||||
|
|
||||||
|
const RABBITMQ_ARGS = [
|
||||||
|
'--amqp-host=localhost',
|
||||||
|
'--amqp-port=5672',
|
||||||
|
'--amqp-user=guest',
|
||||||
|
'--amqp-password=guest',
|
||||||
|
];
|
||||||
|
|
||||||
|
const CACHE_ARGS = [
|
||||||
|
'--session-save=redis',
|
||||||
|
'--session-save-redis-host=localhost',
|
||||||
|
'--session-save-redis-port=6379',
|
||||||
|
'--cache-backend=redis',
|
||||||
|
'--cache-backend-redis-server=localhost',
|
||||||
|
'--cache-backend-redis-port=6379',
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('buildInstallArgs', () => {
|
||||||
|
describe('base args', () => {
|
||||||
|
it('returns only base args when services is null', () => {
|
||||||
|
expect(buildInstallArgs(null)).toEqual(BASE_ARGS);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns only base args when services is empty', () => {
|
||||||
|
expect(buildInstallArgs({})).toEqual(BASE_ARGS);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mysql', () => {
|
||||||
|
it('adds db flags when mysql service is present', () => {
|
||||||
|
const services: Services = { mysql: MYSQL_SERVICE };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...MYSQL_ARGS]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('search engine', () => {
|
||||||
|
it('adds opensearch flags when opensearch service is present', () => {
|
||||||
|
const services: Services = { opensearch: { image: 'opensearchproject/opensearch:2.19.1' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...OPENSEARCH_ARGS]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds elasticsearch7 flags for an elasticsearch 7.x image', () => {
|
||||||
|
const services: Services = { elasticsearch: { image: 'elasticsearch:7.17.0' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([
|
||||||
|
...BASE_ARGS,
|
||||||
|
'--search-engine=elasticsearch7',
|
||||||
|
'--elasticsearch-host=localhost',
|
||||||
|
'--elasticsearch-port=9200',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds elasticsearch8 flags for an elasticsearch 8.x image', () => {
|
||||||
|
const services: Services = { elasticsearch: { image: 'elasticsearch:8.11.4' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([
|
||||||
|
...BASE_ARGS,
|
||||||
|
'--search-engine=elasticsearch8',
|
||||||
|
'--elasticsearch-host=localhost',
|
||||||
|
'--elasticsearch-port=9200',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prefers opensearch over elasticsearch when both are present', () => {
|
||||||
|
const services: Services = {
|
||||||
|
opensearch: { image: 'opensearchproject/opensearch:2.19.1' },
|
||||||
|
elasticsearch: { image: 'elasticsearch:8.11.4' },
|
||||||
|
};
|
||||||
|
const args = buildInstallArgs(services);
|
||||||
|
expect(args).toContain('--search-engine=opensearch');
|
||||||
|
expect(args.some(a => a.startsWith('--search-engine=elasticsearch'))).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('rabbitmq', () => {
|
||||||
|
it('adds amqp flags when rabbitmq service is present', () => {
|
||||||
|
const services: Services = { rabbitmq: { image: 'rabbitmq:4.0-management' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...RABBITMQ_ARGS]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('cache / session', () => {
|
||||||
|
it('adds redis cache flags when redis service is present', () => {
|
||||||
|
const services: Services = { redis: { image: 'redis:7.2' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...CACHE_ARGS]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds redis cache flags when valkey service is present', () => {
|
||||||
|
const services: Services = { valkey: { image: 'valkey:8.0' } };
|
||||||
|
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...CACHE_ARGS]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds cache flags once when both valkey and redis are present', () => {
|
||||||
|
const services: Services = {
|
||||||
|
valkey: { image: 'valkey:8.0' },
|
||||||
|
redis: { image: 'redis:7.2' },
|
||||||
|
};
|
||||||
|
const args = buildInstallArgs(services);
|
||||||
|
expect(args.filter(a => a === '--session-save=redis')).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('buildMysqlPrepArgs', () => {
|
||||||
|
it('uses root password and port from service config', () => {
|
||||||
|
expect(buildMysqlPrepArgs(MYSQL_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');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to default root password when env is absent', () => {
|
||||||
|
const args = buildMysqlPrepArgs({ image: 'mysql:8.4' });
|
||||||
|
expect(args).toContain('-prootpassword');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('all services', () => {
|
||||||
|
it('adds all flags when all services are present', () => {
|
||||||
|
const services: Services = {
|
||||||
|
mysql: MYSQL_SERVICE,
|
||||||
|
opensearch: { image: 'opensearchproject/opensearch:2.19.1' },
|
||||||
|
rabbitmq: { image: 'rabbitmq:4.0-management' },
|
||||||
|
valkey: { image: 'valkey:8.0' },
|
||||||
|
};
|
||||||
|
expect(buildInstallArgs(services)).toEqual([
|
||||||
|
...BASE_ARGS,
|
||||||
|
...MYSQL_ARGS,
|
||||||
|
...OPENSEARCH_ARGS,
|
||||||
|
...RABBITMQ_ARGS,
|
||||||
|
...CACHE_ARGS,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
export interface ServiceConfig {
|
||||||
|
image: string;
|
||||||
|
env?: Record<string, string>;
|
||||||
|
ports?: string[];
|
||||||
|
options?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Services {
|
||||||
|
mysql?: ServiceConfig;
|
||||||
|
opensearch?: ServiceConfig;
|
||||||
|
elasticsearch?: ServiceConfig;
|
||||||
|
rabbitmq?: ServiceConfig;
|
||||||
|
redis?: ServiceConfig;
|
||||||
|
valkey?: ServiceConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BASE_ARGS = [
|
||||||
|
'--base-url=http://localhost/',
|
||||||
|
'--admin-user=admin',
|
||||||
|
'--admin-password=admin123',
|
||||||
|
'--admin-email=admin@example.com',
|
||||||
|
'--admin-firstname=Admin',
|
||||||
|
'--admin-lastname=User',
|
||||||
|
'--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';
|
||||||
|
return ['-h127.0.0.1', `--port=${port}`, '-uroot', `-p${rootPassword}`, '-e', 'SET GLOBAL log_bin_trust_function_creators = 1;'];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const buildInstallArgs = (services: Services | null): string[] => {
|
||||||
|
const args = [...BASE_ARGS];
|
||||||
|
|
||||||
|
if (!services) return args;
|
||||||
|
|
||||||
|
if (services.mysql) {
|
||||||
|
const dbPort = services.mysql.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'}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (services.opensearch) {
|
||||||
|
args.push(
|
||||||
|
'--search-engine=opensearch',
|
||||||
|
'--opensearch-host=localhost',
|
||||||
|
'--opensearch-port=9200',
|
||||||
|
);
|
||||||
|
} else if (services.elasticsearch) {
|
||||||
|
const majorVersion = services.elasticsearch.image.split(':')[1]?.split('.')[0];
|
||||||
|
args.push(
|
||||||
|
`--search-engine=elasticsearch${majorVersion}`,
|
||||||
|
'--elasticsearch-host=localhost',
|
||||||
|
'--elasticsearch-port=9200',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (services.rabbitmq) {
|
||||||
|
args.push(
|
||||||
|
'--amqp-host=localhost',
|
||||||
|
'--amqp-port=5672',
|
||||||
|
'--amqp-user=guest',
|
||||||
|
'--amqp-password=guest',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (services.valkey || services.redis) {
|
||||||
|
args.push(
|
||||||
|
'--session-save=redis',
|
||||||
|
'--session-save-redis-host=localhost',
|
||||||
|
'--session-save-redis-port=6379',
|
||||||
|
'--cache-backend=redis',
|
||||||
|
'--cache-backend-redis-server=localhost',
|
||||||
|
'--cache-backend-redis-port=6379',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
import { buildInstallArgs, buildMysqlPrepArgs, Services } from './build-command';
|
||||||
|
|
||||||
|
export async function run(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const servicesInput = core.getInput('services');
|
||||||
|
const path = core.getInput('path') || '.';
|
||||||
|
const extraArgs = core.getInput('extra_args').trim();
|
||||||
|
|
||||||
|
let services: Services | null = null;
|
||||||
|
if (servicesInput && servicesInput !== 'null') {
|
||||||
|
services = JSON.parse(servicesInput) as Services;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = buildInstallArgs(services);
|
||||||
|
|
||||||
|
if (extraArgs) {
|
||||||
|
args.push(...extraArgs.split(/\s+/));
|
||||||
|
}
|
||||||
|
|
||||||
|
core.setOutput('command', `php bin/magento setup:install ${args.join(' ')}`);
|
||||||
|
|
||||||
|
await exec.exec('php', ['bin/magento', 'setup:install', ...args], { cwd: path });
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed((error as Error).message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"typeRoots": ["../node_modules/@types"],
|
||||||
|
"types": ["jest"]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user