mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2026-10-23 04:48:57 +03:00
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [github.com/golangci/golangci-lint/v2/cmd/golangci-lint](https://github.com/golangci/golangci-lint) | `v2.8.0` β `v2.10.1` |  |  | --- ### Release Notes <details> <summary>golangci/golangci-lint (github.com/golangci/golangci-lint/v2/cmd/golangci-lint)</summary> ### [`v2.10.1`](https://github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v2101) [Compare Source](https://github.com/golangci/golangci-lint/compare/v2.10.0...v2.10.1) *Released on 2026-02-17* 1. Fixes - buildssa panic ### [`v2.10.0`](https://github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v2100) [Compare Source](https://github.com/golangci/golangci-lint/compare/v2.9.0...v2.10.0) *Released on 2026-02-17* 1. Linters new features or changes - `ginkgolinter`: from 0.22.0 to 0.23.0 - `gosec`: from 2.22.11 to 2.23.0 (new rules: `G117`, `G602`, `G701`, `G702`, `G703`, `G704`, `G705`, `G706`) - `staticcheck`: from 0.6.1 to 0.7.0 2. Linters bug fixes - `godoclint`: from 0.11.1 to 0.11.2 ### [`v2.9.0`](https://github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v290) [Compare Source](https://github.com/golangci/golangci-lint/compare/v2.8.0...v2.9.0) *Released on 2026-02-10* 1. Enhancements - π go1.26 support 2. Linters new features or changes - `arangolint`: from 0.3.1 to 0.4.0 (new rule: detect potential query injections) - `ginkgolinter`: from 0.21.2 to 0.22.0 (support for wrappers) - `golines`: from 0.14.0 to 0.15.0 - `misspell`: from 0.7.0 to 0.8.0 - `revive`: from v1.13.0 to v1.14.0 (new rules: `epoch-naming`, `use-slices-sort`) - `unqueryvet`: from 1.4.0 to 1.5.3 (new options: `check-n1`, `check-sql-injection`, `check-tx-leaks`, `allow`, `custom-rules`) - `wsl_v5`: from 5.3.0 to 5.6.0 (new rule: `after-block`) 3. Linters bug fixes - `modernize`: from 0.41.0 to 0.42.0 - `prealloc`: from 1.0.1 to 1.0.2 - `protogetter`: from 0.3.18 to 0.3.20 4. Misc. - Log information about files when configuration verification - Emit an error when no linters enabled - Do not collect VCS information when loading code </details> --- ### Configuration π **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC). π¦ **Automerge**: Enabled. β» **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. π **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My41LjAiLCJ1cGRhdGVkSW5WZXIiOiI0My41LjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbIktpbmQvRGVwZW5kZW5jeVVwZGF0ZSIsInJ1bi1lbmQtdG8tZW5kLXRlc3RzIl19--> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1396 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Renovate Bot <bot@kriese.eu> Co-committed-by: Renovate Bot <bot@kriese.eu>
197 lines
4.6 KiB
Go
197 lines
4.6 KiB
Go
package workflowpattern
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
type WorkflowPattern struct {
|
|
Pattern string
|
|
Negative bool
|
|
Regex *regexp.Regexp
|
|
}
|
|
|
|
func CompilePattern(rawpattern string) (*WorkflowPattern, error) {
|
|
negative := false
|
|
pattern := rawpattern
|
|
if strings.HasPrefix(rawpattern, "!") {
|
|
negative = true
|
|
pattern = rawpattern[1:]
|
|
}
|
|
rpattern, err := PatternToRegex(pattern)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
regex, err := regexp.Compile(rpattern)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &WorkflowPattern{
|
|
Pattern: pattern,
|
|
Negative: negative,
|
|
Regex: regex,
|
|
}, nil
|
|
}
|
|
|
|
//nolint:gocyclo
|
|
func PatternToRegex(pattern string) (string, error) {
|
|
var rpattern strings.Builder
|
|
rpattern.WriteString("^")
|
|
pos := 0
|
|
errors := map[int]string{}
|
|
for pos < len(pattern) {
|
|
switch pattern[pos] {
|
|
case '*':
|
|
if pos+1 < len(pattern) && pattern[pos+1] == '*' {
|
|
if pos+2 < len(pattern) && pattern[pos+2] == '/' {
|
|
rpattern.WriteString("(.+/)?")
|
|
pos += 3
|
|
} else {
|
|
rpattern.WriteString(".*")
|
|
pos += 2
|
|
}
|
|
} else {
|
|
rpattern.WriteString("[^/]*")
|
|
pos++
|
|
}
|
|
case '+', '?':
|
|
if pos > 0 {
|
|
rpattern.WriteByte(pattern[pos])
|
|
} else {
|
|
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
}
|
|
pos++
|
|
case '[':
|
|
rpattern.WriteByte(pattern[pos])
|
|
pos++
|
|
if pos < len(pattern) && pattern[pos] == ']' {
|
|
errors[pos] = "Unexpected empty brackets '[]'"
|
|
pos++
|
|
break
|
|
}
|
|
validChar := func(a, b, test byte) bool {
|
|
return test >= a && test <= b
|
|
}
|
|
startPos := pos
|
|
for pos < len(pattern) && pattern[pos] != ']' {
|
|
switch pattern[pos] {
|
|
case '-':
|
|
if pos <= startPos || pos+1 >= len(pattern) {
|
|
errors[pos] = "Invalid range"
|
|
pos++
|
|
break
|
|
}
|
|
validRange := func(a, b byte) bool {
|
|
return validChar(a, b, pattern[pos-1]) && validChar(a, b, pattern[pos+1]) && pattern[pos-1] <= pattern[pos+1]
|
|
}
|
|
if !validRange('A', 'z') && !validRange('0', '9') {
|
|
errors[pos] = "Ranges can only include a-z, A-Z, A-z, and 0-9"
|
|
pos++
|
|
break
|
|
}
|
|
rpattern.WriteString(pattern[pos : pos+2])
|
|
pos += 2
|
|
default:
|
|
if !validChar('A', 'z', pattern[pos]) && !validChar('0', '9', pattern[pos]) {
|
|
errors[pos] = "Ranges can only include a-z, A-Z and 0-9"
|
|
pos++
|
|
break
|
|
}
|
|
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
pos++
|
|
}
|
|
}
|
|
if pos >= len(pattern) || pattern[pos] != ']' {
|
|
errors[pos] = "Missing closing bracket ']' after '['"
|
|
pos++
|
|
}
|
|
rpattern.WriteString("]")
|
|
pos++
|
|
case '\\':
|
|
if pos+1 >= len(pattern) {
|
|
errors[pos] = "Missing symbol after \\"
|
|
pos++
|
|
break
|
|
}
|
|
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos+1]})))
|
|
pos += 2
|
|
default:
|
|
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
pos++
|
|
}
|
|
}
|
|
if len(errors) > 0 {
|
|
var errorMessage strings.Builder
|
|
for position, err := range errors {
|
|
if errorMessage.Len() > 0 {
|
|
errorMessage.WriteString(", ")
|
|
}
|
|
fmt.Fprintf(&errorMessage, "Position: %d Error: %s", position, err)
|
|
}
|
|
return "", fmt.Errorf("invalid Pattern '%s': %s", pattern, errorMessage.String())
|
|
}
|
|
rpattern.WriteString("$")
|
|
return rpattern.String(), nil
|
|
}
|
|
|
|
func CompilePatterns(patterns ...string) ([]*WorkflowPattern, error) {
|
|
ret := []*WorkflowPattern{}
|
|
for _, pattern := range patterns {
|
|
cp, err := CompilePattern(pattern)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ret = append(ret, cp)
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
// returns true if the workflow should be skipped paths/branches
|
|
func Skip(sequence []*WorkflowPattern, input []string, traceWriter TraceWriter) bool {
|
|
if len(sequence) == 0 {
|
|
return false
|
|
}
|
|
for _, file := range input {
|
|
matched := false
|
|
for _, item := range sequence {
|
|
if item.Regex.MatchString(file) {
|
|
pattern := item.Pattern
|
|
if item.Negative {
|
|
matched = false
|
|
traceWriter.Info("%s excluded by pattern %s", file, pattern)
|
|
} else {
|
|
matched = true
|
|
traceWriter.Info("%s included by pattern %s", file, pattern)
|
|
}
|
|
}
|
|
}
|
|
if matched {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// returns true if the workflow should be skipped paths-ignore/branches-ignore
|
|
func Filter(sequence []*WorkflowPattern, input []string, traceWriter TraceWriter) bool {
|
|
if len(sequence) == 0 {
|
|
return false
|
|
}
|
|
for _, file := range input {
|
|
matched := false
|
|
for _, item := range sequence {
|
|
if item.Regex.MatchString(file) == !item.Negative {
|
|
pattern := item.Pattern
|
|
traceWriter.Info("%s ignored by pattern %s", file, pattern)
|
|
matched = true
|
|
break
|
|
}
|
|
}
|
|
if !matched {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|