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 7ca5097
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ 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]);
} else if (hub) {
deployParams = deployParams.concat(['--auto-create']);
}

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 +48,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
56 changes: 52 additions & 4 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,44 @@ 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',
'--auto-create',
'--hub',
'my-hub',
]);
});

test('test action run deploy with branch name correctly', async () => {
test('test action run deploy a specific doc inside a hub correctly', async () => {
expect(mockedDeploy.run).not.toHaveBeenCalled();

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

await main();
Expand All @@ -74,10 +97,35 @@ test('test action run deploy with branch name correctly', async () => {

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

test('test action run deploy with branch name correctly', async () => {
expect(mockedDeploy.run).not.toHaveBeenCalled();

const restore = mockEnv({
INPUT_FILE: 'my-file.yml',
INPUT_DOC: 'my-doc',
INPUT_TOKEN: 'SECRET',
INPUT_BRANCH: 'latest',
});

await main();

restore();

expect(mockedDeploy.run).toHaveBeenCalledWith([
'my-file.yml',
'--token',
'SECRET',
'--doc',
'my-doc',
'--branch',
'latest',
]);
Expand Down Expand Up @@ -114,10 +162,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 7ca5097

Please sign in to comment.