Skip to content

Commit 9a078f0

Browse files
committed
Update ruler.
1 parent d173ac7 commit 9a078f0

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

Makefile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,36 @@ LD_FLAGS_GITHASH := -X 'github.com/prequel-dev/cre/pkg/ruler.Githash=$(GITHASH)'
77
LD_FLAGS_VERSION := -X 'github.com/prequel-dev/cre/pkg/ruler.Version=$(VERSION)'
88
LD_FLAGS := $(LD_FLAGS_GITHASH) $(LD_FLAGS_VERSION)
99

10+
BINDIR := ./bin
11+
1012
.PHONY: all
1113
all: clean ruler rules
1214

15+
.PHONY: bindir
16+
bindir:
17+
mkdir -p $(BINDIR)
18+
1319
.PHONY: ruler
14-
ruler:
15-
@mkdir -p bin/
16-
@env CGO_ENABLED=0 go build -ldflags "${LD_FLAGS}" -o ./bin/ruler ./cmd/ruler/ruler.go
20+
ruler: bindir
21+
@env CGO_ENABLED=0 go build -ldflags "${LD_FLAGS}" -o ./bin/ruler-${SEMVER} ./cmd/ruler/ruler.go
22+
23+
.PHONY: linux
24+
linux: bindir
25+
@env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-${SEMVER}-linux-amd64 ./cmd/ruler/ruler.go
26+
@env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-${SEMVER}-linux-arm64 ./cmd/ruler/ruler.go
27+
28+
.PHONY: darwin
29+
darwin: bindir
30+
@env GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-${SEMVER}-darwin-arm64 ./cmd/ruler/ruler.go
1731

18-
.PHONY: cross-compile
19-
cross-compile:
20-
@env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-linux-amd64 ./cmd/ruler/ruler.go
21-
@env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-linux-arm64 ./cmd/ruler/ruler.go
22-
@env GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-darwin-arm64 ./cmd/ruler/ruler.go
23-
@env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-windows-amd64 ./cmd/ruler/ruler.go
32+
.PHONY: windows
33+
windows: bindir
34+
@env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags "${LD_FLAGS}" -o ./bin/ruler-${SEMVER}-windows-amd64 ./cmd/ruler/ruler.go
2435

2536
.PHONY: rules
2637
rules:
2738
@mkdir -p bin/rules/
28-
@./bin/ruler build -p rules -o ./bin
39+
@./bin/ruler-${SEMVER} build -p rules -o ./bin
2940

3041
.PHONY: clean
3142
clean:

pkg/ruler/build.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package ruler
22

33
import (
44
"bytes"
5-
"crypto/sha256"
6-
"encoding/hex"
75
"errors"
86
"fmt"
97
"os"
@@ -246,31 +244,18 @@ func _build(vers, inPath, outPath, packageName string) error {
246244
return err
247245
}
248246

249-
hash := _sha256(doc)
250-
251-
fileName := makeFilename(packageName, vers, hash)
247+
fileName := makeFilename(packageName, vers)
252248
fullPath := filepath.Join(outPath, fileName)
253249

254250
if err = writeFile(fullPath, doc); err != nil {
255251
return err
256252
}
257253

258-
hashPath := fmt.Sprintf("%s.sha256", fullPath)
259-
if err = writeFile(hashPath, []byte(hash)); err != nil {
260-
return err
261-
}
262-
263-
fmt.Printf("Wrote file [sha256 %s]: %s\n", hash, fileName)
264-
fmt.Printf("Wrote hash file: %s\n", hashPath)
254+
fmt.Printf("Wrote file: %s\n", fileName)
265255

266256
return nil
267257
}
268258

269-
func _sha256(data []byte) string {
270-
sum := sha256.Sum256(data)
271-
return hex.EncodeToString(sum[:])
272-
}
273-
274259
func writeFile(fn string, data []byte) error {
275260
fh, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0644)
276261
if err != nil {
@@ -284,23 +269,17 @@ func writeFile(fn string, data []byte) error {
284269
return fh.Close()
285270
}
286271

287-
func makeFilename(name, vers, hash string) string {
272+
func makeFilename(name, vers string) string {
288273
name = strings.TrimSuffix(name, ".yaml")
289274
vers = strings.TrimPrefix(vers, "v")
290275

291-
buildMeta := fmt.Sprintf(".%s", hash[:8])
292-
293-
return fmt.Sprintf("%s.%s%s.yaml", name, vers, buildMeta)
276+
return fmt.Sprintf("%s.%s.yaml", name, vers)
294277
}
295278

296279
// Convert to document per section
297280

298281
func generateDocument(rules map[string]parser.ParseRuleT, terms map[string]parser.ParseTermT) ([]byte, error) {
299282

300-
type docT struct {
301-
Rules []any `yaml:"rules,omitempty"`
302-
}
303-
304283
// Gather keys to produce consistent order output
305284
ruleKeys := make([]string, 0, len(rules))
306285
for k := range rules {

pkg/ruler/validate.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ var (
2727

2828
type dupesT map[string]struct{}
2929
type tagsT dupesT
30-
type rulesT dupesT
31-
type termsT dupesT
3230

3331
func validateTagsFields(t RuleIncludeT, tags tagsT) error {
3432

0 commit comments

Comments
 (0)