Skip to content

Commit 6ce9fcf

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/klauspost/compress-1.18.0
2 parents a3ab061 + dca4999 commit 6ce9fcf

File tree

6 files changed

+88
-15
lines changed

6 files changed

+88
-15
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
- uses: actions/setup-go@v5
1919
- uses: actions/checkout@v4
2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
22+
with:
23+
version: v2.3.0
2224

2325
man-page:
2426
name: Check if man page has been regenerated
@@ -72,9 +74,21 @@ jobs:
7274
steps:
7375
- name: Checkout code
7476
uses: actions/checkout@v4
77+
with:
78+
fetch-depth: 0
79+
filter: tree:0
80+
81+
- name: Set safe directory in container
82+
run: /usr/bin/git config --global --add safe.directory ${GITHUB_WORKSPACE}
83+
84+
- name: Define fakemachine version
85+
run: echo "FAKEMACHINE_VER=$(git describe --always --tags HEAD)" >> "$GITHUB_ENV"
7586

7687
- name: Test build
77-
run: go build -o fakemachine cmd/fakemachine/main.go
88+
run: go build -ldflags="-X main.Version=${FAKEMACHINE_VER}" ./cmd/fakemachine
89+
90+
- name: Print fakemachine version
91+
run: ./fakemachine --version
7892

7993
- name: Run unit tests (${{matrix.backend}} backend)
8094
run: go test -v ./... --backend=${{matrix.backend}} | tee test.out

.golangci.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
version: "2"
12
linters:
23
enable:
3-
- errcheck
44
- errorlint
5-
- gofmt
6-
- gosimple
7-
- govet
8-
- ineffassign
95
- misspell
106
- revive
117
- staticcheck
12-
- stylecheck
13-
- unused
148
- whitespace
9+
exclusions:
10+
generated: lax
11+
presets:
12+
- comments
13+
- common-false-positives
14+
- legacy
15+
- std-error-handling
16+
paths:
17+
- third_party$
18+
- builtin$
19+
- examples$
20+
formatters:
21+
enable:
22+
- gofmt
23+
exclusions:
24+
generated: lax
25+
paths:
26+
- third_party$
27+
- builtin$
28+
- examples$

cmd/fakemachine/main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"github.com/go-debos/fakemachine"
99
"github.com/jessevdk/go-flags"
1010
"os"
11+
"runtime/debug"
1112
"strings"
1213
)
1314

15+
var Version string
16+
1417
type Options struct {
1518
Backend string `short:"b" long:"backend" description:"Virtualisation backend to use" default:"auto"`
1619
Volumes []string `short:"v" long:"volume" description:"volume to mount"`
@@ -22,11 +25,47 @@ type Options struct {
2225
ScratchSize string `short:"s" long:"scratchsize" description:"On-disk scratch space size (with a unit suffix, e.g. 4G); if unset, memory backed scratch space is used"`
2326
ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fakemachine"`
2427
Quiet bool `short:"q" long:"quiet" description:"Don't show logs from fakemachine or the backend; only print the command's stdout/stderr"`
28+
Version bool `long:"version" description:"Print fakemachine version"`
2529
}
2630

2731
var options Options
2832
var parser = flags.NewParser(&options, flags.Default)
2933

34+
func GetDeterminedVersion(version string) string {
35+
DeterminedVersion := "unknown"
36+
37+
// Use the injected Version from build system if any.
38+
// Otherwise try to determine the best version string from debug info.
39+
if len(version) > 0 {
40+
DeterminedVersion = version
41+
} else {
42+
info, ok := debug.ReadBuildInfo()
43+
if ok {
44+
// Try vcs version first as it will only be set on a local build
45+
var revision *string
46+
var modified *string
47+
for _, s := range info.Settings {
48+
if s.Key == "vcs.revision" {
49+
revision = &s.Value
50+
}
51+
if s.Key == "vcs.modified" {
52+
modified = &s.Value
53+
}
54+
}
55+
if revision != nil {
56+
DeterminedVersion = *revision
57+
if modified != nil && *modified == "true" {
58+
DeterminedVersion += "-dirty"
59+
}
60+
} else {
61+
DeterminedVersion = info.Main.Version
62+
}
63+
}
64+
}
65+
66+
return DeterminedVersion
67+
}
68+
3069
func warnLocalhost(variable string, value string) {
3170
message := `WARNING: Environment variable %[1]s contains a reference to
3271
localhost. This may not work when running from fakemachine.
@@ -151,6 +190,11 @@ func main() {
151190
os.Exit(1)
152191
}
153192

193+
if options.Version {
194+
fmt.Printf("fakemachine %v\n", GetDeterminedVersion(Version))
195+
return
196+
}
197+
154198
m, err := fakemachine.NewMachineWithBackend(options.Backend)
155199
if err != nil {
156200
fmt.Printf("fakemachine: %v\n", err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/go-debos/fakemachine
33
go 1.24
44

55
require (
6-
al.essio.dev/pkg/shellescape v1.5.1
6+
al.essio.dev/pkg/shellescape v1.6.0
77
github.com/docker/go-units v0.5.0
88
github.com/jessevdk/go-flags v1.6.1
99
github.com/klauspost/compress v1.18.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
al.essio.dev/pkg/shellescape v1.5.1 h1:86HrALUujYS/h+GtqoB26SBEdkWfmMI6FubjXlsXyho=
2-
al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
1+
al.essio.dev/pkg/shellescape v1.6.0 h1:NxFcEqzFSEVCGN2yq7Huv/9hyCEGVa/TncnOOBBeXHA=
2+
al.essio.dev/pkg/shellescape v1.6.0/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=

machine_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ func AssertSectorSize(t *testing.T, sectorsize int) {
8989
m.SetSectorSize(sectorsize)
9090
_, err := m.CreateImage("test-"+strconv.Itoa(sectorsize)+"-sector-size.img", 1024*1024)
9191
require.Nil(t, err)
92-
if sectorsize == 512 {
92+
switch sectorsize {
93+
case 512:
9394
exitcode, _ := m.RunInMachineWithArgs([]string{"-test.run", "TestImage512SectorSize", backendName})
9495
require.Equal(t, exitcode, 0)
95-
} else if sectorsize == 4096 {
96+
case 4096:
9697
exitcode, _ := m.RunInMachineWithArgs([]string{"-test.run", "TestImage4kSectorSize", backendName})
9798
require.Equal(t, exitcode, 0)
98-
} else {
99+
default:
99100
t.Fatalf("Unhandled sector size %d", sectorsize)
100101
}
101102
} else {

0 commit comments

Comments
 (0)