diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 522aa01..1a4ac73 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -16,7 +16,15 @@ jobs: include: "test/" find: "world" replace: "there" + - name: Self test + id: selftest2 + uses: ./ + with: + include: "test/" + Hello: "there.." + - name: Check outputs and modified files run: | test "${{ steps.selftest.outputs.modifiedFiles }}" == "1" - grep "Hello there" test/hello.txt + test "${{ steps.selftest2.outputs.modifiedFiles }}" == "1" + grep "there.. there" test/hello.txt diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3605df4..03b5294 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master with: - name: jacobtomlinson/gha-find-replace + name: mpede/gha-find-replace username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} tags: "latest,${{ env.RELEASE_VERSION }}" diff --git a/main.go b/main.go index 9e6b952..f44a92f 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "log" "os" + "strings" "path/filepath" "regexp" ) @@ -59,17 +60,52 @@ func main() { find := os.Getenv("INPUT_FIND") replace := os.Getenv("INPUT_REPLACE") + reserved := []string{"INCLUDE","EXCLUDE","FIND","REPLACE"} + + INPUT_PREFIX := "INPUT_" + files, filesErr := listFiles(include, exclude) check(filesErr) modifiedCount := 0 - for _, path := range files { - modified, findAndReplaceErr := findAndReplace(path, find, replace) - check(findAndReplaceErr) + if find!="" && replace!="" { + for _, path := range files { + modified, findAndReplaceErr := findAndReplace(path, find, replace) + check(findAndReplaceErr) + + if modified { + modifiedCount++ + } + } + } + + for _, pair := range os.Environ() { + if strings.Contains(pair,INPUT_PREFIX) { + keyValue := strings.SplitN(pair,"=",2) + find := strings.SplitN(keyValue[0],"_",2)[1] + replace := keyValue[1] + + found := false + for i := 0; i