Skip to content

Commit

Permalink
fix: ensure raw_output is a string
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Miller <[email protected]>
  • Loading branch information
Djelibeybi committed Aug 8, 2024
1 parent 88f7996 commit 8a22b94
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 56 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/sanity-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ jobs:
OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }}

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Get object storage namespace
id: test-action-get-os-ns
uses: ./
with:
command: os ns get
command: 'iam compartment list --compartment-id-in-subtree=true'
query: "data[?name=='github-actions'].id"
silent: false

- name: Output object storage namespace
id: output-os-ns
run: echo "${{ steps.test-action-get-os-ns.outputs.output }}"
- name: Echo object storage namespace
id: echo-os-ns-get
run: |
echo "Output: ${{ steps.test-action-get-os-ns.outputs.output}}"
echo "Raw output: ${{ steps.test-action-get-os-ns.outputs.raw_output}}"
- name: Test non-JSON output
id: test-non-json-output
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ jobs:
OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }}
steps:
- name: Retrieve the OCID of a named compartment in tenancy
uses: oracle-actions/[email protected].0
uses: oracle-actions/[email protected].1
id: find-compartment-id
with:
command: 'iam compartment list --compartment-id-in-subtree=true'
query: "data[?name=='testing'].id"

- name: Retrieve the display name and shape of the instances in my compartment
uses: oracle-actions/[email protected].0
uses: oracle-actions/[email protected].1
id: find-instances
with:
command: 'compute instance list --compartment-id ${{ steps.find-compartment-id.outputs.raw_output }}'
Expand Down
38 changes: 21 additions & 17 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.

39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
{
"name": "@oracle-actions/run-oci-cli-command",
"version": "1.3.0",
"description": "Run an Oracle Cloud Infrastructure (OCI) CLI command",
"version": "1.3.1",
"author": {
"name": "Oracle Cloud Infrastructure",
"email": "[email protected]"
},
"description": "Run an Oracle Cloud Infrastructure (OCI) CLI command",
"main": "src/main.ts",
"private": true,
"homepage": "https://github.com/oracle-actions/run-oci-cli-command#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/oracle-actions/run-oci-cli-command.git"
},
"bugs": {
"url": "https://github.com/oracle-actions/run-oci-cli-command/issues"
},
"keywords": [
"github",
"actions",
"oracle-cloud",
"oracle-cloud-infrastructure"
],
"exports": {
".": "./dist/index.js"
},
"engines": {
"node": ">=20"
},
Expand All @@ -15,29 +32,15 @@
"format:write": "npx prettier --write .",
"format:check": "npx prettier --check .",
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
"package": "npx ncc build src/main.ts -o dist --source-map --license LICENSE.txt",
"package": "npx ncc build src/index.ts -o dist --source-map --license LICENSE.txt",
"all": "npm run format:write && npm run lint && npm run package"
},
"repository": {
"type": "git",
"url": "git+https://github.com/oracle-actions/run-oci-cli-command.git"
},
"files": [
"LICENSE.txt",
"THIRD_PARTY_LICENSES.txt",
"dist/*"
],
"keywords": [
"github",
"actions",
"oracle-cloud",
"oracle-cloud-infrastructure"
],
"license": "UPL-1.0",
"bugs": {
"url": "https://github.com/oracle-actions/run-oci-cli-command/issues"
},
"homepage": "https://github.com/oracle-actions/run-oci-cli-command#readme",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Copyright (c) 2024, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
import { runOciCliCommand } from './main'

// eslint-disable-next-line @typescript-eslint/no-floating-promises
runOciCliCommand()
14 changes: 3 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function isJson(item: string): boolean {
* data.
*
*/
async function runOciCliCommand(): Promise<void> {
export async function runOciCliCommand(): Promise<void> {
if (!fs.existsSync(path.join(os.homedir(), '.oci-cli-installed'))) {
core.startGroup('Installing Oracle Cloud Infrastructure CLI')
const cli = await exec.getExecOutput('python -m pip install oci-cli')
Expand All @@ -56,7 +56,6 @@ async function runOciCliCommand(): Promise<void> {
if (silent) core.setSecret(cliCommand)

const cliResult = await exec.getExecOutput(cliCommand, [], { silent: silent })
let stdout = {}
let output = ''
let raw_output = ''

Expand All @@ -65,10 +64,10 @@ async function runOciCliCommand(): Promise<void> {
output = cliResult.stdout
raw_output = cliResult.stdout
} else {
stdout = JSON.parse(cliResult.stdout)
const stdout = JSON.parse(cliResult.stdout)
output = JSON.stringify(JSON.stringify(stdout))
if (Object.keys(stdout).length == 1) {
raw_output = Object.keys(stdout)[0]
raw_output = String(Object.values(stdout)[0])
}
}

Expand All @@ -82,10 +81,3 @@ async function runOciCliCommand(): Promise<void> {
core.setFailed(`Failed: ${JSON.stringify(stderr)}`)
}
}

/**
* Requires OCI CLI environment variables to be set
*/
runOciCliCommand().catch(e => {
if (e instanceof Error) core.setFailed(e.message)
})

0 comments on commit 8a22b94

Please sign in to comment.