Compare commits

...

23 Commits

Author SHA1 Message Date
Max Claus Nunes c44dd59952 Update doc to include "program-args" example 2023-04-27 18:16:36 -03:00
Max Claus Nunes 5a02122f33
Merge pull request #18 from maxcnunes/fix-ci
Fix CI tasks
2022-08-08 14:34:12 -03:00
Max Claus Nunes edee55552a Add name workflow 2022-08-08 14:31:37 -03:00
Max Claus Nunes d314b7b928 Add missing test files 2022-08-08 11:47:49 -03:00
Max Claus Nunes f0479bba61 Fix lint CI 2022-08-08 11:40:24 -03:00
Max Claus Nunes 90f855c72b Use Github actions 2022-08-08 11:14:30 -03:00
Max Claus Nunes 1fde6281f1 Ignore go-tmp-unmask
Closes https://github.com/maxcnunes/gaper/issues/13
2022-08-07 10:47:30 -03:00
Max Claus Nunes 95fc7d2127 Update cli to v2 2022-08-07 10:40:15 -03:00
Max Claus Nunes b0dcdd49b0 Add extensions example 2022-08-07 10:30:58 -03:00
Max Claus Nunes 39d9c0ad64 Support multiple extensions with comma
Closes https://github.com/maxcnunes/gaper/issues/17
2022-08-07 10:10:24 -03:00
Max Claus Nunes 9229e8d69b Improve examples doc 2021-12-18 08:01:38 -03:00
Max Claus Nunes 4eb2525b49 Fix typo 2021-12-18 07:30:07 -03:00
Max Claus Nunes 7f381c7e58 Add example for custom configurations 2021-12-18 07:28:48 -03:00
Max Claus Nunes 2a09c4e713 Add example to install using the binary 2019-12-04 18:19:40 -03:00
Max Claus Nunes e99cd89574 Upgrade urfave/cli to version 1.22.2 2019-11-21 19:05:09 -03:00
Max Claus Nunes 3f3fcea575 Remove dep script 2019-11-21 19:04:37 -03:00
Max Claus Nunes 0324256f9c Migrate to go module 2019-11-12 18:37:44 -03:00
Max Claus Nunes 7c57257db3 Fix typo 2019-01-19 17:47:02 -02:00
Max Claus Nunes 60a0a90d11 Add notes about the watch method used in Gaper 2019-01-19 17:43:21 -02:00
Max Claus Nunes 2cdb29eb89 Add note about directory path settings
Close #11
2019-01-19 17:39:53 -02:00
Max Claus Nunes 69ab70821a Apply logic to ignore invalid extensions for non glob matches 2019-01-19 17:26:51 -02:00
Max Claus Nunes 56a75324ca Prepare release 1.0.3 2018-11-18 13:40:51 -02:00
Max Claus Nunes 7ecf55b3f6 Fix issue of gaper not restarting after a previous failure
Close #8
2018-11-18 13:37:19 -02:00
23 changed files with 253 additions and 240 deletions

37
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: goreleaser
on:
push:
# run only against tags
tags:
- '*'
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Fetch all tags
run: git fetch --force --tags
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

39
.github/workflows/workflow.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: dev-workflow
on:
- push
jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
# - macos-latest
# - windows-latest
go:
- '1.19'
# - '1.18'
# - '1.17'
# - '1.16'
# - '1.15'
env:
OS: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.48
- name: Test
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

View File

@ -1,29 +0,0 @@
language: go
go:
# - 1.7.x
# - 1.8.x
# - 1.9.x
- 1.10.x
# - master
before_script:
- go version
- make setup
- make lint
script:
- make test
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false
deploy:
- provider: script
skip_cleanup: true
script: curl -sL http://git.io/goreleaser | bash
on:
tags: true

View File

