asmith-nhsx / gha-find-replace

A GitHub Action to find and replace strings in project files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find and Replace Action

GitHub Marketplace Actions Status Actions Status

This action will find and replace strings in your project files.

Usage

Example workflow

This example replaces hello with world in all of your project files.

name: My Workflow
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Find and Replace
        uses: jacobtomlinson/gha-find-replace@v2
        with:
          find: "hello"
          replace: "world"
          regex: false

Inputs

Input Description
find A string to find and replace in your project files. (Defaults to a regular expression.)
replace The string to replace it with.
include (optional) A glob of files to include. Defaults to **.
exclude (optional) A glob of files to exclude. Defaults to .git/** .
regex (optional) Whether to match with.find as a regular expression instead of a fixed string. Defaults to true.

Outputs

Output Description
modifiedFiles The number of files that have been modified

Examples

Including a subdirectory

You can limit your find and replace to a directory.

name: My Workflow
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Find and Replace
        uses: jacobtomlinson/gha-find-replace@v2
        with:
          find: "hello"
          replace: "world"
          include: "justthisdirectory/**"
          regex: true

Filter by file name

You can limit your find and replace to just files with a specific name.

name: My Workflow
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Find and Replace
        uses: jacobtomlinson/gha-find-replace@v2
        with:
          find: "hello"
          replace: "world"
          include: "**README.md" # Will match all README.md files in any nested directory

Exclude by file type

You can set your find and replace to ignore certain file types.

name: My Workflow
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Find and Replace
        uses: jacobtomlinson/gha-find-replace@v2
        with:
          find: "hello"
          replace: "world"
          exclude: "**/*.py" # Do not modify Python files

Publishing

To publish a new version of this Action we need to update the Docker image tag in action.yml and also create a new release on GitHub.

  • Work out the next tag version number.
  • Update the Docker image in action.yml.
  • Create a new release on GitHub with the same tag.

About

A GitHub Action to find and replace strings in project files.

License:MIT License


Languages

Language:Go 87.4%Language:Dockerfile 12.6%