Skip to content

Commit

Permalink
write the index deterministically
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-hanselman committed Sep 25, 2021
1 parent 968d5db commit d5a70a7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
"sort"
"strings"

"github.com/kevin-hanselman/dud/src/artifact"
Expand Down Expand Up @@ -48,7 +49,15 @@ func (idx Index) ToFile(indexPath string) error {
return errors.Wrap(err, errPrefix)
}
defer file.Close()

// Sort the stage paths index file is written deterministically.
paths := []string{}
for stagePath := range idx {
paths = append(paths, stagePath)
}
sort.Strings(paths)

for _, stagePath := range paths {
if _, err := fmt.Fprintln(file, stagePath); err != nil {
return errors.Wrapf(err, "%s: write %s", errPrefix, stagePath)
}
Expand Down

0 comments on commit d5a70a7

Please sign in to comment.