Upgrade to go1.23 and swap to using the new iters package

This commit is contained in:
David Dworken 2024-08-25 12:24:19 -07:00
parent 05c71b2f21
commit 7a19b4defd
No known key found for this signature in database
9 changed files with 41 additions and 44 deletions

View File

@ -44,7 +44,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Go test
if: ${{ !startsWith(github.event.head_commit.message, 'Release') }}
env:

View File

@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Docker Compose setup
run: |
set -euo pipefail

View File

@ -32,7 +32,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Linux Setup
if: ${{ matrix.os == 'ubuntu-latest'}}
run: |
@ -119,7 +119,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Download artifact
uses: actions/download-artifact@v4
- name: Check all goldens were used

View File

@ -13,7 +13,7 @@ jobs:
- uses: actions/setup-python@v3
- uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Install dependencies
run: |

View File

@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- name: Build server binary
run: |
GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }} go build -o hishtory-server-${{ matrix.goos }}-${{ matrix.goarch }} backend/server/server.go

View File

@ -33,7 +33,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-linux-amd64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-linux-arm64:
@ -45,7 +45,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-linux-arm64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-linux-arm7:
@ -57,7 +57,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-linux-arm7.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-freebsd-amd64:
@ -69,7 +69,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-freebsd-amd64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-netbsd-amd64:
@ -81,7 +81,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-netbsd-amd64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-darwin-amd64:
@ -94,7 +94,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-darwin-amd64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
build-darwin-arm64:
@ -107,7 +107,7 @@ jobs:
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
with:
config-file: .github/slsa/.slsa-goreleaser-darwin-arm64.yml
go-version: 1.21
go-version: 1.23
evaluated-envs: "VERSION_LDFLAGS:${{needs.args.outputs.ldflags}}"
compile-builder: true # See github.com/slsa-framework/slsa-github-generator/issues/942
@ -184,7 +184,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.23
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741
with:
name: hishtory-linux-amd64

View File

@ -1,4 +1,4 @@
FROM golang:1.21-alpine3.17 AS builder
FROM golang:1.23.0-alpine3.20 AS builder
WORKDIR /app
RUN apk add --update --no-cache --virtual .build-deps build-base

View File

@ -31,6 +31,7 @@ import (
"github.com/schollz/progressbar/v3"
"golang.org/x/exp/slices"
"gorm.io/gorm"
"iter"
)
//go:embed config.sh
@ -369,10 +370,10 @@ func getFishHistoryPath(homedir string) string {
return filepath.Join(homedir, ".local/share/fish/fish_history")
}
func parseFishHistory(homedir string) Seq2[string, error] {
func parseFishHistory(homedir string) iter.Seq2[string, error] {
lines := readFileToIterator(getFishHistoryPath(homedir))
return func(yield func(string, error) bool) bool {
return lines(func(line string, err error) bool {
return func(yield func(string, error) bool) {
lines(func(line string, err error) bool {
if err != nil {
return yield(line, err)
}
@ -385,44 +386,39 @@ func parseFishHistory(homedir string) Seq2[string, error] {
}
}
type (
// Represents an iterator of (K,V). Equivalent of the future Go stdlib type iter.Seq2.
// TODO: Swap this to the stdlib function once it has been released, along with the below two functions
Seq2[K, V any] func(yield func(K, V) bool) bool
)
// Concatenate two iterators. Equivalent of the future Go stdlib function iter.Concat2.
func concatIterators(iters ...Seq2[string, error]) Seq2[string, error] {
return func(yield func(string, error) bool) bool {
// Concatenate two iterators.
// TODO: Equivalent of the future Go stdlib function iter.Concat2.
func concatIterators(iters ...iter.Seq2[string, error]) iter.Seq2[string, error] {
return func(yield func(string, error) bool) {
for _, seq := range iters {
if !seq(yield) {
return false
}
seq(yield)
}
return true
return
}
}
// Convert a slice into an iterator. Equivalent of the future Go stdlib function iter.Values
func Values[Slice ~[]Elem, Elem any](s Slice) Seq2[Elem, error] {
return func(yield func(Elem, error) bool) bool {
// Convert a slice into an iterator.
// TODO: Equivalent of the future Go stdlib function iter.Values
func Values[Slice ~[]Elem, Elem any](s Slice) iter.Seq2[Elem, error] {
return func(yield func(Elem, error) bool) {
for _, v := range s {
if !yield(v, nil) {
return false
return
}
}
return true
return
}
}
func readFileToIterator(path string) Seq2[string, error] {
return func(yield func(string, error) bool) bool {
func readFileToIterator(path string) iter.Seq2[string, error] {
return func(yield func(string, error) bool) {
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
return true
return
}
file, err := os.Open(path)
if err != nil {
return yield("", fmt.Errorf("failed to open file: %w", err))
yield("", fmt.Errorf("failed to open file: %w", err))
return
}
defer file.Close()
@ -432,15 +428,16 @@ func readFileToIterator(path string) Seq2[string, error] {
for scanner.Scan() {
line := scanner.Text()
if !yield(line, nil) {
return false
return
}
}
if err := scanner.Err(); err != nil {
return yield("", fmt.Errorf("scanner.Err()=%w", err))
yield("", fmt.Errorf("scanner.Err()=%w", err))
return
}
return true
return
}
}

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/ddworken/hishtory
go 1.21
go 1.23.0
require (
github.com/DataDog/datadog-go v4.8.3+incompatible