Brian McGee
97e94ba848
fix: remove -dirty suffix from revision
...
Avoids unnecessary rebuilds in local dev.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-13 10:08:50 +01:00
Brian McGee
39b73b8e7e
Merge pull request #9 from numtide/fix/install-docs-dependencies
...
fix: install node dependencies in devshell commands
2024-05-10 11:15:31 +01:00
Brian McGee
249f807e92
fix: install node dependencies in devshell commands
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-10 11:15:04 +01:00
Brian McGee
9b00e00666
feat: set nix package version to shortRev
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-10 11:06:31 +01:00
Brian McGee
e5da10e873
doc: refine docs and usage
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-10 10:46:39 +01:00
zimbatm
e5a6cc60e2
ci: handle releases with goreleaser
2024-05-09 22:16:57 +02:00
Brian McGee
4ffe2ca16c
feat: add CGO dependencies to devshell
...
Required for running tests with bench and/or race enabled.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-09 11:50:37 +01:00
Brian McGee
ebfd17b76a
feat: add nix github workflow
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-08 08:54:58 +01:00
Brian McGee
a79ae9583c
feat: add cpu profile flag
2024-05-06 16:05:10 +01:00
Brian McGee
4a6fbf943c
fix: vhs command wrapper
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-03 20:03:40 +01:00
Brian McGee
e232ffe249
ci: testing alternative gh pages upload action
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-03 18:00:34 +01:00
Brian McGee
ab7bf54a31
fix: source filter in package build
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-03 16:17:39 +01:00
Brian McGee
0ec0c3dbe1
fix: update filter to prevent rebuilds
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-03 13:47:41 +01:00
Brian McGee
b01ea779aa
doc: add init gif
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-03 13:27:02 +01:00
Brian McGee
166a919fee
chore: remove flake-root input
...
No longer needed
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 13:41:10 +01:00
Brian McGee
17f354b880
doc: improve hero gif
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:38 +01:00
Brian McGee
6c66daf26b
fix: devshell commands for docs
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:38 +01:00
Brian McGee
311e46a409
doc: fix docs package build
...
Vitepress cli does some funky stuff with the tty.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:38 +01:00
Brian McGee
95c6cdbd57
doc: add some devshell helpers
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:37 +01:00
Brian McGee
7cc49e2275
wip: add focs package
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:37 +01:00
Brian McGee
894f90f084
doc: move assets into public folder
...
Fixes issues with built version of the site
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:37 +01:00
Brian McGee
b86d0f897f
doc: configure hero and logo
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:36 +01:00
Brian McGee
397d051088
fix: nix filter for package
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 11:41:36 +01:00
Brian McGee
757d5e746a
feat: configure a pipeline for formatting nix code
...
Relies on a fork of treefmt-nix until it can be merged.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-01 09:12:01 +01:00
Brian McGee
3000c65ead
fix: nix-filter config for package
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-01 09:11:27 +01:00
Brian McGee
40b76b74a0
feat: ensure deterministic application of formatters
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-04-26 10:33:29 +01:00
Brian McGee
fcce518d5e
feat: various perf improvements
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-04-25 12:16:04 +01:00
Brian McGee
49596b8e08
fix: setting build Name and Version
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-28 09:18:45 +00:00
Brian McGee
2b49923bf7
feat: add an example of 'before'
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 14:17:16 +00:00
Brian McGee
da82b80f29
feat: support --no-cache
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
diff --git a/cli/cli.go b/cli/cli.go
index 8b23262..b370ee7 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -11,6 +11,7 @@ var Cli = Format{}
type Format struct {
AllowMissingFormatter bool `default:"false" help:"Do not exit with error if a configured formatter is missing"`
WorkingDirectory kong.ChangeDirFlag `default:"." short:"C" help:"Run as if treefmt was started in the specified working directory instead of the current working directory"`
+ NoCache bool `help:"Ignore the evaluation cache entirely. Useful for CI"`
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI."`
diff --git a/cli/format.go b/cli/format.go
index 6c46096..14ac16c 100644
--- a/cli/format.go
+++ b/cli/format.go
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
+ "io/fs"
"os"
"os/signal"
"strings"
@@ -168,6 +169,20 @@ func (f *Format) Run() error {
var changes int
+ processBatch := func() error {
+ if Cli.NoCache {
+ changes += len(batch)
+ } else {
+ count, err := cache.Update(batch)
+ if err != nil {
+ return err
+ }
+ changes += count
+ }
+ batch = batch[:0]
+ return nil
+ }
+
LOOP:
for {
select {
@@ -179,22 +194,17 @@ func (f *Format) Run() error {
}
batch = append(batch, path)
if len(batch) == batchSize {
- count, err := cache.Update(batch)
- if err != nil {
+ if err = processBatch(); err != nil {
return err
}
- changes += count
- batch = batch[:0]
}
}
}
// final flush
- count, err := cache.Update(batch)
- if err != nil {
+ if err = processBatch(); err != nil {
return err
}
- changes += count
if Cli.FailOnChange && changes != 0 {
return ErrFailOnChange
@@ -251,6 +261,22 @@ func (f *Format) Run() error {
}
defer close(pathsCh)
+
+ if Cli.NoCache {
+ return walker.Walk(ctx, func(path string, info fs.FileInfo, err error) error {
+ select {
+ case <-ctx.Done():
+ return ctx.Err()
+ default:
+ // ignore symlinks and directories
+ if !(info.IsDir() || info.Mode()&os.ModeSymlink == os.ModeSymlink) {
+ pathsCh <- path
+ }
+ return nil
+ }
+ })
+ }
+
return cache.ChangeSet(ctx, walker, pathsCh)
})
diff --git a/cli/format_test.go b/cli/format_test.go
index fb389fe..2349767 100644
--- a/cli/format_test.go
+++ b/cli/format_test.go
@@ -216,6 +216,15 @@ func TestCache(t *testing.T) {
as.NoError(err)
as.Contains(string(out), "0 files changed")
+ // clear cache
+ out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c")
+ as.NoError(err)
+ as.Contains(string(out), fmt.Sprintf("%d files changed", 29))
+
+ out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
+ as.NoError(err)
+ as.Contains(string(out), "0 files changed")
+
// no cache
out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "--no-cache")
as.NoError(err)
diff --git a/nix/packages.nix b/nix/packages.nix
index 127eb08..e0f8604 100644
--- a/nix/packages.nix
+++ b/nix/packages.nix
@@ -13,7 +13,7 @@
packages = rec {
treefmt = inputs'.gomod2nix.legacyPackages.buildGoApplication rec {
pname = "treefmt";
- version = "0.0.1+dev";
+ version = "2.0.0+dev";
# ensure we are using the same version of go to build with
inherit (pkgs) go;
diff --git a/cli/cli.go b/cli/cli.go
index 8b23262..b370ee7 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -11,6 +11,7 @@ var Cli = Format{}
type Format struct {
AllowMissingFormatter bool `default:"false" help:"Do not exit with error if a configured formatter is missing"`
WorkingDirectory kong.ChangeDirFlag `default:"." short:"C" help:"Run as if treefmt was started in the specified working directory instead of the current working directory"`
+ NoCache bool `help:"Ignore the evaluation cache entirely. Useful for CI"`
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI."`
diff --git a/cli/format.go b/cli/format.go
index 6c46096..14ac16c 100644
--- a/cli/format.go
+++ b/cli/format.go
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
+ "io/fs"
"os"
"os/signal"
"strings"
@@ -168,6 +169,20 @@ func (f *Format) Run() error {
var changes int
+ processBatch := func() error {
+ if Cli.NoCache {
+ changes += len(batch)
+ } else {
+ count, err := cache.Update(batch)
+ if err != nil {
+ return err
+ }
+ changes += count
+ }
+ batch = batch[:0]
+ return nil
+ }
+
LOOP:
for {
select {
@@ -179,22 +194,17 @@ func (f *Format) Run() error {
}
batch = append(batch, path)
if len(batch) == batchSize {
- count, err := cache.Update(batch)
- if err != nil {
+ if err = processBatch(); err != nil {
return err
}
- changes += count
- batch = batch[:0]
}
}
}
// final flush
- count, err := cache.Update(batch)
- if err != nil {
+ if err = processBatch(); err != nil {
return err
}
- changes += count
if Cli.FailOnChange && changes != 0 {
return ErrFailOnChange
@@ -251,6 +261,22 @@ func (f *Format) Run() error {
}
defer close(pathsCh)
+
+ if Cli.NoCache {
+ return walker.Walk(ctx, func(path string, info fs.FileInfo, err error) error {
+ select {
+ case <-ctx.Done():
+ return ctx.Err()
+ default:
+ // ignore symlinks and directories
+ if !(info.IsDir() || info.Mode()&os.ModeSymlink == os.ModeSymlink) {
+ pathsCh <- path
+ }
+ return nil
+ }
+ })
+ }
+
return cache.ChangeSet(ctx, walker, pathsCh)
})
diff --git a/nix/packages.nix b/nix/packages.nix
index 127eb08..e0f8604 100644
--- a/nix/packages.nix
+++ b/nix/packages.nix
@@ -13,7 +13,7 @@
packages = rec {
treefmt = inputs'.gomod2nix.legacyPackages.buildGoApplication rec {
pname = "treefmt";
- version = "0.0.1+dev";
+ version = "2.0.0+dev";
# ensure we are using the same version of go to build with
inherit (pkgs) go;
2024-02-15 13:59:56 +00:00
Brian McGee
0fbae06f19
feat: support reading paths from stdin
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 10:37:56 +00:00
Brian McGee
cb9564c7ef
feat: add -s -w build flags to reduce binary size
...
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-14 15:10:20 +00:00
Brian McGee
15db7f459c
fix: duplicate processing in ordered formatters ( #24 )
...
Fixes a bug with formatters processing paths out of order.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
Reviewed-on: https://git.numtide.com/numtide/treefmt/pulls/24
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-12 15:15:51 +00:00
Brian McGee
80e99b6d75
feat: use go-git index instead of git ls-files
( #23 )
...
Figured out how to use `go-git` properly.
```console
# git
❯ nix run .# -- --config-file ./test/echo.toml --tree-root /home/brian/Development/com/github/nixos/nixpkgs -c
38539 files changed in 272.843495ms
# filesystem
❯ nix run .# -- --config-file ./test/echo.toml --tree-root /home/brian/Development/com/github/nixos/nixpkgs -c --walk filesystem
38567 files changed in 348.84277ms
```
Signed-off-by: Brian McGee <brian@bmcgee.ie>
Reviewed-on: https://git.numtide.com/numtide/treefmt/pulls/23
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-12 11:33:14 +00:00
Brian McGee
5711caebb9
feat: support .gitignore files ( #19 )
...
Introduces a `--walk` flag which can be used to tell `treefmt` how to traverse the directory specified by `--tree-root`.
By default, it will attempt to use `git ls-files`. If this fails, it falls back to using the filesystem.
You can explicitly traverse the filesystem instead of using git by providing `--walk filesystem`.
Close #1
Reviewed-on: https://git.numtide.com/numtide/treefmt/pulls/19
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-11 20:52:22 +00:00
Brian McGee
4a78a1e319
fix: nix build
...
- update `gomod2nix.toml`
- add formatters as `nativeBuildInputs` for nix build
- export a `XDG_CACHE_HOME` for checks
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-01-03 09:20:32 +00:00
Brian McGee
f322e1ffb8
fix: include correct gotools package
2023-12-24 11:19:48 +00:00
Brian McGee
298e5ac217
feat: change module root to git.numtide.com
2023-12-23 13:39:16 +00:00
Brian McGee
12452b01b6
feat: align example treefmt config with flake treefmt config
...
Prevent unnecessary reformatting
2023-12-23 13:06:50 +00:00
Brian McGee
6904097171
feat: initial import
2023-12-23 12:50:51 +00:00