Skip to content

Commit

Permalink
Add expose-json-outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
serbantarmure committed Nov 15, 2023
1 parent 993a062 commit 2240ff2
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 5 deletions.
2 changes: 2 additions & 0 deletions expose-json-outputs/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn 1.17.3
nodejs 16.16.0
19 changes: 19 additions & 0 deletions expose-json-outputs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Expose JSON Outputs

This action exposes JSON input as a set of outputs.

## Expose JSON as outputs

Proxies JS shared action outputs from composite actions. See gsm-secrets as an example of the issue.

### Inputs

The list of arguments, that are used in GH Action:

| name | type | required | default | description |
| ------ | ------ | -------- | ------- | ---------------------- |
| `json` | string || | JSON string to process |

## Contributing

We would love for you to contribute to `toptal/actions/tree/main/expose-json-outputs`, pull requests are welcome!
12 changes: 12 additions & 0 deletions expose-json-outputs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Expose JSON as outputs'
description: 'Proxies JS shared action outputs from composite actions. See gsm-secrets as an example of the issue.'
author: 'Dev X'
inputs:
json:
description: 'JSON string to process'
required: true
# outputs are intentionally not declared due to the dynamic nature of the outputs
# outputs:
runs:
using: 'node16'
main: 'dist/index.js'
1 change: 1 addition & 0 deletions expose-json-outputs/dist/index.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions expose-json-outputs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "expose-json-outputs",
"version": "1.0.0",
"description": "Exposes JSON input as a set of outputs",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "ncc build --minify -o dist src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/toptal/davinci-github-actions.git"
},
"keywords": [
"actions",
"node",
"json"
],
"author": "Dev X",
"bugs": {
"url": "https://github.com/toptal/davinci-github-actions/issues"
},
"homepage": "https://github.com/toptal/davinci-github-actions/expose-json-outputs#readme",
"dependencies": {
"@actions/core": "^1.10.0"
},
"devDependencies": {
"@vercel/ncc": "^0.36.1"
}
}
15 changes: 15 additions & 0 deletions expose-json-outputs/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const core = require('@actions/core')

try {
const jsonString = core.getInput('json')
core.debug(`json: ${jsonString}`)
const jsonObj = JSON.parse(jsonString)

for (const key in jsonObj) {
if (jsonObj.hasOwnProperty(key)) {
core.setOutput(key, jsonObj[key])
}
}
} catch (error) {
core.setFailed(error.message)
}
33 changes: 33 additions & 0 deletions expose-json-outputs/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@actions/core@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.0.tgz#44551c3c71163949a2f06e94d9ca2157a0cfac4f"
integrity sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==
dependencies:
"@actions/http-client" "^2.0.1"
uuid "^8.3.2"

"@actions/http-client@^2.0.1":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-2.1.0.tgz#b6d8c3934727d6a50d10d19f00a711a964599a9f"
integrity sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==
dependencies:
tunnel "^0.0.6"

"@vercel/ncc@^0.36.1":
version "0.36.1"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.36.1.tgz#d4c01fdbbe909d128d1bf11c7f8b5431654c5b95"
integrity sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==

tunnel@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==

uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
8 changes: 3 additions & 5 deletions gsm-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ Action to get Google Secret Manager secrets. This action is based on google-gith

Unfortunately, due to the specifics of GHA implementation for composite actions, it is not possible to expose arbitrary outputs, so this action goes hand by hand with a [parser](../expose-json-outputs/README.md) that exposes a JSON string as outputs of a JS action, which is able to expose arbitrary outputs.


> To prevent accidentally committing credentials please add these lines to .gitignore file:
```
# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json
```
# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json

0 comments on commit 2240ff2

Please sign in to comment.