@ -28,7 +28,13 @@ make setup
### Running gaper in development
```
make build && ./gaper --verbose --bin-name srv --build-path ./testdata/server
make build && \
./gaper \
--verbose \
--bin-name srv \
--build-path ./testdata/server \
--build-args="-ldflags=\"-X 'main.Version=v1.0.0'\"" \
--extensions "go,txt"
```
### Running lint
@ -49,3 +55,6 @@ A single test:
go test -run TestSimplePost ./...
```
### Release
The release runs automatically with a Github action on pushed git tags.

81
Gopkg.lock generated
View File

@ -1,81 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
name = "github.com/fatih/color"
packages = ["."]
revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4"
version = "v1.7.0"
[[projects]]
name = "github.com/mattn/go-colorable"
packages = ["."]
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
version = "v0.0.9"
[[projects]]
name = "github.com/mattn/go-isatty"
packages = ["."]
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3"
[[projects]]
name = "github.com/mattn/go-shellwords"
packages = ["."]
revision = "02e3cf038dcea8290e44424da473dd12be796a8a"
version = "v1.0.3"
[[projects]]
branch = "master"
name = "github.com/mattn/go-zglob"
packages = [
".",
"fastwalk"
]
revision = "49693fbb3fe3c3a75fc4e4d6fb1d7cedcbdeb385"
[[projects]]
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
name = "github.com/stretchr/objx"
packages = ["."]
revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c"
version = "v0.1.1"
[[projects]]
name = "github.com/stretchr/testify"
packages = [
"assert",
"mock"
]
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
name = "github.com/urfave/cli"
packages = ["."]
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
version = "v1.20.0"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "8446ff85ebcb6bc802d3f444727c3910444a405f3c073c1095eb5cc8c497138b"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,23 +0,0 @@
[[constraint]]
name = "github.com/fatih/color"
version = "1.7.0"
[[constraint]]
name = "github.com/mattn/go-shellwords"
version = "1.0.3"
[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"
[prune]
go-tests = true
unused-packages = true
[[constraint]]
branch = "master"
name = "github.com/mattn/go-zglob"
[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

View File

@ -3,32 +3,14 @@ TEST_PACKAGES := $(shell go list ./... | grep -v cmd)
COVER_PACKAGES := $(shell go list ./... | grep -v cmd | paste -sd "," -)
LINTER := $(shell command -v gometalinter 2> /dev/null)
.PHONY: setup
setup:
ifeq ($(OS), Darwin)
brew install dep
else
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
endif
dep ensure -vendor-only
ifndef LINTER
@echo "Installing linter"
@go get -u github.com/alecthomas/gometalinter
@gometalinter --install
endif
build:
@go build -o ./gaper cmd/gaper/main.go
## lint: Validate golang code
# Install it following this doc https://golangci-lint.run/usage/install/#local-installation,
# please use the same version from .github/workflows/workflow.yml.
lint:
@gometalinter \
--deadline=120s \
--line-length=120 \
--enable-all \
--disable=gochecknoinits --disable=gochecknoglobals \
--vendor ./...
@golangci-lint run
test:
@go test -p=1 -coverpkg $(COVER_PACKAGES) \

View File

@ -18,15 +18,23 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/maxcnunes/gaper)](https://goreportcard.com/report/github.com/maxcnunes/gaper)
[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser)
## Changelog
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
## Installation
Using go tooling:
```
go get -u github.com/maxcnunes/gaper/cmd/gaper
```
## Changelog
Or, downloading the binary instead (example for version 1.1.0, make sure you are using the latest version though):
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
```
curl -SL https://github.com/maxcnunes/gaper/releases/download/v1.1.0/gaper_1.1.0_linux_amd64.tar.gz | tar -xvzf - -C "${GOPATH}/bin"
```
## Usage
@ -53,7 +61,7 @@ GLOBAL OPTIONS:
--watch value, -w value list of folders or files to watch for changes
--ignore value, -i value list of folders or files to ignore for changes
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
--extensions value, -e value a comma-delimited list of file extensions to watch for changes (default: "go")
--extensions value, -e value extensions to watch for changes (default: "go")
--no-restart-on value, -n value don't automatically restart the supervised program if it ends:
if "error", an exit code of 0 will still restart.
if "exit", no restart regardless of exit code.
@ -62,7 +70,15 @@ GLOBAL OPTIONS:
--version, -v print the version
```
Since in most projects there is no need to watch changes of:
### Watch and Ignore paths
For those options Gaper supports static paths (e.g. `build/`, `seed.go`) or glob paths (e.g. `migrations/**/up.go`, `*_test.go`).
On using a path to a directory please add a `/` at the end (e.g. `build/`) to make sure Gaper won't include other matches that starts with that same value (e.g. `build/`, `build_settings.go`).
### Default ignore settings
Since in most projects there is no need to watch changes for:
* hidden files and folders
* test files (`*_test.go`)
@ -70,6 +86,10 @@ Since in most projects there is no need to watch changes of:
Gaper by default ignores those cases already. Although, if you need Gaper to watch those files anyway it is possible to disable this setting with `--disable-default-ignore` argument.
### Watch method
Currently Gaper uses polling to watch file changes. We have plans to [support fs events](https://github.com/maxcnunes/gaper/issues/12) though in a near future.
### Examples
Using all defaults provided by Gaper:
@ -78,12 +98,18 @@ Using all defaults provided by Gaper:
gaper
```
Ignore watch over all test files:
> no need for this in case if you are not using `--disable-default-ignore`
Example providing a few custom configurations:
```
--ignore './**/*_test.go'
gaper \
--bin-name build/api-dev \
--build-path cmd/server \
--build-args "-ldflags=\"-X 'main.Version=dev'" \
-w 'public/**' -w '*.go' \
-e js -e css -e html \
--ignore './**/*_mock.go' \
--program-args "-arg1 ok -arg2=nope" \
--watch .
```
## Contributing

View File

@ -1,31 +0,0 @@
version: "{build}"
# Source Config
clone_folder: c:\gopath\src\github.com\maxcnunes\gaper
# Build host
environment:
GOPATH: c:\gopath
GOBIN: c:\gopath\bin
init:
- git config --global core.autocrlf input
# Build
install:
- set Path=c:\go\bin;c:\gopath\bin;%Path%
- go version
- go env
- go get -u github.com/golang/dep/cmd/dep
- choco install make
- make setup
build: false
deploy: false
test_script:
- go build github.com/maxcnunes/gaper/cmd/gaper
- make test

View File

@ -17,7 +17,6 @@ type Builder interface {
type builder struct {
dir string
binary string
errors string
wd string
buildArgs []string
}

View File

@ -38,15 +38,13 @@ func TestBuilderFailureBuild(t *testing.T) {
t.Fatalf("couldn't get current working directory: %v", err)
}
absPathBuild := filepath.Join(wd, dir)
b := NewBuilder(dir, bin, wd, bArgs)
err = b.Build()
assert.NotNil(t, err, "build error")
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
"# _"+absPathBuild+"\n"+
"# github.com/maxcnunes/gaper/testdata/build-failure\n"+
"./main.go:4:6: func main must have no arguments and no return values\n"+
"./main.go:5:1: missing return at end of function\n")
"./main.go:5:1: missing return\n")
}
func TestBuilderDefaultBinName(t *testing.T) {

View File

@ -4,15 +4,15 @@ import (
"os"
"github.com/maxcnunes/gaper"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
// build info
var (
// keep the version hardcoded because on installing it through "go get/install"
// it doesn't apply the build tags to override it. So, it is make easier for
// people using in that case to find out which version they are using
version = "1.0.2-dev"
// Version is hardcoded because when installing it through "go get/install"
// the build tags are not available to override it.
// Update it after every release.
version = "1.0.3-dev"
)
func main() {
@ -41,69 +41,61 @@ func main() {
app.Usage = "Used to build and restart a Go project when it crashes or some watched file changes"
app.Version = version
app.Action = func(c *cli.Context) {
app.Action = func(c *cli.Context) error {
args := parseArgs(c)
chOSSiginal := make(chan os.Signal, 2)
logger.Verbose(loggerVerbose)
if err := gaper.Run(args, chOSSiginal); err != nil {
logger.Error(err)
os.Exit(1)
}
}
exts := make(cli.StringSlice, len(gaper.DefaultExtensions))
for i := range gaper.DefaultExtensions {
exts[i] = gaper.DefaultExtensions[i]
return gaper.Run(args, chOSSiginal)
}
// supported arguments
app.Flags = []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "bin-name",
Usage: "name for the binary built by gaper for the executed program (default current directory name)",
},
cli.StringFlag{
&cli.StringFlag{
Name: "build-path",
Value: gaper.DefaultBuildPath,
Usage: "path to the program source code",
},
cli.StringFlag{
&cli.StringFlag{
Name: "build-args",
Usage: "arguments used on building the program",
},
cli.StringFlag{
&cli.StringFlag{
Name: "program-args",
Usage: "arguments used on executing the program",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "verbose",
Usage: "turns on the verbose messages from gaper",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "disable-default-ignore",
Usage: "turns off default ignore for hidden files and folders, \"*_test.go\" files, and vendor folder",
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "watch, w",
Usage: "list of folders or files to watch for changes",
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "ignore, i",
Usage: "list of folders or files to ignore for changes\n" +
"\t\t(always ignores all hidden files and directories)",
},
cli.IntFlag{
&cli.IntFlag{
Name: "poll-interval, p",
Value: gaper.DefaultPoolInterval,
Usage: "how often in milliseconds to poll watched files for changes",
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "extensions, e",
Value: &exts,
Value: cli.NewStringSlice(gaper.DefaultExtensions...),
Usage: "a comma-delimited list of file extensions to watch for changes",
},
cli.StringFlag{
&cli.StringFlag{
Name: "no-restart-on, n",
Usage: "don't automatically restart the supervised program if it ends:\n" +
"\t\tif \"error\", an exit code of 0 will still restart.\n" +

View File

@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
@ -59,6 +60,8 @@ func Run(cfg *Config, chOSSiginal chan os.Signal) error {
return err
}
logger.Debugf("Config: %+v", cfg)
wCfg := WatcherConfig{
DefaultIgnore: !cfg.DisableDefaultIgnore,
PollInterval: cfg.PollInterval,
@ -103,7 +106,8 @@ func run(cfg *Config, chOSSiginal chan os.Signal, builder Builder, runner Runner
continue
}
changeRestart = true
changeRestart = runner.IsRunning()
if err := restart(builder, runner); err != nil {
return err
}
@ -205,6 +209,13 @@ func setupConfig(cfg *Config) error {
cfg.WatchItems = append(cfg.WatchItems, cfg.BuildPath)
}
var extensions []string
for i := range cfg.Extensions {
values := strings.Split(cfg.Extensions[i], ",")
extensions = append(extensions, values...)
}
cfg.Extensions = extensions
return nil
}

16
go.mod Normal file
View File

@ -0,0 +1,16 @@
module github.com/maxcnunes/gaper
go 1.13
require (
github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/mattn/go-shellwords v1.0.3
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.4.0
github.com/urfave/cli/v2 v2.11.1
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

38
go.sum Normal file
View File

@ -0,0 +1,38 @@
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-shellwords v1.0.3 h1:K/VxK7SZ+cvuPgFSLKi5QPI9Vr/ipOf4C1gN+ntueUk=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3 h1:GWnsQiFbiQ7lREZbKkiJC6xxbymvny8GKtpdkPxjB6o=
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 h1:FCfAlbS73+IQQJktaKGHldMdL2bGDVpm+OrCEbVz1f4=
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -23,6 +23,7 @@ type Runner interface {
Kill() error
Errors() chan error
Exited() bool
IsRunning() bool
ExitStatus(err error) int
}
@ -108,6 +109,11 @@ func (r *runner) Exited() bool {
return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited()
}
// IsRunning returns if the process is running
func (r *runner) IsRunning() bool {
return r.command != nil && r.command.Process != nil && r.command.Process.Pid > 0
}
// Errors get errors occurred during the build
func (r *runner) Errors() chan error {
return r.errors

0
testdata/.hidden-file vendored Normal file
View File

0
testdata/.hidden-folder/.gitkeep vendored Normal file
View File

6
testdata/mocks.go vendored
View File

@ -57,6 +57,12 @@ func (m *MockRunner) Exited() bool {
return args.Bool(0)
}
// IsRunning ...
func (m *MockRunner) IsRunning() bool {
args := m.Called()
return args.Bool(0)
}
// ExitStatus ...
func (m *MockRunner) ExitStatus(err error) int {
args := m.Called()

1
testdata/server/data.txt vendored Normal file
View File

@ -0,0 +1 @@
test

View File

@ -7,6 +7,8 @@ import (
"net/http"
)
var Version string
func main() {
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) // nolint gas
@ -16,6 +18,6 @@ func main() {
log.Fatal("Forced failure")
})
log.Println("Starting server")
log.Println("Starting server: Version", Version)
log.Fatal(http.ListenAndServe(":8080", nil))
}

View File

@ -118,6 +118,11 @@ func (w *watcher) scanChange(watchPath string) (string, error) {
err := filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
// Ignore attempt to acess go temporary unmask
if strings.Contains(err.Error(), "-go-tmp-umask") {
return filepath.SkipDir
}
return fmt.Errorf("couldn't walk to path \"%s\": %v", path, err)
}
@ -189,13 +194,14 @@ func resolvePaths(paths []string, extensions map[string]bool) (map[string]bool,
}
for _, match := range matches {
// don't care for extension filter right now for non glob paths
// since they could be a directory
if isGlob {
if _, ok := extensions[filepath.Ext(match)]; !ok {
// ignore existing files that don't match the allowed extensions
if f, err := os.Stat(match); !os.IsNotExist(err) && !f.IsDir() {
if ext := filepath.Ext(match); ext != "" {
if _, ok := extensions[ext]; !ok {
continue
}
}
}
if _, ok := result[match]; !ok {
result[match] = true

View File

@ -1,7 +1,6 @@
package gaper
import (
"log"
"os"
"path/filepath"
"runtime"
@ -105,14 +104,19 @@ func TestWatcherWatchChange(t *testing.T) {
time.Sleep(time.Millisecond * 500)
// update hidden files and dirs to check builtin hidden ignore is working
os.Chtimes(hiddenfile1, time.Now(), time.Now())
os.Chtimes(hiddenfile2, time.Now(), time.Now())
err = os.Chtimes(hiddenfile1, time.Now(), time.Now())
assert.Nil(t, err, "chtimes error")
err = os.Chtimes(hiddenfile2, time.Now(), time.Now())
assert.Nil(t, err, "chtimes error")
// update testfile first to check ignore is working
os.Chtimes(testfile, time.Now(), time.Now())
err = os.Chtimes(testfile, time.Now(), time.Now())
assert.Nil(t, err, "chtimes error")
time.Sleep(time.Millisecond * 500)
os.Chtimes(mainfile, time.Now(), time.Now())
err = os.Chtimes(mainfile, time.Now(), time.Now())
assert.Nil(t, err, "chtimes error")
select {
case event := <-w.Events():
@ -173,6 +177,11 @@ func TestWatcherIgnoreFile(t *testing.T) {
},
}
// create vendor folder for testing
if err := os.MkdirAll("vendor", os.ModePerm); err != nil {
t.Fatal(err)
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
srvdir := "."
@ -198,12 +207,12 @@ func TestWatcherIgnoreFile(t *testing.T) {
filePath := tc.file
file, err := os.Open(filePath)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
fileInfo, err := file.Stat()
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
assert.Equal(t, tc.expectIgnore, wt.ignoreFile(filePath, fileInfo))