-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go: lower Go requirement to Go 1.18 #37
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a06a225
tests: don't call testing.Testing() in mocks
cyphar 6ef6896
go: lower Go requirement to Go 1.18
cyphar e11873c
deps: downgrade golang.org/x/sys requirement
cyphar 31bfec2
gha: test older Go versions in CI
cyphar 2d9831f
gha: compile-test for all supported Go versions
cyphar d17d372
gha: use stable/oldstable go versions
cyphar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |
|
||
## [Unreleased] ## | ||
|
||
### Compatibility ### | ||
- The minimum Go version requirement for `filepath-securejoin` is now Go 1.18 | ||
(we use generics internally). | ||
|
||
For reference, `[email protected]` somewhat-arbitrarily bumped the | ||
Go version requirement to 1.21. | ||
|
||
While we did make some use of Go 1.21 stdlib features (and in principle Go | ||
versions <= 1.21 are no longer even supported by upstream anymore), some | ||
downstreams have complained that the version bump has meant that they have to | ||
do workarounds when backporting fixes that use the new `filepath-securejoin` | ||
API onto old branches. This is not an ideal situation, but since using this | ||
library is probably better for most downstreams than a hand-rolled | ||
workaround, we now have compatibility shims that allow us to build on older | ||
Go versions. | ||
- Lower minimum version requirement for `golang.org/x/sys` to `v0.18.0` (we | ||
need the wrappers for `fsconfig(2)`), which should also make backporting | ||
patches to older branches easier. | ||
|
||
## [0.3.5] - 2024-12-06 ## | ||
|
||
### Fixed ### | ||
- `MkdirAll` will now no longer return an `EEXIST` error if two racing | ||
processes are creating the same directory. We will still verify that the path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build linux && go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return fmt.Errorf("%w: %w", extraErr, baseErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build linux | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGoCompatErrorWrap(t *testing.T) { | ||
baseErr := errors.New("base error") | ||
extraErr := errors.New("extra error") | ||
|
||
err := wrapBaseError(baseErr, extraErr) | ||
|
||
require.Error(t, err) | ||
assert.ErrorIs(t, err, baseErr, "wrapped error should contain base error") | ||
assert.ErrorIs(t, err, extraErr, "wrapped error should contain extra error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build linux && !go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type wrappedError struct { | ||
inner error | ||
isError error | ||
} | ||
|
||
func (err wrappedError) Is(target error) bool { | ||
return err.isError == target | ||
} | ||
|
||
func (err wrappedError) Unwrap() error { | ||
return err.inner | ||
} | ||
|
||
func (err wrappedError) Error() string { | ||
return fmt.Sprintf("%v: %v", err.isError, err.inner) | ||
} | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return wrappedError{ | ||
inner: baseErr, | ||
isError: extraErr, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build linux && go1.21 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"slices" | ||
"sync" | ||
) | ||
|
||
func slices_DeleteFunc[S ~[]E, E any](slice S, delFn func(E) bool) S { | ||
return slices.DeleteFunc(slice, delFn) | ||
} | ||
|
||
func slices_Contains[S ~[]E, E comparable](slice S, val E) bool { | ||
return slices.Contains(slice, val) | ||
} | ||
|
||
func slices_Clone[S ~[]E, E any](slice S) S { | ||
return slices.Clone(slice) | ||
} | ||
|
||
func sync_OnceValue[T any](f func() T) func() T { | ||
return sync.OnceValue(f) | ||
} | ||
|
||
func sync_OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2) { | ||
return sync.OnceValues(f) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhat problematic, here's why.
A cache that actions/setup-go creates adds a Go version to the source data for the cache key (or maybe to the cache key itself -- I don't remember exactly). Now, if you change the go version manually (say from 1.22 to 1.23), the existing cache is instantly invalidated. But a string like "stable" or "oldstable" never changes, so when a new minor Go version is released, your CI jobs can still be stuck using an old one from the cache.
The same problem exists when a new Go patch version is released, and it is mitigated by setting the
check-latest: true
input foraction/setup-go
. I believe it also helps when you usestable/oldstable
, and in this case it becomes a must-have, if you really want to test Go 1.24.0 once it comes out, not when a cache expires.I might not be entirely correct here but at the very least it makes sense to keep an eye on your CI runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, damn. I assumed this was more like a thin alias that wouldn't cause those kinds of issues. I'll add
check-latest: true
, hopefully that mitigates the risk.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the aliases are supposed to imply
check-latest: true
according to the docs:But I'll add it anyway.