Skip to content

Commit

Permalink
feat: Add skip repository update flag (#458)
Browse files Browse the repository at this point in the history
* feat: add skip update repository flag

* doc: update README
  • Loading branch information
kamiazya authored Jan 5, 2023
1 parent d193a44 commit 7bba007
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ you can specify a specific version for each operating system (not macOS).
ubuntu-graphviz-version: '2.42.2-3build2'
# libgraphviz-dev version on Ubuntu.
ubuntu-libgraphvizdev-version: '2.42.2-3build2'
# Skip to run apt update command on Ubuntu.
ubuntu-skip-apt-update: 'true' # defalt false
# graphviz version on Windows.
windows-graphviz-version: '2.49.3'
# Skip to run brew update command on macOS.
macos-skip-brew-update: 'true' # defalt false
```
## See Also
Expand Down
10 changes: 10 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ branding:
icon: arrow-down-circle
color: gray-dark
inputs:
ubuntu-skip-apt-update:
description: |-
Skip to run apt update command on Ubuntu.
required: false
default: 'false'
ubuntu-graphviz-version:
description: |-
graphviz version on Ubuntu.
Expand All @@ -13,6 +18,11 @@ inputs:
description: |-
libgraphviz-dev version on Ubuntu.
required: false
macos-skip-brew-update:
description: |-
Skip to run brew update command on macOS.
required: false
default: 'false'
windows-graphviz-version:
description: |-
graphviz version on Windows.
Expand Down
12 changes: 9 additions & 3 deletions src/GraphvizInstaller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInput } from '@actions/core';
import { getBooleanInput, getInput } from '@actions/core';
import { exec } from '@actions/exec';

export class GraphvizInstaller {
Expand All @@ -22,17 +22,23 @@ export class GraphvizInstaller {
}

private async brewInstall() {
await exec('brew', ['update']);
const skipBrewUpdate = getBooleanInput('macos-skip-brew-update');
if (skipBrewUpdate === false) {
await exec('brew', ['update']);
}
await exec('brew', [
'install',
'graphviz',
]);
}

private async getAptInstall() {
const skipAptUpdate = getBooleanInput('ubuntu-skip-apt-update');
const graphvizVersion = getInput('ubuntu-graphviz-version');
const libgraphvizdevVersion = getInput('ubuntu-libgraphvizdev-version');
await exec('sudo', ['apt-get', 'update']);
if (skipAptUpdate === false) {
await exec('sudo', ['apt-get', 'update']);
}
await exec('sudo', [
'apt-get',
'install',
Expand Down
72 changes: 71 additions & 1 deletion src/__tests__/GraphvizInstaller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jest.mock('@actions/core');
jest.mock('@actions/exec');

import { getInput } from '@actions/core';
import { getInput, getBooleanInput } from '@actions/core';
import * as exec from '@actions/exec';
import { GraphvizInstaller } from '../GraphvizInstaller';

Expand Down Expand Up @@ -33,6 +33,51 @@ describe('class GraphvizInstaller', () => {

expect(brewInstall.mock.calls.length).toBe(1);
});

describe('inputs works', () => {
test('default', async () => {
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"brew",
Array [
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"brew",
Array [
"install",
"graphviz",
],
]
`);
});
test('skip brew update', async () => {
(getBooleanInput as jest.Mock).mockReturnValue(true);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"brew",
Array [
"install",
"graphviz",
],
]
`);
});
});
});

describe('Work on "linux"', () => {
Expand All @@ -51,8 +96,30 @@ describe('class GraphvizInstaller', () => {
});

describe('inputs works', () => {
test('skip apt update', async () => {
(getBooleanInput as jest.Mock).mockReturnValue(true);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"sudo",
Array [
"apt-get",
"install",
"graphviz",
"libgraphviz-dev",
"pkg-config",
],
]
`);
});

test('graphviz version not seted', async () => {
(getInput as jest.Mock).mockReturnValue('');
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();
Expand Down Expand Up @@ -92,6 +159,7 @@ describe('class GraphvizInstaller', () => {
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();
Expand Down Expand Up @@ -129,6 +197,7 @@ describe('class GraphvizInstaller', () => {
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();
Expand Down Expand Up @@ -166,6 +235,7 @@ describe('class GraphvizInstaller', () => {
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();
Expand Down

0 comments on commit 7bba007

Please sign in to comment.