pathfilter

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pathfilter matches changed file paths against doublestar-style globs with include and ignore lists, for deciding whether a change in a monorepo should trigger a build or deploy.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(glob, file string) bool

Match reports whether file matches glob. Supported syntax: `*` (any run of characters within one segment), `?` (one character within a segment), `**` as a whole segment (zero or more segments), `[abc]`, `[a-z]` and `[!a]` classes, and `{a,b}` alternation. A glob ending in "/" matches everything beneath that directory. Wildcards match dotfiles. Both sides are normalized, so backslash separators work.

Example
package main

import (
	"fmt"

	"github.com/GLINCKER/levelrail/kit/pathfilter"
)

func main() {
	fmt.Println(pathfilter.Match("src/**/*.{go,ts}", "src/a/b/c.go"))
	fmt.Println(pathfilter.Match("docs/", "docs/guide/intro.md"))
}
Output:
true
true

func Normalize

func Normalize(p string) string

Normalize converts Windows separators to slashes and strips a leading "./" or "/".

Types

type Filter

type Filter struct {
	Paths  []string
	Ignore []string
}

Filter is a set of include globs and ignore globs. An empty Paths list includes every path; a path matching any Ignore glob is dropped.

func (Filter) Apply

func (f Filter) Apply(files []string) Result

Apply decides whether a change touching files should run. An empty file list means the file set is unknown, so the answer is always to run.

Example
package main

import (
	"fmt"

	"github.com/GLINCKER/levelrail/kit/pathfilter"
)

func main() {
	f := pathfilter.Filter{
		Paths:  []string{"services/api/**"},
		Ignore: []string{"**/*.md"},
	}
	fmt.Println(f.Apply([]string{"services/api/main.go"}).Run)
	fmt.Println(f.Apply([]string{"services/web/index.ts"}).Reason)
	fmt.Println(f.Apply([]string{"services/api/README.md"}).Reason)
}
Output:
true
skipped: no changed path matched paths
skipped: every changed path matched paths_ignore

func (Filter) IsZero

func (f Filter) IsZero() bool

IsZero reports whether the filter has no globs at all.

func (Filter) Validate

func (f Filter) Validate() error

Validate reports the first malformed glob.

type Result

type Result struct {
	Run    bool
	Reason string
}

Result is the outcome of applying a Filter to a changed-file list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL