https://github.com/onlyutkarsh/patch-files-action
A GitHub action to patch JSON files.
https://github.com/onlyutkarsh/patch-files-action
actions json
Last synced: about 1 year ago
JSON representation
A GitHub action to patch JSON files.
- Host: GitHub
- URL: https://github.com/onlyutkarsh/patch-files-action
- Owner: onlyutkarsh
- License: mit
- Created: 2020-03-30T20:27:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T07:45:48.000Z (over 3 years ago)
- Last Synced: 2025-03-24T09:42:34.314Z (about 1 year ago)
- Topics: actions, json
- Language: TypeScript
- Homepage: https://github.com/marketplace/actions/patch-files
- Size: 312 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Patch files
A simple action to patch JSON files.
> Only JSON files are supported at the moment. Support for other file types is planned in the later versions.
## Inputs
- `files`
Glob expression. See example action YAML below. *Required.*
- `patch-syntax`
Use the `operation syntax => value` syntax to patch the JSON file. *Required.*
Supported Operations:
- `+` add. Example: `+ /version => "1.0.0"`
- `-` remove. Example: `- /version` **Note:** No value is passed.
- `=` replace. Example: `= /version => "1.0.1"`
**Example**:
Input JSON:
```json
{
"version": "1.0.0",
"keywords": [],
"bugs": {
"url": "http://www.dummy.com"
}
}
```
Patch Syntax:
```yaml
patch-syntax: |
= /version => "1.0.1"
+ /author => "John Smith"
= /bugs/url => "https://www.mydomain.com"
```
Output JSON:
```json
{
"version": "1.0.1",
"keywords": [],
"author": "John Smith",
"bugs": {
"url": "https://www.mydomain.com"
}
}
```
- `output-patched-file`
If `true`, the patched content is printed in the logs. *Optional. Default is `true`*.
- `fail-if-no-files-patched`
If `true`, fails the build, if no files are patched. *Optional. Default is `false`*.
- `fail-if-error`
If `true`, failes the build when an error occurrs. *Optional. Default is `false`*
## Sample action
```yaml
name: "test action"
on:
pull_request:
push:
branches:
- master
- 'feature/*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Patch files
uses: onlyutkarsh/patch-files-action@v1.0.1
env:
name: utkarsh
with:
files: |
testfiles/**/*.json
patch-syntax: |
= /version => "1.0.1"
+ /author => "${{ env.name }}"
= /bugs/url => "https://www.google.com"
+ /buildId => "${{ github.run_number }}"
```
## Acknowledgment
- Inspired from https://marketplace.visualstudio.com/items?itemName=geeklearningio.gl-vsts-tasks-file-patch task for Azure Pipelines