https://github.com/iamthenoah/gh-action-update-json
GitHub Action for updating key-value pairs in JSON files and committing changes to your repository.
https://github.com/iamthenoah/gh-action-update-json
automation cicd json workflow
Last synced: 5 months ago
JSON representation
GitHub Action for updating key-value pairs in JSON files and committing changes to your repository.
- Host: GitHub
- URL: https://github.com/iamthenoah/gh-action-update-json
- Owner: iamthenoah
- License: mit
- Created: 2024-10-09T12:42:52.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-04T09:58:46.000Z (over 1 year ago)
- Last Synced: 2025-03-04T10:39:14.580Z (over 1 year ago)
- Topics: automation, cicd, json, workflow
- Language: TypeScript
- Homepage:
- Size: 370 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/iamthenoah/update-json-file/actions/workflows/build.yml)
[](https://github.com/iamthenoah/gh-action-update-json/actions/workflows/publish.yml)
# Update JSON File Workflow
This GitHub Actions workflow updates a specified key in a JSON file and commits the changes to a specified branch.
## Description
The workflow takes a JSON file path, a key to update, and the new value. It can optionally commit the changes to a specified branch with a customizable commit message.
## Usage
To use this workflow, add it to your GitHub Actions configuration.
### Inputs
| **Input** | **Description** | **Required** | **Default** |
|-----------|---------------------------------------------------------------------------------|--------------|---------------------------------|
| `file` | Relative path of the JSON file to update from the root of the repo. | Yes | — |
| `key` | The key in the JSON file to update (e.g. `my.nested.key`). | Yes | — |
| `value` | The new value to assign to the specified key. | Yes | — |
| `commit` | Whether to commit the changes. | No | `'true'` |
| `branch` | Branch to commit the changes to. Defaults to the current branch if unspecified. | No | _current branch_ |
| `message` | Commit message. Supports placeholders: `%f` = file, `%k` = key, `%v` = value. | No | `'Updated %f with %k:%v.'` |
| `name` | Commit author name. | No | `'Github Workflow'` |
| `email` | Commit author email. | No | `'noreply@github-workflow.com'` |
### Example
Here’s an example of how to configure the workflow in your GitHub Actions file to update :
```yaml
name: Update package.json version
on:
push:
tags:
- 'v*'
jobs:
update-package-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Package Json version
uses: iamthenoah/gh-action-update-json@v4
with:
# The 'file' input specifies the relative path of the JSON file to update from the root.
# Default: None, Required: true
file: './package.json'
# The 'key' input is the key in the JSON file to update (e.g., 'my.nested.key').
# Default: None, Required: true
key: 'version'
# The 'value' input specifies the value to set for the key.
# Default: None, Required: true
value: ${{ github.ref_name }}
# The 'branch' input specifies the branch to commit changes to.
# Default: '', Required: false
branch: 'master'
# The 'message' input is the custom commit message format.
# Default: 'Updated %f with `%k:%v`.', Required: false
message: 'Updated %f version to `%v`'
# The 'name' input specifies the name shown as the commit sender.
# Default: 'Github Workflow', Required: false
name: 'My Workflow'
# The 'email' input sets the email of the committer.
# Default: 'noreply@github-workflow.com', Required: false
email: 'workflow@example.com'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
```
## Permissions
This workflow requires elevated permissions in order to commit changes to a repositry. To account for this, add the following in the root of the workflow or job:
```yaml
permissions:
contents: write
```
## License
This project is licensed under the MIT License.