From 535b41e0598d339b7b6afe3493f708bf7e16d781 Mon Sep 17 00:00:00 2001 From: actualben Date: Wed, 18 Feb 2026 11:40:53 +0100 Subject: [PATCH 1/2] update go deps --- go.mod | 19 +++++++++---------- go.sum | 44 +++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 237a2ea..499f406 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,18 @@ module github.com/backplane/contextdir -go 1.20 +go 1.25.0 require ( - github.com/containerd/continuity v0.3.1-0.20230206214859-2a963a2f56e8 - github.com/moby/buildkit v0.11.5 - github.com/moby/patternmatcher v0.5.0 - github.com/sirupsen/logrus v1.9.0 - github.com/urfave/cli/v2 v2.25.1 - golang.org/x/sys v0.7.0 + github.com/containerd/continuity v0.4.5 + github.com/moby/buildkit v0.27.1 + github.com/moby/patternmatcher v0.6.0 + github.com/sirupsen/logrus v1.9.4 + github.com/urfave/cli/v2 v2.27.7 + golang.org/x/sys v0.41.0 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/pkg/errors v0.9.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect ) diff --git a/go.sum b/go.sum index 09afb74..f19e989 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,26 @@ -github.com/containerd/continuity v0.3.1-0.20230206214859-2a963a2f56e8 h1:EdSQb65ohzz4jsyPOhxfu3/+c9nnU0euk0otferwl9A= -github.com/containerd/continuity v0.3.1-0.20230206214859-2a963a2f56e8/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= -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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4= +github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE= +github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= +github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/moby/buildkit v0.11.5 h1:S6YrFJ0bfBT2w9e8kOxqsDV8Bw+HtfqdB6eHL17BXRI= -github.com/moby/buildkit v0.11.5/go.mod h1:P5Qi041LvCfhkfYBHry+Rwoo3Wi6H971J2ggE+PcIoo= -github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= -github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/moby/buildkit v0.27.1 h1:qlIWpnZzqCkrYiGkctM1gBD/YZPOJTjtUdRBlI0oBOU= +github.com/moby/buildkit v0.27.1/go.mod h1:99qLrCrIAFgEOiFnCi9Y0Wwp6/qA7QvZ3uq/6wF0IsI= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= 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/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw= -github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= -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-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU= +github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4= +github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg= +github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= +golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 50ddbec525626ea0c7a9906cdf19a8c6f552f907 Mon Sep 17 00:00:00 2001 From: actualben Date: Wed, 18 Feb 2026 12:33:09 +0100 Subject: [PATCH 2/2] update go dependencies and improve CI - update go module dependencies - replace moby/buildkit with moby/patternmatcher/ignorefile - add pre-commit config and replace lint workflow with check workflow - update GitHub Actions to v6 (checkout, setup-go, goreleaser) - add proper error handling in stat and file packages - fix linting issues --- .github/workflows/check.yml | 34 ++++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 34 ---------------------------------- .github/workflows/release.yml | 10 +++++----- .pre-commit-config.yaml | 33 +++++++++++++++++++++++++++++++++ README.md | 1 - files/file.go | 5 ++++- go.mod | 2 +- go.sum | 2 -- scan/scan.go | 2 +- stat/stat.go | 14 ++++++++++---- utils/utils.go | 17 +++++++++++++---- 11 files changed, 101 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..16c289f --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,34 @@ +# workflow which lints and checks the rust code on every push and pull request +name: Check +on: + push: + +jobs: + unified: + runs-on: ubuntu-latest + steps: + # https://github.com/actions/checkout + - name: checkout + uses: actions/checkout@v6 + + # https://github.com/actions/setup-go + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version-file: "go.mod" + + # https://github.com/actions/setup-python + - name: setup python + uses: actions/setup-python@v6 + with: + python-version: ">=3.14" + + # https://github.com/pre-commit/action + - name: run pre-commit + uses: pre-commit/action@v3.0.1 + env: + SKIP: no-commit-to-branch,golangci-lint-full + + # https://github.com/golangci/golangci-lint-action + - name: golangci-lint + uses: golangci/golangci-lint-action@v9 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 43617f4..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: lint -on: - push: - branches: ['main'] - pull_request: - branches: ['main'] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - # https://github.com/actions/checkout - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: yamllint - run: >- - docker run - --rm - --volume "$(pwd):/work" - backplane/yamllint - -f github - . - - - name: make lint - run: >- - docker run - --rm - --volume "$(pwd):/work" - --workdir /work - backplane/goenv - make lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6a5363..0c263ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,26 +2,26 @@ name: release on: push: tags: - - 'v*.*.*' + - "v*.*.*" jobs: goreleaser: runs-on: ubuntu-latest steps: # https://github.com/actions/checkout - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: fetch-depth: 0 # https://github.com/actions/setup-go - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v6 with: - go-version: '>=1.20' + go-version-file: "go.mod" # https://github.com/goreleaser/goreleaser-action - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v6 with: version: latest args: release --clean diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e775513 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: mixed-line-ending + args: + - --fix=lf + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: detect-private-key + - id: no-commit-to-branch + args: + - --branch + - main + - repo: https://github.com/rhysd/actionlint + rev: v1.7.11 + hooks: + - id: actionlint-docker + name: check github workflows with actionlint + args: + - -ignore + - "invalid format because owner and repo and ref should not be empty" + - -ignore + - "remove the if: section" + - repo: https://github.com/golangci/golangci-lint + rev: v2.10.1 + hooks: + - id: golangci-lint-full diff --git a/README.md b/README.md index 4c380ea..efc9577 100644 --- a/README.md +++ b/README.md @@ -253,4 +253,3 @@ $ contextdir checksum --detailed The key .Dir.hash is the SHA-256 sum of all the StatsHash values of every non-ignored file, this is the value that is normally reported without the `--detailed` flag. - diff --git a/files/file.go b/files/file.go index 3840ab4..6846a62 100644 --- a/files/file.go +++ b/files/file.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "fmt" "io/fs" "github.com/backplane/contextdir/stat" @@ -19,7 +20,9 @@ type File struct { func NewFile(fullpath, relpath string, fi fs.FileInfo) (*File, error) { // Gather a bunch of statistics about the file at the given fullpath stats := stat.NewStat(relpath) - stats.PopulateFromFileInfo(fullpath, fi) + if err := stats.PopulateFromFileInfo(fullpath, fi); err != nil { + return nil, fmt.Errorf("failed to populate stat struct for file: '%s' - error: %w", fullpath, err) + } // We're going to marshall the stats struct into json then use the hash of // that json document as the basis of our context hashing. JSON is way less diff --git a/go.mod b/go.mod index 499f406..c33c45f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.25.0 require ( github.com/containerd/continuity v0.4.5 - github.com/moby/buildkit v0.27.1 github.com/moby/patternmatcher v0.6.0 github.com/sirupsen/logrus v1.9.4 github.com/urfave/cli/v2 v2.27.7 @@ -14,5 +13,6 @@ require ( require ( github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/stretchr/testify v1.11.1 // indirect github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect ) diff --git a/go.sum b/go.sum index f19e989..4ca4c38 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3 github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/moby/buildkit v0.27.1 h1:qlIWpnZzqCkrYiGkctM1gBD/YZPOJTjtUdRBlI0oBOU= -github.com/moby/buildkit v0.27.1/go.mod h1:99qLrCrIAFgEOiFnCi9Y0Wwp6/qA7QvZ3uq/6wF0IsI= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/scan/scan.go b/scan/scan.go index c7f7699..4095b9e 100644 --- a/scan/scan.go +++ b/scan/scan.go @@ -27,7 +27,7 @@ type ScanResults struct { } func ScanContextDir(contextDir string) (*ScanResults, error) { - var results *ScanResults = &ScanResults{ + var results = &ScanResults{ DockerIgnoreEntries: make([]string, 0), IgnoredFiles: make([]*files.File, 0), } diff --git a/stat/stat.go b/stat/stat.go index 9bf60ee..329b5d2 100644 --- a/stat/stat.go +++ b/stat/stat.go @@ -1,6 +1,7 @@ package stat import ( + "fmt" "io/fs" "os" ) @@ -37,7 +38,7 @@ func NewStat(path string) *Stat { // given fi (fs.FileInfo) and by gathering additional information from lower-level // OS APIs as available; the given path MUST be a valid path which can be used // in function calls (not an externally-relative path) -func (s *Stat) PopulateFromFileInfo(path string, fi fs.FileInfo) { +func (s *Stat) PopulateFromFileInfo(path string, fi fs.FileInfo) error { // NOTE: this does NOT set s.Path from path and this function needs a real // path to read symlinks s.Mode = uint32(fi.Mode()) @@ -47,11 +48,16 @@ func (s *Stat) PopulateFromFileInfo(path string, fi fs.FileInfo) { if fi.Mode()&os.ModeSymlink != 0 { s.Mode = s.Mode | 0777 - if link, err := os.Readlink(path); err == nil { - s.Linkname = link + link, err := os.Readlink(path) + if err != nil { + return fmt.Errorf("failed to read link at '%s' - error: %w", path, err) } + s.Linkname = link } // this is just a stub on windows - s.populateFromUnixInfo(path, fi) + if err := s.populateFromUnixInfo(path, fi); err != nil { + return fmt.Errorf("failed to populate unix info for file at '%s' - error: %w", path, err) + } + return nil } diff --git a/utils/utils.go b/utils/utils.go index c1d79eb..af7a006 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,9 +2,10 @@ package utils import ( "encoding/json" + "fmt" "os" - "github.com/moby/buildkit/frontend/dockerfile/dockerignore" + "github.com/moby/patternmatcher/ignorefile" ) // WriteJson writes the given data structure to STDOUT using the indended Marshaler @@ -13,8 +14,16 @@ func WriteJSON(data any) error { if err != nil { return err } - os.Stdout.Write(output) - os.Stdout.Write([]byte("\n")) + + // ensure a trailing newline on output + if len(output) == 0 || output[len(output)-1] != '\n' { + output = append(output, '\n') + } + + if _, err := os.Stdout.Write(output); err != nil { + return fmt.Errorf("failed to write JSON to stdout - error: %w", err) + } + return nil } @@ -25,7 +34,7 @@ func LoadDockerIgnore(path string) (excludes []string, err error) { if err != nil { return } - excludes, err = dockerignore.ReadAll(fh) + excludes, err = ignorefile.ReadAll(fh) if err != nil { return }