Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 0 additions & 34 deletions .github/workflows/lint.yml

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

5 changes: 4 additions & 1 deletion files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io/fs"

"github.com/backplane/contextdir/stat"
Expand All @@ -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
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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/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/stretchr/testify v1.11.1 // indirect
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
)
42 changes: 17 additions & 25 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
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/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=
2 changes: 1 addition & 1 deletion scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
14 changes: 10 additions & 4 deletions stat/stat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stat

import (
"fmt"
"io/fs"
"os"
)
Expand Down Expand Up @@ -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())
Expand All @@ -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
}
17 changes: 13 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down