From 02aa6d9c22254139f4974c595349e9a56c18c65d Mon Sep 17 00:00:00 2001 From: SmAsHeD <6071159+smashedr@users.noreply.github.com> Date: Sun, 21 Jul 2024 15:31:06 -0700 Subject: [PATCH] Updates (#2) * Updates and Minor Fixes * Add Output * Update Color --- .github/ISSUE_TEMPLATE/0-bug.yaml | 37 ++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 17 ++++++++ .prettierrc.json | 4 +- README.md | 72 ++++++++++++++++++++++++------- action.yaml => action.yml | 10 ++++- commit-checklist.json | 4 ++ dist/index.js | 55 ++++++++++++----------- src/index.js | 55 ++++++++++++----------- 8 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/0-bug.yaml create mode 100644 .github/ISSUE_TEMPLATE/config.yml rename action.yaml => action.yml (71%) create mode 100644 commit-checklist.json diff --git a/.github/ISSUE_TEMPLATE/0-bug.yaml b/.github/ISSUE_TEMPLATE/0-bug.yaml new file mode 100644 index 0000000..581df1e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/0-bug.yaml @@ -0,0 +1,37 @@ +name: "⚠️ Report an Issue" +description: "Something Not Working Right? Please let us know..." +labels: ["bug"] +assignees: + - smashedr + +body: + - type: input + id: website + validations: + required: false + attributes: + label: Repo Link + description: Please provide a link to the repository or workflow you are having issues with if possible. + + - type: textarea + id: description + validations: + required: true + attributes: + label: Details + description: Please describe the issue you are experiencing and how to reproduce. + placeholder: Provide as many details as you can... + + - type: textarea + id: logs + validations: + required: false + attributes: + label: Log Output + description: Paste any relevant logs or output in this box. + render: shell + + - type: markdown + attributes: + value: | + All issues/bugs that we can verify will be fixed. Thank you for taking the time to make this report! diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..84a7231 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,17 @@ +blank_issues_enabled: true +contact_links: + - name: '💡 Request a Feature' + about: Request a New Feature or Enhancement in the Discussions. + url: https://github.com/cssnr/update-version-tags-action/discussions/new?category=feature-requests + + - name: '❔ Ask a Question' + about: Ask a General Question or start a Discussions. + url: https://github.com/cssnr/update-version-tags-action/discussions/new?category=q-a + + - name: '💬 Join Discord' + about: Chat with us about Issues, Features, Questions and More. + url: https://discord.gg/wXy6m2X8wY + + - name: '📝 Submit Feedback' + about: Send General Feedback. + url: https://cssnr.github.io/feedback/?app=Update%20JSON%20Value diff --git a/.prettierrc.json b/.prettierrc.json index 45be804..28cd342 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -5,13 +5,13 @@ "singleQuote": true, "overrides": [ { - "files": ["**/*.json", "**/*.yaml"], + "files": ["**/*.json", "**/*.yaml", "**/*.yml"], "options": { "singleQuote": false } }, { - "files": ["**/*.json", "**/*.yaml"], + "files": ["**/*.json", "**/*.yaml", "**/*.yml"], "options": { "tabWidth": 2 } diff --git a/README.md b/README.md index 464dd9b..671b5df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ [![Tags](https://img.shields.io/github/actions/workflow/status/cssnr/update-json-value-action/tags.yaml?logo=github&logoColor=white&label=tags)](https://github.com/cssnr/update-json-value-action/actions/workflows/tags.yaml) -[![CSSNR Website](https://img.shields.io/badge/pages-website-blue?logo=github&logoColor=white&color=blue)](https://cssnr.github.io/) +[![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/update-json-value-action?logo=github)](https://github.com/cssnr/update-json-value-action/releases/latest) +[![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/update-json-value-action?logo=htmx&logoColor=white)](https://github.com/cssnr/update-json-value-action) +[![GitHub Org Stars](https://img.shields.io/github/stars/cssnr?style=flat&logo=github&logoColor=white)](https://cssnr.github.io/) [![Discord](https://img.shields.io/discord/899171661457293343?logo=discord&logoColor=white&label=discord&color=7289da)](https://discord.gg/wXy6m2X8wY) + # Update JSON Value Action Update JSON file Value(s) for Publishing. @@ -8,9 +11,11 @@ Update JSON file Value(s) for Publishing. Zero configuration to update a `manifest.json` file `version` value to a release tag. Allows setting multiple key/value pairs and setting nested keys. Arrays are not supported yet. -* [Inputs](#Inputs) -* [Examples](#Examples) -* [Support](#Support) +* [Inputs](#Inputs) +* [Outputs](#Outputs) +* [Examples](#Examples) +* [Support](#Support) +* [Contributing](#Contributing) > [!NOTE] > Please submit a @@ -19,24 +24,32 @@ Allows setting multiple key/value pairs and setting nested keys. Arrays are not ## Inputs -| input | required | default | description | -|--------|----------|------------------|-----------------------------------| -| file | No | manifest.json | JSON File Path | -| keys | No | version | JSON Keys to Update, One per Line | -| values | No | $GITHUB_REF_NAME | Values to Update, One per Line | - -If no options are passed, it will update the `manifest.json` file key `version` to the value of `GITHUB_REF_NAME`. -For multiple `keys` and `values` use new lines. Nested keys are specified using `.` notation. +| input | required | default | description | +|--------|----------|--------------------|-----------------------------------| +| file | No | `manifest.json` | JSON File Path | +| keys | No | `version` | JSON Keys to Update, One per Line | +| values | No | `$GITHUB_REF_NAME` | Values to Update, One per Line | +| write | No | `true` | Write Updates to `file` | -## Examples +If no options are passed, it will update the `manifest.json` file's key `version` to the value of `GITHUB_REF_NAME`. +For multiple `keys` and `values` use new lines with a yaml `|`. +Nested keys are specified using `.` notation. -Update the `manifest.json` file key `version` to the current `GITHUB_REF_NAME`. ```yaml - name: 'Update JSON' uses: cssnr/update-json-value-action@v1 ``` +## Outputs + +| output | description | +|--------|---------------------| +| result | Updated JSON String | + +## Examples + Same as above but manually setting values and only running on `release` events. + ```yaml - name: 'Update JSON' uses: cssnr/update-json-value-action@v1 @@ -48,6 +61,7 @@ Same as above but manually setting values and only running on `release` events. ``` Same as above but also setting an additional key value pair. + ```yaml - name: 'Update JSON' uses: cssnr/update-json-value-action@v1 @@ -63,6 +77,7 @@ Same as above but also setting an additional key value pair. ``` Set a nested key and use file from different directory. + ```yaml - name: 'Update JSON' uses: cssnr/update-json-value-action@v1 @@ -75,6 +90,17 @@ Set a nested key and use file from different directory. "Release ${{ github.ref_name }}" ``` +Use the Output. + +```yaml +- name: 'Update JSON' + id: json + uses: cssnr/update-json-value-action@v1 + +- name: "Echo Result" + run: echo '${{ steps.json.outputs.result }}' +``` + # Support For general help or to request a feature, see: @@ -86,4 +112,20 @@ If you are experiencing an issue/bug or getting unexpected results, you can: - Report an Issue: https://github.com/cssnr/update-json-value-action/issues - Chat with us on Discord: https://discord.gg/wXy6m2X8wY -- Provide General Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=Update%20JSON%20Value) +- Provide General + Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=Update%20JSON%20Value) + +# Contributing + +Currently, the best way to contribute to this project is to star this project on GitHub. + +Additionally, you can support other GitHub Actions I have published: + +- [VirusTotal Action](https://github.com/cssnr/virustotal-action) +- [Update Version Tags Action](https://github.com/cssnr/update-version-tags-action) +- [Update JSON Value Action](https://github.com/cssnr/update-json-value-action) +- [Parse Issue Form Action](https://github.com/cssnr/parse-issue-form-action) +- [Portainer Stack Deploy](https://github.com/cssnr/portainer-stack-deploy-action) +- [Mozilla Addon Update Action](https://github.com/cssnr/mozilla-addon-update-action) + +For a full list of current projects to support visit: [https://cssnr.github.io/](https://cssnr.github.io/) diff --git a/action.yaml b/action.yml similarity index 71% rename from action.yaml rename to action.yml index 223715a..0a76614 100644 --- a/action.yaml +++ b/action.yml @@ -8,7 +8,7 @@ branding: inputs: file: description: "JSON File" - required: true + required: false default: "manifest.json" keys: description: "Keys to Update" @@ -17,6 +17,14 @@ inputs: values: description: "Values to Set" required: false + write: + description: "Write Result to File" + required: false + default: "true" + +outputs: + result: + description: "JSON Output Results" runs: using: "node20" diff --git a/commit-checklist.json b/commit-checklist.json new file mode 100644 index 0000000..2dd6851 --- /dev/null +++ b/commit-checklist.json @@ -0,0 +1,4 @@ +[ + { "value": "Run Build", "fileMask": "*src\\*.js" }, + { "value": "Check main in action.yml", "fileMask": "*action.yml" } +] diff --git a/dist/index.js b/dist/index.js index 60eb77e..b9e092d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26813,49 +26813,54 @@ const fs = __nccwpck_require__(7147) try { // Parse Inputs const inputFile = core.getInput('file') - console.log('file:', inputFile) + console.log('inputFile:', inputFile) const inputKeys = core.getInput('keys') console.log('inputKeys:', inputKeys) - const inputValues = core.getInput('values') + const inputValues = + core.getInput('values') || process.env.GITHUB_REF_NAME console.log('inputValues:', inputValues) + const writeFile = core.getBooleanInput('write') + console.log('writeFile:', writeFile) // Parse Keys - if (!inputKeys) { - return core.setFailed('No Keys Found.') - } - const parsedKeys = inputKeys.split('\n') - console.log('parsedKeys:', parsedKeys) + const keys = inputKeys.split('\n') + console.log('keys:', keys) // Parse Values - const parsedValues = [] - if (!inputValues) { - parsedValues.push(process.env.GITHUB_REF_NAME) - } else { - parsedValues.push(...inputValues.split('\n')) - } - console.log('parsedValues:', parsedValues) + const values = inputValues.split('\n') + console.log('values:', values) - // Validate Parsed Inputs - if (parsedKeys.length !== parsedValues.length) { - return core.setFailed('Keys and Values are not equal in length.') + // Validate Inputs + if (keys.length !== values.length) { + return core.setFailed('Keys and Values length are not equal.') } // Update JSON - let file = fs.readFileSync(inputFile) - let data = JSON.parse(file.toString()) - for (let i = 0; i < parsedKeys.length; i++) { - const key = parsedKeys[i] - const value = parsedValues[i] - console.log(`-- ${i} -- ${key}: ${value}`) + const file = fs.readFileSync(inputFile) + const data = JSON.parse(file.toString()) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + const value = values[i] + console.log(`--- ${i + 1}: ${key}: ${value}`) setNestedValue(data, key, value) } - let result = JSON.stringify(data, null, 2) - fs.writeFileSync(inputFile, result) // Display Result + const result = JSON.stringify(data, null, 2) console.log('-'.repeat(40)) console.log(result) console.log('-'.repeat(40)) + + // Write File + if (writeFile) { + core.info(`\u001b[32;1mWriting result to file: ${inputFile}`) + fs.writeFileSync(inputFile, result) + } else { + core.info('\u001b[33;1mNot writing file because write is false.') + } + + // Set Output + core.setOutput('result', JSON.stringify(data)) } catch (e) { core.debug(e) core.info(e.message) diff --git a/src/index.js b/src/index.js index 0e97da7..8522507 100644 --- a/src/index.js +++ b/src/index.js @@ -5,49 +5,54 @@ const fs = require('fs') try { // Parse Inputs const inputFile = core.getInput('file') - console.log('file:', inputFile) + console.log('inputFile:', inputFile) const inputKeys = core.getInput('keys') console.log('inputKeys:', inputKeys) - const inputValues = core.getInput('values') + const inputValues = + core.getInput('values') || process.env.GITHUB_REF_NAME console.log('inputValues:', inputValues) + const writeFile = core.getBooleanInput('write') + console.log('writeFile:', writeFile) // Parse Keys - if (!inputKeys) { - return core.setFailed('No Keys Found.') - } - const parsedKeys = inputKeys.split('\n') - console.log('parsedKeys:', parsedKeys) + const keys = inputKeys.split('\n') + console.log('keys:', keys) // Parse Values - const parsedValues = [] - if (!inputValues) { - parsedValues.push(process.env.GITHUB_REF_NAME) - } else { - parsedValues.push(...inputValues.split('\n')) - } - console.log('parsedValues:', parsedValues) + const values = inputValues.split('\n') + console.log('values:', values) - // Validate Parsed Inputs - if (parsedKeys.length !== parsedValues.length) { - return core.setFailed('Keys and Values are not equal in length.') + // Validate Inputs + if (keys.length !== values.length) { + return core.setFailed('Keys and Values length are not equal.') } // Update JSON - let file = fs.readFileSync(inputFile) - let data = JSON.parse(file.toString()) - for (let i = 0; i < parsedKeys.length; i++) { - const key = parsedKeys[i] - const value = parsedValues[i] - console.log(`-- ${i} -- ${key}: ${value}`) + const file = fs.readFileSync(inputFile) + const data = JSON.parse(file.toString()) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + const value = values[i] + console.log(`--- ${i + 1}: ${key}: ${value}`) setNestedValue(data, key, value) } - let result = JSON.stringify(data, null, 2) - fs.writeFileSync(inputFile, result) // Display Result + const result = JSON.stringify(data, null, 2) console.log('-'.repeat(40)) console.log(result) console.log('-'.repeat(40)) + + // Write File + if (writeFile) { + core.info(`\u001b[32;1mWriting result to file: ${inputFile}`) + fs.writeFileSync(inputFile, result) + } else { + core.info('\u001b[33;1mNot writing file because write is false.') + } + + // Set Output + core.setOutput('result', JSON.stringify(data)) } catch (e) { core.debug(e) core.info(e.message)