jaywcjlove / github-action-modify-file-content

Replace text content and submit content

Home Page:https://jaywcjlove.github.io/github-action-modify-file-content

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to replace and remove the delimiters

stecullum opened this issue · comments

Hi thanks for your great work. I have things working but its awkward when we have lots of tokens. But as the code replaces within the delimiters and still leaves the delimiters in the destination file, things get messy when trying to update a document

Do you think you could just support a direct string replacement eg sed s/!!image!!/value/gp kind of construct. At the moment I have to be very careful with the tokens used and they need to match the code language and obviously leaving the start/end tokens in the file is not very good when editing documents..

Ideally ..

  body: myimage:123
  token: !!image!!

Currenty I have this and its ok for yaml as long as i use comments etc

   ##start_image> 
   image: xxx
   ##end_image 

which leaves me with this file..

   ##start_image> 
   image: myimage:123
   ##end_image 

But it would be much nicer to say

  image: !!image!!
  something: !!another!!

And have the result as image: 123 and something:abc

@stecullum Using the comment tag <!--GAMFC-->, it can be hidden and shown on GitHub. If you use the image: !!image!! tag and replace it in a commit, I won't be able to accurately find it in the next commit.

DOH..!!
of course

Can you provide any guidance..on how to provide the body with new lines/whitespacing etc..

See example below....

For this yaml file

## note the white space/indentation
    image: myimage
    ##<
    tag: replaceme:1.2.3.
    ##>

Using this action...

     - name: Modify pull-request files
        uses: jaywcjlove/github-action-modify-file-content@main
        with:
          branch: ${{ fromJson(steps.release.outputs.pr).headBranchName }}
          body: "tag: myapp-1.0.0"
          path: 'helm-release.yaml'
          openDelimiter: '##<'    # its a yaml file so try and use comments indicators so as not to pollute
          closeDelimiter: '##>'   # its a yaml file so try and use comments indicators so as not to pollute

The output of the file is...wrong

## note the white space/indentation is correct
    ##<tag: myapp-1.0.0##>

expected...

## note the white space/indentation
    image: myimage
    ##<
    tag: myapp:1.0.0
    ##>