Skip to content

Commit

Permalink
fix: use working-dir from "composer-options" (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 16, 2021
1 parent 51c83d9 commit 6f35852
Show file tree
Hide file tree
Showing 19 changed files with 2,356 additions and 143 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -37,9 +37,7 @@ jobs:
- "locked"
composer-options:
- "--ignore-platform-reqs"
- ""
working-directory:
- "subdirectory"
- "--working-dir subdirectory"
- ""
steps:
- uses: "actions/checkout@v2"
Expand All @@ -50,4 +48,3 @@ jobs:
with:
dependency-versions: "${{ matrix.dependency-versions }}"
composer-options: "${{ matrix.composer-options }}"
working-directory: "${{ matrix.working-directory }}"
15 changes: 1 addition & 14 deletions README.md
Expand Up @@ -83,20 +83,7 @@ For example:
```yaml
- uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-reqs"
```

#### working-directory

If your `composer.json` is located in a sub-folder (e.g.: `packages/api`),
you must use `working-directory` input to get the action working properly.

For example:

```yaml
- uses: "ramsey/composer-install@v1"
with:
working-directory: "packages/api"
composer-options: "--ignore-platform-reqs --working-dir backend"
```

### Matrix Example
Expand Down
7 changes: 2 additions & 5 deletions __tests__/actions/mainAction.test.ts
Expand Up @@ -64,7 +64,6 @@ describe('main action', () => {
expect(composerInstallMock).toHaveBeenCalledWith(
'lowest',
'--ignore-platform-reqs',
''
)
})

Expand All @@ -74,9 +73,8 @@ describe('main action', () => {
const composerInstallMock = jest.spyOn(composer, 'install')
const mockFactory = cache.restoreFactory()

process.env['INPUT_COMPOSER-OPTIONS'] = '--ignore-platform-reqs'
process.env['INPUT_COMPOSER-OPTIONS'] = '--ignore-platform-reqs --working-dir subdirectory'
process.env['INPUT_DEPENDENCY-VERSIONS'] = 'lowest'
process.env['INPUT_WORKING-DIRECTORY'] = 'subdirectory'

await mainAction()

Expand All @@ -91,8 +89,7 @@ describe('main action', () => {
expect(composerInstallMock).toHaveBeenCalledTimes(1)
expect(composerInstallMock).toHaveBeenCalledWith(
'lowest',
'--ignore-platform-reqs',
'subdirectory'
'--ignore-platform-reqs --working-dir subdirectory',
)
})

Expand Down
3 changes: 1 addition & 2 deletions __tests__/actions/postAction.test.ts
Expand Up @@ -57,9 +57,8 @@ describe('post action', () => {
const cacheMock = jest.spyOn(cache, 'cache')
const mockFactory = cache.saveFactory()

process.env['INPUT_COMPOSER-OPTIONS'] = ''
process.env['INPUT_COMPOSER-OPTIONS'] = ' --working-dir subdirectory'
process.env['INPUT_DEPENDENCY-VERSIONS'] = 'highest'
process.env['INPUT_WORKING-DIRECTORY'] = 'subdirectory'

await postAction()

Expand Down
59 changes: 7 additions & 52 deletions __tests__/composer/install.test.ts
Expand Up @@ -14,12 +14,7 @@ describe('composer.install with mocked exec', () => {
await composer.install('locked')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'install',
'--no-interaction',
'--no-progress',
'--ansi'
])
expect(execMock).toHaveBeenCalledWith('composer install --no-interaction --no-progress --ansi')
})

test('executes command to install composer with highest dependencies', async () => {
Expand All @@ -28,12 +23,7 @@ describe('composer.install with mocked exec', () => {
await composer.install('highest')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'update',
'--no-interaction',
'--no-progress',
'--ansi'
])
expect(execMock).toHaveBeenCalledWith('composer update --no-interaction --no-progress --ansi')
})

test('executes command to install composer with lowest dependencies', async () => {
Expand All @@ -42,13 +32,7 @@ describe('composer.install with mocked exec', () => {
await composer.install('lowest')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'update',
'--prefer-lowest',
'--no-interaction',
'--no-progress',
'--ansi'
])
expect(execMock).toHaveBeenCalledWith('composer update --prefer-lowest --no-interaction --no-progress --ansi')
})

test('executes command to install composer with locked dependencies when provided invalid dependencyPreference', async () => {
Expand All @@ -57,44 +41,15 @@ describe('composer.install with mocked exec', () => {
await composer.install('foobar')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'install',
'--no-interaction',
'--no-progress',
'--ansi'
])
expect(execMock).toHaveBeenCalledWith('composer install --no-interaction --no-progress --ansi')
})

test('executes command to install composer with locked dependencies and working directory', async () => {
test('executes command to install composer with locked dependencies and options', async () => {
const execMock = jest.spyOn(exec, 'exec')

await composer.install('locked', '', 'subdirectory')
await composer.install('locked', '--profile --no-plugins --working-dir subdirectory')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'install',
'--no-interaction',
'--no-progress',
'--ansi',
'--working-dir=subdirectory'
])
})

test('executes command to install composer with locked dependencies, working directory and options', async () => {
const execMock = jest.spyOn(exec, 'exec')

await composer.install('locked', '--opt1 --opt2 --opt3', 'subdirectory')

expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith('composer', [
'install',
'--no-interaction',
'--no-progress',
'--ansi',
'--working-dir=subdirectory',
'--opt1',
'--opt2',
'--opt3'
])
expect(execMock).toHaveBeenCalledWith('composer install --no-interaction --no-progress --ansi --profile --no-plugins --working-dir subdirectory')
})
})
4 changes: 2 additions & 2 deletions __tests__/utils/getCacheKeys.test.ts
Expand Up @@ -56,8 +56,8 @@ describe('cache keys', () => {
await expect(
getCacheKeys('highest', '--some-other-option --and-another', 'subdirectory')
).resolves.toEqual({
key: 'fooplatform-php-7.99.99-subdirectory-highest-foobar---some-other-option --and-another',
restoreKeys: ['fooplatform-php-7.99.99-subdirectory-highest-foobar-', 'fooplatform-php-7.99.99-subdirectory-highest-']
key: 'fooplatform-php-7.99.99-highest-foobar---some-other-option --and-another',
restoreKeys: ['fooplatform-php-7.99.99-highest-foobar-', 'fooplatform-php-7.99.99-highest-']
})
expect(utils.hashFiles).toHaveBeenCalledWith('subdirectory/composer.json\nsubdirectory/composer.lock');
})
Expand Down
25 changes: 25 additions & 0 deletions __tests__/utils/getComposerWorkingDir.test.ts
@@ -0,0 +1,25 @@
import { getComposerWorkingDir } from '../../src/utils/getComposerWorkingDir';

jest.mock('@actions/core');

describe('getComposerWorkingDir', () => {
test('with empty options', () => {
expect(getComposerWorkingDir()).toEqual('');
});

test('with --working-dir option', () => {
expect(getComposerWorkingDir('--working-dir subdirectory')).toEqual('subdirectory');
});

test('with -d (alias of --working-dir) option', () => {
expect(getComposerWorkingDir('-d subdirectory')).toEqual('subdirectory');
});

test('with other options AND without --working-dir', () => {
expect(getComposerWorkingDir('-vv --no-plugins')).toEqual('');
});

test('with other options AND with --working-dir', () => {
expect(getComposerWorkingDir('-vv --working-dir subdirectory --no-plugins')).toEqual('subdirectory');
});
});
28 changes: 28 additions & 0 deletions __tests__/utils/parseStringToArguments.test.ts
@@ -0,0 +1,28 @@
import {parseStringToArguments} from '../../src/utils'

describe('parseStringToArguments', () => {
test('empty args', () => {
expect(parseStringToArguments('')).toEqual({
_: []
})
})

test('only positional argument', () => {
expect(parseStringToArguments('test')).toEqual({
_: ['test']
})
})

test('positional argument with lot of options', () => {
expect(
parseStringToArguments(
'--no-plugins --profile --working-dir subdirectory test'
)
).toEqual({
_: ['test'],
plugins: false,
profile: true,
'working-dir': 'subdirectory'
})
})
})

0 comments on commit 6f35852

Please sign in to comment.