Fix Windows builds and test they compile (#543)

This commit is contained in:
Toni Spets
2023-12-15 22:57:23 +02:00
committed by GitHub
parent 6824eb61a8
commit 91ad34d709
2 changed files with 26 additions and 13 deletions

View File

@@ -20,7 +20,6 @@ jobs:
- uses: actions/setup-go@v4 - uses: actions/setup-go@v4
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
cache: true
- run: | - run: |
go install golang.org/x/tools/cmd/goimports@latest go install golang.org/x/tools/cmd/goimports@latest
@@ -29,6 +28,27 @@ jobs:
- uses: pre-commit/action@v3.0.0 - uses: pre-commit/action@v3.0.0
build-windows:
name: Build Windows
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y mingw-w64
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- run: |
go build ./cmd/litestream/
file ./litestream.exe
env:
CGO_ENABLED: "1"
GOOS: windows
GOARCH: amd64
CC: x86_64-w64-mingw32-gcc
build: build:
name: Build & Unit Test name: Build & Unit Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -39,12 +59,6 @@ jobs:
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ inputs.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ inputs.os }}-go-
- run: go env - run: go env
- run: go install ./cmd/litestream - run: go install ./cmd/litestream

View File

@@ -5,7 +5,6 @@ package main
import ( import (
"context" "context"
"io" "io"
"log"
"log/slog" "log/slog"
"os" "os"
"os/signal" "os/signal"
@@ -37,16 +36,16 @@ func runWindowsService(ctx context.Context) error {
defer elog.Close() defer elog.Close()
// Set eventlog as log writer while running. // Set eventlog as log writer while running.
log.SetOutput((*eventlogWriter)(elog)) slog.SetDefault(slog.New(slog.NewTextHandler((*eventlogWriter)(elog), nil)))
defer log.SetOutput(os.Stderr) defer slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
log.Print("Litestream service starting") slog.Info("Litestream service starting")
if err := svc.Run(serviceName, &windowsService{ctx: ctx}); err != nil { if err := svc.Run(serviceName, &windowsService{ctx: ctx}); err != nil {
return errStop return errStop
} }
log.Print("Litestream service stopped") slog.Info("Litestream service stopped")
return nil return nil
} }
@@ -69,7 +68,7 @@ func (s *windowsService) Execute(args []string, r <-chan svc.ChangeRequest, stat
} }
// Execute replication command. // Execute replication command.
if err := c.Run(s.ctx); err != nil { if err := c.Run(); err != nil {
slog.Error("cannot replicate", "error", err) slog.Error("cannot replicate", "error", err)
statusCh <- svc.Status{State: svc.StopPending} statusCh <- svc.Status{State: svc.StopPending}
return true, 2 return true, 2