Skip to content

Commit

Permalink
Merge pull request #15 from bluehorndigital/composer-allow-plugins-fix
Browse files Browse the repository at this point in the history
run composer config to set allow-plugins
  • Loading branch information
mglaman authored Jul 12, 2022
2 parents 2a69aa6 + bed45ad commit 238817c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
drupal-version: "^9"
- php-version: "8.0"
drupal-version: "^9"
- php-version: "8.0"
drupal-version: "10.0.x-dev"
- php-version: "8.1"
drupal-version: "^10@alpha"
env:
extensions: zip, gd
key: cache-v1
Expand Down Expand Up @@ -64,7 +64,10 @@ jobs:
env:
INPUT_VERSION: ${{ matrix.drupal-version }}
INPUT_PATH: ~/drupal
INPUT_ALLOW_PLUGINS: oomphinc/composer-installers-extender
- name: Debug composer.json
run: cat ~/drupal/composer.json
- name: Include plugin
run: cd ~/drupal && composer require oomphinc/composer-installers-extender
- name: Verify build
run: test -f ~/drupal/web/index.php
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Where to build Drupal. Defaults to `~/drupal`.

Extra dependencies to install.

### `allow_plugins`

Additional packages to configure with `allow-plugins`.

## Example usage

```
Expand Down
15 changes: 15 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ test('can find major version from constraint', () => {
expect(utils.getMajorVersionFromConstraint('8.9.x-dev')).toBe(8);
expect(utils.getMajorVersionFromConstraint('dev-8.9.x')).toBe(8);
});

test('can get array from string', () => {
expect(utils.stringToArray("composer/installers\nphpstan/extension-installer")).toEqual([
'composer/installers',
'phpstan/extension-installer'
]);
expect(utils.stringToArray("composer/installers\r\nphpstan/extension-installer")).toEqual([
'composer/installers',
'phpstan/extension-installer'
]);
expect(utils.stringToArray("composer/installers,phpstan/extension-installer")).toEqual([
'composer/installers',
'phpstan/extension-installer'
]);
})
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ inputs:
dependencies:
description: 'Additional dependencies to install'
required: false
allow_plugins:
description: 'Packages to add to allow-plugins for Composer'
required: false
default: ''
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
branding:
icon: 'box'
icon: 'box'
color: 'blue'
33 changes: 29 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ function getState(name) {
exports.getState = getState;
//# sourceMappingURL=core.js.map


/***/ }),

/***/ 717:
Expand Down Expand Up @@ -2252,6 +2251,7 @@ async function doScript() {
});
const drupalPath = utils.resolvePath(core.getInput('path') || '~/drupal');
const extraDependencies = core.getInput('dependencies')
const allowPlugins = utils.stringToArray(core.getInput('allow_plugins'))

await exec.exec('composer', [
'create-project',
Expand All @@ -2268,9 +2268,23 @@ async function doScript() {
['config', 'repositories.1', 'composer', 'https://packages.drupal.org/8'],
['require', '--dev', `drupal/core-dev:${drupalVersion}`],
];

if (utils.getMajorVersionFromConstraint(drupalVersion) === 8) {
commands.push(['config', '--no-plugins', 'allow-plugins.drupal/core-composer-scaffold', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.drupal/core-project-message', 'true']);
}
commands.push(['config', '--no-plugins', 'allow-plugins.composer/installers', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.dealerdirect/phpcodesniffer-composer-installer', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.phpstan/extension-installer', 'true']);

allowPlugins.forEach(package => {
commands.push(['config', '--no-plugins', 'allow-plugins.' + package, 'true']);
});

if (utils.getMajorVersionFromConstraint(drupalVersion) > 8) {
commands.push(['require', '--dev', '--with-all-dependencies', 'phpspec/prophecy-phpunit:^2']);
}

if (extraDependencies) {
commands.push(['require', extraDependencies]);
}
Expand All @@ -2293,7 +2307,8 @@ doScript().catch(error => core.setFailed(error.message));

const path = __nccwpck_require__(622);
const semverMajor = __nccwpck_require__(688)
const smeverCoerce = __nccwpck_require__(466)
const smeverCoerce = __nccwpck_require__(466);
const { access } = __nccwpck_require__(747);

function resolvePath(filepath) {
if (filepath[0] === '~') {
Expand All @@ -2305,11 +2320,21 @@ function resolvePath(filepath) {
function getMajorVersionFromConstraint(constraint) {
return semverMajor(smeverCoerce(constraint))
}

function stringToArray(string) {
return string.split(/\r?\n/).reduce(
(acc, line) =>
acc
.concat(line.split(","))
.filter(pat => pat)
.map(pat => pat.trim()),
[]
);
}

module.exports = {
resolvePath,
getMajorVersionFromConstraint
getMajorVersionFromConstraint,
stringToArray
}


Expand Down
15 changes: 15 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function doScript() {
});
const drupalPath = utils.resolvePath(core.getInput('path') || '~/drupal');
const extraDependencies = core.getInput('dependencies')
const allowPlugins = utils.stringToArray(core.getInput('allow_plugins'))

await exec.exec('composer', [
'create-project',
Expand All @@ -31,9 +32,23 @@ async function doScript() {
['config', 'repositories.1', 'composer', 'https://packages.drupal.org/8'],
['require', '--dev', `drupal/core-dev:${drupalVersion}`],
];

if (utils.getMajorVersionFromConstraint(drupalVersion) === 8) {
commands.push(['config', '--no-plugins', 'allow-plugins.drupal/core-composer-scaffold', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.drupal/core-project-message', 'true']);
}
commands.push(['config', '--no-plugins', 'allow-plugins.composer/installers', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.dealerdirect/phpcodesniffer-composer-installer', 'true']);
commands.push(['config', '--no-plugins', 'allow-plugins.phpstan/extension-installer', 'true']);

allowPlugins.forEach(package => {
commands.push(['config', '--no-plugins', 'allow-plugins.' + package, 'true']);
});

if (utils.getMajorVersionFromConstraint(drupalVersion) > 8) {
commands.push(['require', '--dev', '--with-all-dependencies', 'phpspec/prophecy-phpunit:^2']);
}

if (extraDependencies) {
commands.push(['require', extraDependencies]);
}
Expand Down
17 changes: 14 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const semverMajor = require('semver/functions/major')
const smeverCoerce = require('semver/functions/coerce')
const smeverCoerce = require('semver/functions/coerce');
const { access } = require('fs');

function resolvePath(filepath) {
if (filepath[0] === '~') {
Expand All @@ -12,9 +13,19 @@ function resolvePath(filepath) {
function getMajorVersionFromConstraint(constraint) {
return semverMajor(smeverCoerce(constraint))
}

function stringToArray(string) {
return string.split(/\r?\n/).reduce(
(acc, line) =>
acc
.concat(line.split(","))
.filter(pat => pat)
.map(pat => pat.trim()),
[]
);
}

module.exports = {
resolvePath,
getMajorVersionFromConstraint
getMajorVersionFromConstraint,
stringToArray
}

0 comments on commit 238817c

Please sign in to comment.