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

inputs: make the doc parameter optional #485

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

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
Loading