Skip to content

Commit

Permalink
Install local binary (#5)
Browse files Browse the repository at this point in the history
* Add detail to README. Remove outputs for local binary. Address linting issues.
  • Loading branch information
gsarjeant committed Feb 12, 2024
1 parent a0ef71e commit 10847c3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 61 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
uses: ./
with:
install-cli: yes
install-local-binary: yes

- name: Print Output
id: output
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Install Oso Cloud Tools

Installs the Oso Cloud CLI and Oso Cloud local binary on a GitHub actions runner.
Installs the
[Oso Cloud CLI](https://www.osohq.com/docs/reference/client-apis/cli)
on a GitHub actions runner.

More to come.
The CLI is required for the following Oso Cloud GitHub actions:

- validate-polar-syntax (a wrapper for `oso-cloud validate`)
- run-polar-tests (a wrapper for `oso-cloud test`)
- deploy-polar-code (a wrapper for `oso-cloud policy`)

See the documentation for each action for additional information about that action.

Inputs: none
Outputs:

- cli-version: The version number of the CLI that was installed
- cli-sha: The SHA of the CLI that was installed

Currently, the action always installs the latest version of the CLI.
A future revision will bundle a specific version with each release,
so that previous versions of the CLI can be deployed if desired.
33 changes: 0 additions & 33 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ describe('action', () => {
switch (name) {
case 'install-cli':
return 'yes'
case 'install-local-binary':
return 'yes'
default:
return ''
}
Expand All @@ -62,10 +60,6 @@ describe('action', () => {
expect(installCliMock).toHaveBeenCalled()

expect(debugMock).toHaveBeenNthCalledWith(1, 'Installing Oso Cloud CLI')
expect(debugMock).toHaveBeenNthCalledWith(
2,
'Installing Oso Cloud local binary'
)
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'cli-version', '0.12.5')
expect(setOutputMock).toHaveBeenNthCalledWith(
2,
Expand All @@ -80,8 +74,6 @@ describe('action', () => {
switch (name) {
case 'install-cli':
return 'maybe'
case 'install-local-binary':
return 'yes'
default:
return ''
}
Expand All @@ -98,29 +90,4 @@ describe('action', () => {
expect(errorMock).not.toHaveBeenCalled()
expect(setOutputMock).not.toHaveBeenCalledTimes(1)
})

it('sets a failed status on an invalid install-local-binary input', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'install-cli':
return 'yes'
case 'install-local-binary':
return 'maybe'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'Invalid value for install-local-binary: maybe. Please specify either "yes" or "no".'
)
expect(errorMock).not.toHaveBeenCalled()
expect(setOutputMock).not.toHaveBeenCalledTimes(1)
})
})
6 changes: 0 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ inputs:
description: Whether or not to install the OSO Cloud CLI.
required: false
default: 'yes'
install-local-binary:
description: Whether or not to install the OSO Cloud local binary.
required: false
default: 'yes'

outputs:
cli-version:
description: 'The version of the OSO Cloud CLI that was installed'
cli-sha:
description: 'The SHA of the OSO Cloud CLI that was installed'
local-binary-version:
description: 'The version of the OSO Cloud local binary that was installed'

runs:
using: node20
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions dist/index.js

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

11 changes: 0 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ export async function run(): Promise<void> {
try {
const validInstallInputValues: Set<string> = new Set(['yes', 'no'])
const shouldInstallCli: string = core.getInput('install-cli')
const shouldInstallLocalBinary: string = core.getInput(
'install-local-binary'
)

// Validate inputs
if (!validInstallInputValues.has(shouldInstallCli)) {
throw new Error(
`Invalid value for install-cli: ${shouldInstallCli}. Please specify either "yes" or "no".`
)
}
if (!validInstallInputValues.has(shouldInstallLocalBinary)) {
throw new Error(
`Invalid value for install-local-binary: ${shouldInstallLocalBinary}. Please specify either "yes" or "no".`
)
}

if (shouldInstallCli === 'yes') {
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
Expand All @@ -33,9 +25,6 @@ export async function run(): Promise<void> {
core.setOutput('cli-version', cliInfo.split(' ')[1])
core.setOutput('cli-sha', cliInfo.split(' ')[3])
}
if (shouldInstallLocalBinary === 'yes') {
core.debug('Installing Oso Cloud local binary')
}
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 10847c3

Please sign in to comment.