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

Add required property #2

Merged
merged 2 commits into from
Feb 2, 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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ jobs:
name: A test job to read a value from json as a variable
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Read a json file
uses: ./
id: read
with:
input-file: 'package.json'
input-property: 'author.name' # Exp: 'fiddlermikey'
- name: Read a json file
uses: ./
id: read-nofail
with:
input-file: 'package.json'
input-property: 'foo' # does not exist
required-value: 'false' # Ignore if not present
- name: Display property value for input-property in input-file
id: write
run: echo "The value for ${{ steps.read.outputs.output-property }} is ${{ steps.read.outputs.output-value }}"
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
description: 'Root-level or nested property using dot notation'
required: true
default: 'package.json'
required-value:
description: 'Fail if not found'
required: false
default: 'false'
outputs:
output-property:
description: 'The value of input-property'
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2836,12 +2836,14 @@ const fs = __nccwpck_require__(147);
const core = __nccwpck_require__(186);
try {
const item = core.getInput('input-property') || 'foo'
const requiredValue = core.getInput('required-value') || 'false'
const inputFile = core.getInput('input-file') || 'package.json'
const newdata = JSON.parse(fs.readFileSync(inputFile))
const outValue = eval("newdata." + item)
var outValue = ''
outValue = eval("newdata." + item)
core.setOutput('output-property', item);
core.setOutput('output-value', outValue);
if (outValue === undefined) {
if (outValue === undefined && requiredValue == 'true') {
core.setFailed('Property: ' + item + ' does not exist in ' + inputFile);
}
}
Expand Down
6 changes: 4 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ const fs = require('fs');
const core = require('@actions/core');
try {
const item = core.getInput('input-property') || 'foo'
const requiredValue = core.getInput('required-value') || 'false'
const inputFile = core.getInput('input-file') || 'package.json'
const newdata = JSON.parse(fs.readFileSync(inputFile))
const outValue = eval("newdata." + item)
var outValue = ''
outValue = eval("newdata." + item)
core.setOutput('output-property', item);
core.setOutput('output-value', outValue);
if (outValue === undefined) {
if (outValue === undefined && requiredValue == 'true') {
core.setFailed('Property: ' + item + ' does not exist in ' + inputFile);
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"precommit": "npm run build && git add dist/"
},
"author": {
"name": "fiddlermikey"
"name": "fiddlermikey",
"email": "[email protected]"
},
"devDependencies": {
"eslint": "^8.21.0"
Expand Down