• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / infraspace-savegame-editor / 16723959123

04 Aug 2025 01:04PM UTC coverage: 39.65% (+0.9%) from 38.733%
16723959123

push

github

heathcliff26
version: Add commit when archiving git

Currently the commit is empty when building rpm.
Add it during git archive directly into code.

Signed-off-by: Heathcliff <heathcliff@heathcliff.eu>

11 of 13 new or added lines in 1 file covered. (84.62%)

272 of 686 relevant lines covered (39.65%)

0.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.67
/pkg/gui/version.go
1
package gui
2

3
import (
4
        "os"
5
        "path/filepath"
6
        "runtime"
7
        "runtime/debug"
8
        "strings"
9

10
        "fyne.io/fyne/v2"
11
        "fyne.io/fyne/v2/widget"
12
        "github.com/heathcliff26/infraspace-savegame-editor/pkg/save"
13
)
14

15
const RELEASE = true
16

17
// NOTE: The $Format strings are replaced during 'git archive' thanks to the
18
// companion .gitattributes file containing 'export-subst' in this same
19
// directory.  See also https://git-scm.com/docs/gitattributes
20
var gitCommit string = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
21

22
func init() {
1✔
23
        initGitCommit()
1✔
24
}
1✔
25

26
func initGitCommit() {
1✔
27
        if strings.HasPrefix(gitCommit, "$Format") {
2✔
28
                var commit string
1✔
29
                buildinfo, _ := debug.ReadBuildInfo()
1✔
30
                for _, item := range buildinfo.Settings {
2✔
31
                        if item.Key == "vcs.revision" {
1✔
NEW
32
                                commit = item.Value
×
NEW
33
                                break
×
34
                        }
35
                }
36
                gitCommit = commit
1✔
37
        }
38
}
39

40
type Version struct {
41
        Name, Version, Commit, Go, GameVersion string
42
}
43

44
func NewVersionFromApp(app fyne.App) Version {
1✔
45
        commit := gitCommit
1✔
46
        if len(commit) > 7 {
2✔
47
                commit = commit[:7]
1✔
48
        }
1✔
49

50
        metadata := app.Metadata()
1✔
51

1✔
52
        name, _ := strings.CutSuffix(metadata.Name, ".exe")
1✔
53
        if name == "" {
2✔
54
                name = filepath.Base(os.Args[0])
1✔
55
        }
1✔
56

57
        result := Version{
1✔
58
                Name:        name,
1✔
59
                Version:     "v" + metadata.Version,
1✔
60
                Commit:      commit,
1✔
61
                Go:          runtime.Version(),
1✔
62
                GameVersion: save.GAME_VERSION,
1✔
63
        }
1✔
64

1✔
65
        if !RELEASE {
1✔
66
                result.Version += "-devel"
×
67
        }
×
68

69
        return result
1✔
70
}
71

72
// Create the content for the version dialog
73
func (v Version) CreateContent() fyne.CanvasObject {
×
74
        data := [][]string{
×
75
                {"Version:", v.Version},
×
76
                {"Commit:", v.Commit},
×
77
                {"Go:", v.Go},
×
78
                {"InfraSpace:", v.GameVersion},
×
79
        }
×
80

×
81
        versionTable := widget.NewTable(
×
82
                func() (int, int) {
×
83
                        return len(data), len(data[0])
×
84
                },
×
85
                func() fyne.CanvasObject {
×
86
                        return widget.NewLabel("                    ")
×
87
                },
×
88
                func(i widget.TableCellID, o fyne.CanvasObject) {
×
89
                        o.(*widget.Label).SetText(data[i.Row][i.Col])
×
90
                },
×
91
        )
92

93
        versionTable.ShowHeaderRow = false
×
94
        versionTable.ShowHeaderColumn = false
×
95
        versionTable.StickyRowCount = len(data) - 1
×
96
        versionTable.StickyColumnCount = len(data[0]) - 1
×
97
        versionTable.HideSeparators = true
×
98

×
99
        return versionTable
×
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc