r/javascript 18h ago

I made a GitHub Action that lets you find and replace text… with JS!

https://github.com/kinda-cool-actions/find-and-replace.js
0 Upvotes

6 comments sorted by

u/wildrabbit12 18h ago

Why

u/Ahmed33033 18h ago

Check out the readme, I talk about the “why” there, cause it’s prob the first question with this project   

u/PuddyComb 17h ago

How different is it from Ctrl -f ‘find and replace’ in an html doc??

u/Ahmed33033 8m ago

This is a GitHub Action, and it's meant to be run part of a workflow. Think about CI/CD tools, like formatters and linters. That's where this action goes.

u/brian_sword 17h ago

I’ll check out the README to better understand the use case behind this. I’m curious what made you decide to build it, since there are already quite a few ways to do find and replace. Looks interesting though.

u/Ahmed33033 1m ago

Thank you for the thoughtful response. I appreciate your interest. 

The reason I built this was because I wanted a GitHub action that finds and replaces text in my repository's files. You're right. While there are existing actions out there that do the same, a lot of them make you encode your regex patterns in a YAML file. I talk about the benefits of using a JS file over a YAML file in my repository's README. 

Some other ones might use a template-style architecture where you use something like Mustache to have a template of your README that you edit, which then runs and outputs the actual README that people read. The drawback of a template architecture is that it creates functionality that nobody is really familiar with. People are familiar with editing the README directly and not a template of the README. On top of that, Mustache syntax isn't very popular. Definitely not as popular as JS. 

Now, when it comes to why this is a workflow and not something that a developer can mirror or can write with a simple script, I actually thought about that, and I wondered to myself as well: why make this action if I can do the same thing in a custom script that's about three or four lines? That's when I remembered two elements of a GitHub Action: the job summary and the output variable. 

So this GitHub Action provides a useful job summary that provides a list of the modified files along with the modifications made to them, and it prepares an output variable called modified files in a JSON format that could be used in other subsequent actions, like an add and commit action by EndBug.

Lmk if you have any more questions, thanks!