Skip to content

Commit

Permalink
Fix chunk shuffle for Go 1.20
Browse files Browse the repository at this point in the history
From Go 1.20 the math/rand package started to seed the global random number generator (used by top-level functions like Float64 and Int) with a random value.

This broke chunking logic in Hugoreleaser. We need the same shuffle for each build.
  • Loading branch information
bep committed Mar 1, 2023
1 parent da0f883 commit e4cc2e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.19.x,1.20.x]
platform: [ macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
6 changes: 5 additions & 1 deletion cmd/buildcmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (

const commandName = "build"

// From Go 1.20 the math/rand package started to seed the global random number generator (used by top-level functions like Float64 and Int) with a random value.
// This broke chunking logic in Hugoreleaser. We need the same shuffle for each build.
var rand1 = rand.New(rand.NewSource(1))

// New returns a usable ffcli.Command for the build subcommand.
func New(core *corecmd.Core) *ffcli.Command {
fs := flag.NewFlagSet(corecmd.CommandName+" "+commandName, flag.ExitOnError)
Expand Down Expand Up @@ -105,7 +109,7 @@ func (b *Builder) Exec(ctx context.Context, args []string) error {
if b.chunks > 0 {
// Resource-heavy builds tend to be configured in proximity to eachother,
// so this shuffle may help avoid clustering these slow builds in the same partition.
rand.Shuffle(len(archs), func(i, j int) {
rand1.Shuffle(len(archs), func(i, j int) {
archs[i], archs[j] = archs[j], archs[i]
})

Expand Down

0 comments on commit e4cc2e0

Please sign in to comment.