A GitHub Action that allows you to find and replace text in files by matching a string.
Go to file
Riccardo Rigutini 008d582ac3
Update dist folder
2024-05-27 19:54:13 +00:00
.github Update Dependabot commit message 2024-05-13 18:03:37 +00:00
__tests__ Use replaceAll to replace all instances of search text 2024-05-02 07:48:55 +00:00
dist Update dist folder 2024-05-27 19:54:13 +00:00
src Use replaceAll to replace all instances of search text 2024-05-02 07:48:55 +00:00
test-files Use replaceAll to replace all instances of search text 2024-05-02 07:48:55 +00:00
.eslintignore Initial commit 2023-07-02 14:39:21 +02:00
.eslintrc.json Initial commit 2023-07-02 14:39:21 +02:00
.gitattributes Initial commit 2023-07-02 14:39:21 +02:00
.gitignore Initial commit 2023-07-02 14:39:21 +02:00
.prettierignore Initial commit 2023-07-02 14:39:21 +02:00
.prettierrc.json Initial commit 2023-07-02 14:39:21 +02:00
CHANGELOG.md Initial commit 2023-07-02 14:39:21 +02:00
CODEOWNERS Initial commit 2023-07-02 14:39:21 +02:00
LICENSE Initial commit 2023-07-02 14:39:21 +02:00
README.md Add documentation for max-parallelism option 2023-11-10 17:52:00 +00:00
action.yml Add max parallelism as input option 2023-11-10 17:40:57 +00:00
jest.config.js Initial commit 2023-07-02 14:39:21 +02:00
package-lock.json [chore] Bump glob from 10.3.15 to 10.4.1 2024-05-27 11:36:49 +00:00
package.json [chore] Bump glob from 10.3.15 to 10.4.1 2024-05-27 11:36:49 +00:00
tsconfig.json Use replaceAll to replace all instances of search text 2024-05-02 07:48:55 +00:00

README.md

Replace in files

This GitHub Action allows you to find and replace text in files by matching a string.

It can be useful for automating repetitive tasks such as updating version numbers, replacing placeholders, or modifying configuration files during deployment.

Features

  • Specify the files to be searched using a glob pattern. You can also specify files to be excluded from the search.
  • Find and replace all the occurrences of a string in the repository files.
  • Supports different file encodings, including UTF-8, UTF-16, and ASCII.
  • Works on every platform that supports JavaScript actions, including Linux, macOS, and Windows.

Inputs

  • files: (Required) The files to be searched. It can be the path to a single file, or a glob pattern matching one or more files (e.g. **/*.txt).

  • replacement-text: (Required) The text that will replace the matched text.

  • search-text: (Required) The text that will be replaced.

  • encoding: (Optional) The encoding of the files to be searched. The following values are supported: utf8, utf16le, latin1, ascii, base64, hex. Defaults to utf8.

  • exclude: (Optional) The files to be excluded from the search. It can be the path to a file or a glob pattern matching one or more files (e.g. **/*.md). Defaults to an empty string.

  • max-parallelism: (Optional) The maximum number of files that will be processed in parallel. This can be used to control the performance impact of the operation on the system. It should be a positive integer. Defaults to 10.

Example usage

# Replace all the occurrences of 'hello' with 'world' in all the txt files, 
# excluding the node_modules folder
- name: Replace multiple files
  uses: richardrigutins/replace-in-files@v2
  with:
    files: '**/*.txt'
    search-text: 'hello'
    replacement-text: 'world'
    exclude: 'node_modules/**'
    encoding: 'utf8'
    max-parallelism: 10

# Replace all the occurrences of '{0}' with '42' in the README.md file
- name: Replace single file
  uses: richardrigutins/replace-in-files@v2
  with:
    files: 'README.md'
    search-text: '{0}'
    replacement-text: '42'

Contributing

Contributions are welcome! Here are some ways you can contribute:

  • Report bugs and suggest new features by creating an issue.
  • Improve the documentation by submitting a pull request.
  • Fix bugs or implement new features by submitting a pull request.

Before submitting a pull request, please make sure that your changes are consistent with the project's coding style and that all tests pass. To build and run all the tests and linters, run the following command:

npm run all

Be sure to also include the updated dist folder in your pull request.