Skip to content

Commit

Permalink
feat: Make include_file overrule include_ext, fixes: #350, base_on: #358
Browse files Browse the repository at this point in the history
 (#416)

* feat: Make include_file overrule include_ext

* feat: Make include_file overrule include_ext unittest
  • Loading branch information
zhb127 authored Sep 22, 2024
1 parent 7187d7f commit c75a2f5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions runner/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (e *Engine) cacheFileChecksums(root string) error {
}
}

if e.isExcludeFile(path) || !e.isIncludeExt(path) {
if e.isExcludeFile(path) || !e.isIncludeExt(path) && !e.checkIncludeFile(path) {
e.watcherDebug("!exclude checksum %s", e.config.rel(path))
return nil
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (e *Engine) watchPath(path string) error {
if excludeRegex {
break
}
if !e.isIncludeExt(ev.Name) {
if !e.isIncludeExt(ev.Name) && !e.checkIncludeFile(ev.Name) {
break
}
e.watcherDebug("%s has changed", e.config.rel(ev.Name))
Expand Down Expand Up @@ -328,7 +328,7 @@ func (e *Engine) start() {
e.mainDebug("exit in start")
return
case filename = <-e.eventCh:
if !e.isIncludeExt(filename) {
if !e.isIncludeExt(filename) && !e.checkIncludeFile(filename) {
continue
}
if e.config.Build.ExcludeUnchanged {
Expand Down
59 changes: 59 additions & 0 deletions runner/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,62 @@ include_file = ["main.sh"]
}
assert.Equal(t, []byte("modified"), bytes)
}

func TestShouldIncludeIncludedFileWihtoutIncludedExt(t *testing.T) {
port, f := GetPort()
f()
t.Logf("port: %d", port)

tmpDir := initTestEnv(t, port)

chdir(t, tmpDir)

config := `
[build]
cmd = "true" # do nothing
full_bin = "sh main.sh"
include_ext = ["go"]
include_dir = ["nonexist"] # prevent default "." watch from taking effect
include_file = ["main.sh"]
`
if err := ioutil.WriteFile(dftTOML, []byte(config), 0o644); err != nil {

Check failure on line 1014 in runner/engine_test.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: ioutil (typecheck)

Check failure on line 1014 in runner/engine_test.go

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

undefined: ioutil (typecheck)
t.Fatal(err)
}

err := os.WriteFile("main.sh", []byte("#!/bin/sh\nprintf original > output"), 0o755)
if err != nil {
t.Fatal(err)
}

engine, err := NewEngine(dftTOML, false)
if err != nil {
t.Fatal(err)
}
go func() {
engine.Run()
}()

time.Sleep(time.Second * 1)

bytes, err := os.ReadFile("output")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, []byte("original"), bytes)

t.Logf("start change main.sh")
go func() {
err := os.WriteFile("main.sh", []byte("#!/bin/sh\nprintf modified > output"), 0o755)
if err != nil {
log.Fatalf("Error updating file: %s.", err)
}
}()

time.Sleep(time.Second * 3)

bytes, err = os.ReadFile("output")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, []byte("modified"), bytes)
}

0 comments on commit c75a2f5

Please sign in to comment.