Skip to content

Commit

Permalink
inputs: make the doc parameter optional
Browse files Browse the repository at this point in the history
The GH action `doc:` input parameter should be optional.

Indeed, since we introduced the [directory deploy for Hubs in the CLI](bump-sh/cli#462), the `--doc`
parameter became optional for hubs deployments.

This PR makes sure the `doc` input of the GitHub action is also
optional to be able to deploy a whole directory to a Bump.sh Hub from
the GitHub action too.
  • Loading branch information
paulRbr committed Mar 1, 2024
1 parent 2716178 commit 57daab0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ async function run(): Promise<void> {
const failOnBreaking: boolean = core.getInput('fail_on_breaking') === 'true';
const cliParams = [file];
const config = new Config({ root: path.resolve(__dirname, '../') });
let docCliParams = ['--doc', doc, '--token', token];
let deployParams = ['--token', token];

if (doc) {
deployParams = deployParams.concat(['--doc', doc]);
}

if (hub) {
docCliParams = docCliParams.concat(['--hub', hub]);
deployParams = deployParams.concat(['--hub', hub]);
}

if (branch) {
docCliParams = docCliParams.concat(['--branch', branch]);
deployParams = deployParams.concat(['--branch', branch]);
}

await config.load();
Expand All @@ -42,10 +46,10 @@ async function run(): Promise<void> {
break;
case 'dry-run':
case 'validate': // DEPRECATED, kept for backward compatibility with old gem
await bump.Deploy.run(cliParams.concat(docCliParams).concat(['--dry-run']));
await bump.Deploy.run(cliParams.concat(deployParams).concat(['--dry-run']));
break;
case 'deploy':
await bump.Deploy.run(cliParams.concat(docCliParams));
await bump.Deploy.run(cliParams.concat(deployParams));
break;
case 'diff':
const docDigest = shaDigest([doc, hub]);
Expand Down
30 changes: 26 additions & 4 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,32 @@ test('test action run deploy correctly', async () => {

expect(mockedDeploy.run).toHaveBeenCalledWith([
'my-file.yml',
'--token',
'SECRET',
'--doc',
'my-doc',
]);
});

test('test action run deploy entire directory in hub correctly', async () => {
expect(mockedDeploy.run).not.toHaveBeenCalled();

const restore = mockEnv({
INPUT_FILE: 'my-file.yml',
INPUT_HUB: 'my-hub',
INPUT_TOKEN: 'SECRET',
});

await main();

restore();

expect(mockedDeploy.run).toHaveBeenCalledWith([
'my-file.yml',
'--token',
'SECRET',
'--hub',
'my-hub',
]);
});

Expand All @@ -74,10 +96,10 @@ test('test action run deploy with branch name correctly', async () => {

expect(mockedDeploy.run).toHaveBeenCalledWith([
'my-file.yml',
'--doc',
'my-doc',
'--token',
'SECRET',
'--doc',
'my-doc',
'--branch',
'latest',
]);
Expand Down Expand Up @@ -114,10 +136,10 @@ test('test action run dry-run correctly', async () => {

expect(mockedDeploy.run).toHaveBeenCalledWith([
'my-file.yml',
'--doc',
'my-doc',
'--token',
'SECRET',
'--doc',
'my-doc',
'--dry-run',
]);
});
Expand Down

0 comments on commit 57daab0

Please sign in to comment.