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

lightningnetwork / lnd / 12292179806

12 Dec 2024 08:00AM UTC coverage: 49.544% (+0.004%) from 49.54%
12292179806

Pull #9342

github

ellemouton
docs: add release notes entry
Pull Request #9342: protofsm: update GR Manager usage and start using structured logging

0 of 62 new or added lines in 2 files covered. (0.0%)

78 existing lines in 14 files now uncovered.

100377 of 202602 relevant lines covered (49.54%)

2.06 hits per line

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

79.07
/build/version.go
1
// Copyright (c) 2013-2017 The btcsuite developers
2
// Copyright (c) 2015-2016 The Decred developers
3
// Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go
4
// Copyright (C) 2015-2022 The Lightning Network Developers
5

6
package build
7

8
import (
9
        "context"
10
        "encoding/hex"
11
        "fmt"
12
        "runtime/debug"
13
        "strings"
14

15
        "github.com/btcsuite/btclog/v2"
16
)
17

18
var (
19
        // Commit stores the current commit of this build, which includes the
20
        // most recent tag, the number of commits since that tag (if non-zero),
21
        // the commit hash, and a dirty marker. This should be set using the
22
        // -ldflags during compilation.
23
        Commit string
24

25
        // CommitHash stores the current commit hash of this build.
26
        CommitHash string
27

28
        // RawTags contains the raw set of build tags, separated by commas.
29
        RawTags string
30

31
        // GoVersion stores the go version that the executable was compiled
32
        // with.
33
        GoVersion string
34
)
35

36
// semanticAlphabet is the set of characters that are permitted for use in an
37
// AppPreRelease.
38
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-."
39

40
// These constants define the application version and follow the semantic
41
// versioning 2.0.0 spec (http://semver.org/).
42
const (
43
        // AppMajor defines the major version of this binary.
44
        AppMajor uint = 0
45

46
        // AppMinor defines the minor version of this binary.
47
        AppMinor uint = 18
48

49
        // AppPatch defines the application patch for this binary.
50
        AppPatch uint = 99
51

52
        // AppPreRelease MUST only contain characters from semanticAlphabet per
53
        // the semantic versioning spec.
54
        AppPreRelease = "beta"
55
)
56

57
func init() {
4✔
58
        // Assert that AppPreRelease is valid according to the semantic
4✔
59
        // versioning guidelines for pre-release version and build metadata
4✔
60
        // strings. In particular it MUST only contain characters in
4✔
61
        // semanticAlphabet.
4✔
62
        for _, r := range AppPreRelease {
8✔
63
                if !strings.ContainsRune(semanticAlphabet, r) {
4✔
64
                        panic(fmt.Errorf("rune: %v is not in the semantic "+
×
65
                                "alphabet", r))
×
66
                }
67
        }
68

69
        // Get build information from the runtime.
70
        if info, ok := debug.ReadBuildInfo(); ok {
8✔
71
                GoVersion = info.GoVersion
4✔
72
                for _, setting := range info.Settings {
8✔
73
                        switch setting.Key {
4✔
74
                        case "vcs.revision":
4✔
75
                                CommitHash = setting.Value
4✔
76

77
                        case "-tags":
4✔
78
                                RawTags = setting.Value
4✔
79
                        }
80
                }
81
        }
82
}
83

84
// Version returns the application version as a properly formed string per the
85
// semantic versioning 2.0.0 spec (http://semver.org/).
86
func Version() string {
4✔
87
        // Start with the major, minor, and patch versions.
4✔
88
        version := fmt.Sprintf("%d.%d.%d", AppMajor, AppMinor, AppPatch)
4✔
89

4✔
90
        // Append pre-release version if there is one. The hyphen called for by
4✔
91
        // the semantic versioning spec is automatically appended and should not
4✔
92
        // be contained in the pre-release string.
4✔
93
        if AppPreRelease != "" {
8✔
94
                version = fmt.Sprintf("%s-%s", version, AppPreRelease)
4✔
95
        }
4✔
96

97
        return version
4✔
98
}
99

100
// Tags returns the list of build tags that were compiled into the executable.
101
func Tags() []string {
4✔
102
        if len(RawTags) == 0 {
4✔
103
                return nil
×
104
        }
×
105

106
        return strings.Split(RawTags, ",")
4✔
107
}
108

109
// WithBuildInfo derives a child context with the build information attached as
110
// attributes. At the moment, this only includes the current build's commit
111
// hash.
112
func WithBuildInfo(ctx context.Context, cfg *LogConfig) (context.Context,
113
        error) {
4✔
114

4✔
115
        if cfg.NoCommitHash {
8✔
116
                return ctx, nil
4✔
117
        }
4✔
118

119
        // Convert the commit hash to a byte slice.
120
        commitHash, err := hex.DecodeString(CommitHash)
×
121
        if err != nil {
×
122
                return nil, fmt.Errorf("unable to decode commit hash: %w", err)
×
123
        }
×
124

NEW
125
        return btclog.WithCtx(ctx, btclog.Hex3("rev", commitHash)), nil
×
126
}
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