Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass scripts arguments #20

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ steps:
cake-bootstrap: true
```

### `script-arguments`

If you need pass same additional [argument](https://cakebuild.net/docs/writing-builds/args-and-environment-vars#passing-and-reading-arguments) value to CakeBuild, you can use `script-arguments`.

When you add an Argument: eg.
`var assemblyVersion = Argument<string>("versionTag", "refs/tag/v0.0.0.0");`
then your step can look like that:

```yml
steps:
- name: Update-Assembly-Version
uses: cake-build/cake-action@v1
with:
target: "Update-Assembly-Version"
script-arguments: --versionTag=${{ github.ref }}
jwickowski marked this conversation as resolved.
Show resolved Hide resolved
```

## Cross-platform

Since the [Cake Tool](https://www.nuget.org/packages/Cake.Tool/) is built on .NET Core, the Cake action will run on any of the [virtual environments](https://help.github.com/en/github/automating-your-workflow-with-github-actions/software-in-virtual-environments-for-github-actions) supported by GitHub Actions, namely Linux, Windows and macOS.
Expand Down
60 changes: 59 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from '../src/main';
import { ToolsDirectory } from '../src/toolsDirectory';
import * as dotnet from '../src/dotnet';
import * as cake from '../src/cake';
import { CakeArgument } from '../src/cakeParameter';
import { CakeArgument, CakeSwitch } from '../src/cakeParameter';

jest.mock('@actions/core');
jest.mock('../src/toolsDirectory');
Expand All @@ -13,6 +13,11 @@ jest.mock('../src/cake');

describe('When running the action without any input arguments', () => {
const fakeToolsDirectory = ToolsDirectory as jest.MockedClass<typeof ToolsDirectory>;
const fakeGetInput = core.getInput as jest.MockedFunction<typeof core.getInput>;

beforeAll(() => {
when(fakeGetInput).calledWith('script-arguments').mockReturnValue('');
});

test('it should create the tools directory', async () => {
await run();
Expand Down Expand Up @@ -84,6 +89,59 @@ describe('When running the action with the target input argument', () => {
});
});

describe('When running the action with the script-arguments', () => {
const fakeGetInput = core.getInput as jest.MockedFunction<typeof core.getInput>;
const fakeRunScript = cake.runScript as jest.MockedFunction<typeof cake.runScript>;

describe('and there is a switch argument', () => {
test('it should run script with the specified arguments', async () => {
when(fakeGetInput)
.calledWith('script-arguments').mockReturnValue('--switchArgument');

await run();
expect(fakeRunScript.mock.calls[0][4]).toStrictEqual(
new CakeSwitch('switchArgument')
);
});
});

describe('and there is an input argument', () => {
test('it should run script with the specified arguments', async () => {
when(fakeGetInput)
.calledWith('script-arguments').mockReturnValue('--assemblyVersion=1.0.1');

await run();
expect(fakeRunScript.mock.calls[0][4]).toStrictEqual(
new CakeArgument('assemblyVersion', '1.0.1'));
});

test('it should run script with the specified arguments with one dash', async () => {
when(fakeGetInput)
.calledWith('script-arguments').mockReturnValue('-foo=bar');

await run();
expect(fakeRunScript.mock.calls[0][4]).toStrictEqual(
new CakeArgument('foo', 'bar'));
});
});

jwickowski marked this conversation as resolved.
Show resolved Hide resolved
describe('and there are multiple arguments', () => {
test('it should run script with the specified arguments', async () => {
when(fakeGetInput)
.calledWith('script-arguments').mockReturnValue('--firstInput=1.0.1 --secondInputQuotes="test value" --secondArg');

await run();
expect(fakeRunScript.mock.calls[0][4]).toStrictEqual(
new CakeArgument('firstInput', '1.0.1'));

expect(fakeRunScript.mock.calls[0][5]).toStrictEqual(
new CakeArgument('secondInputQuotes', 'test value'));

expect(fakeRunScript.mock.calls[0][6]).toStrictEqual(
new CakeSwitch('secondArg'));
});
});
});
describe('When running the action with the verbosity input argument', () => {
const fakeGetInput = core.getInput as jest.MockedFunction<typeof core.getInput>;
const fakeRunScript = cake.runScript as jest.MockedFunction<typeof cake.runScript>;
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: 'Flag for if Cake modules should be installed/bootstrapped.'
required: false
default: 'false'
script-arguments:
description: 'The place to pass script arguments that will be passes to runner.'
required: false
default: ''
runs:
using: 'node12'
main: 'dist/index.js'