Compare commits
1
Commits
next
...
74185ae5d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74185ae5d6 |
@@ -8,9 +8,6 @@ RUN go mod download
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Touch .pb.go so make does not try to regenerate via protoc (file is committed)
|
|
||||||
RUN touch mfer/mf.pb.go
|
|
||||||
|
|
||||||
# Go half of fmt-check only: this image has no node, so no prettier. The
|
# Go half of fmt-check only: this image has no node, so no prettier. The
|
||||||
# markdown half runs in the mdfmt stage below.
|
# markdown half runs in the mdfmt stage below.
|
||||||
RUN make fmt-check-go
|
RUN make fmt-check-go
|
||||||
@@ -46,9 +43,6 @@ RUN go mod download
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Touch .pb.go so make does not try to regenerate via protoc (file is committed)
|
|
||||||
RUN touch mfer/mf.pb.go
|
|
||||||
|
|
||||||
RUN make test
|
RUN make test
|
||||||
|
|
||||||
# A build context sent as a tar archive, as upaas sends it, keeps its files'
|
# A build context sent as a tar archive, as upaas sends it, keeps its files'
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ GOLDFLAGS += -X main.Version=$(VERSION)
|
|||||||
GOLDFLAGS += -X main.Gitrev=$(GITREV_BUILD)
|
GOLDFLAGS += -X main.Gitrev=$(GITREV_BUILD)
|
||||||
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
||||||
|
|
||||||
.PHONY: bootstrap setup docker default run ci test fuzz check lint fmt fmt-check fmt-check-go fmt-check-md hooks fixme
|
.PHONY: bootstrap setup docker default run ci test fuzz check lint fmt fmt-check fmt-check-go fmt-check-md hooks fixme generate
|
||||||
|
|
||||||
default: fmt test
|
default: fmt test
|
||||||
|
|
||||||
@@ -58,15 +58,14 @@ fmt-check-md:
|
|||||||
hooks:
|
hooks:
|
||||||
@script/install-precommit
|
@script/install-precommit
|
||||||
|
|
||||||
mfer/mf.pb.go: mfer/mf.proto
|
generate:
|
||||||
cd mfer && go generate .
|
@script/generate
|
||||||
|
|
||||||
bin/mfer: $(SOURCEFILES) mfer/mf.pb.go
|
bin/mfer: $(SOURCEFILES)
|
||||||
protoc --version
|
|
||||||
cd cmd/mfer && go build -tags urfave_cli_no_docs -o ../../bin/mfer $(GOFLAGS) .
|
cd cmd/mfer && go build -tags urfave_cli_no_docs -o ../../bin/mfer $(GOFLAGS) .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rfv mfer/*.pb.go bin/mfer cmd/mfer/mfer *.dockerimage
|
rm -rfv bin/mfer cmd/mfer/mfer *.dockerimage
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@script/fmt
|
@script/fmt
|
||||||
|
|||||||
@@ -72,8 +72,12 @@ provide:
|
|||||||
`script/bootstrap`, then `script/install-precommit`
|
`script/bootstrap`, then `script/install-precommit`
|
||||||
- `script/projectname` — output the project name (`mfer`); used by other scripts
|
- `script/projectname` — output the project name (`mfer`); used by other scripts
|
||||||
such as `script/docker`
|
such as `script/docker`
|
||||||
- `script/test` — run the test suite (`go test`), regenerating the protobuf code
|
- `script/test` — run the test suite (`go test`); one test fails when
|
||||||
first if it is stale
|
`mfer/mf.proto` no longer matches the hash `script/generate` recorded
|
||||||
|
- `script/generate` — regenerate `mfer/mf.pb.go` from `mfer/mf.proto` and record
|
||||||
|
the hash of that `mfer/mf.proto` in `mfer/mf.proto.sha256`; needs `protoc` and
|
||||||
|
`protoc-gen-go`, and is the only thing that regenerates the committed
|
||||||
|
`mfer/mf.pb.go`
|
||||||
- `script/fuzz` — fuzz the manifest parser for one minute; run by hand
|
- `script/fuzz` — fuzz the manifest parser for one minute; run by hand
|
||||||
(`make fuzz`), never by CI, while `script/test` runs its committed seed corpus
|
(`make fuzz`), never by CI, while `script/test` runs its committed seed corpus
|
||||||
as ordinary tests
|
as ordinary tests
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
103901c42b94396aa7ae128fd503ef693a4b7a03b2169481f25fda3d2c254e00 mf.proto
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package mfer_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// mf.pb.go is generated from mf.proto and committed. `make generate`
|
||||||
|
// records the hash of the mf.proto it generated from in mf.proto.sha256.
|
||||||
|
func TestGeneratedCodeMatchesProto(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
proto, err := os.ReadFile("mf.proto")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorded, err := os.ReadFile("mf.proto.sha256")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recordedHash, _, _ := strings.Cut(string(recorded), " ")
|
||||||
|
sum := sha256.Sum256(proto)
|
||||||
|
require.Equal(t, recordedHash, hex.EncodeToString(sum[:]),
|
||||||
|
"mfer/mf.proto has changed since mfer/mf.pb.go was generated "+
|
||||||
|
"from it: run `make generate` and commit the result")
|
||||||
|
}
|
||||||
-11
@@ -5,19 +5,8 @@ set -eu
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||||
|
|
||||||
# Regenerate mfer/mf.pb.go from mfer/mf.proto if it is missing or stale
|
|
||||||
# (mirrors the old Makefile prerequisite; the generated file is
|
|
||||||
# committed, so this is normally a no-op).
|
|
||||||
ensure_pb() {
|
|
||||||
if [ ! -f mfer/mf.pb.go ] ||
|
|
||||||
[ -n "$(find mfer/mf.proto -newer mfer/mf.pb.go 2>/dev/null)" ]; then
|
|
||||||
(cd mfer && go generate .)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
ensure_pb
|
|
||||||
gofumpt -l -w mfer internal cmd
|
gofumpt -l -w mfer internal cmd
|
||||||
# Markdown and JSON, over the same file set script/fmt-check verifies.
|
# Markdown and JSON, over the same file set script/fmt-check verifies.
|
||||||
"$SCRIPT_DIR/prettier" --write
|
"$SCRIPT_DIR/prettier" --write
|
||||||
|
|||||||
@@ -6,19 +6,8 @@ set -eu
|
|||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
# Regenerate mfer/mf.pb.go from mfer/mf.proto if it is missing or stale
|
|
||||||
# (mirrors the old Makefile prerequisite; the generated file is
|
|
||||||
# committed, so this is normally a no-op).
|
|
||||||
ensure_pb() {
|
|
||||||
if [ ! -f mfer/mf.pb.go ] ||
|
|
||||||
[ -n "$(find mfer/mf.proto -newer mfer/mf.pb.go 2>/dev/null)" ]; then
|
|
||||||
(cd mfer && go generate .)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
ensure_pb
|
|
||||||
if [ -n "$(gofmt -l .)" ]; then
|
if [ -n "$(gofmt -l .)" ]; then
|
||||||
echo "gofmt: files need formatting:" >&2
|
echo "gofmt: files need formatting:" >&2
|
||||||
gofmt -l . >&2
|
gofmt -l . >&2
|
||||||
|
|||||||
Executable
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# script/generate: regenerate mfer/mf.pb.go from mfer/mf.proto, and record
|
||||||
|
# the hash of that mf.proto in mfer/mf.proto.sha256. Nothing else
|
||||||
|
# regenerates mf.pb.go: it is committed, so building and checking need no
|
||||||
|
# protoc. Needs protoc and protoc-gen-go on PATH. A test fails while
|
||||||
|
# mf.proto no longer matches the recorded hash.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
|
main() {
|
||||||
|
cd "$ROOT/mfer"
|
||||||
|
go generate .
|
||||||
|
shasum -a 256 mf.proto >mf.proto.sha256
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
-11
@@ -4,19 +4,8 @@ set -eu
|
|||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
# Regenerate mfer/mf.pb.go from mfer/mf.proto if it is missing or stale
|
|
||||||
# (mirrors the old Makefile prerequisite; the generated file is
|
|
||||||
# committed, so this is normally a no-op).
|
|
||||||
ensure_pb() {
|
|
||||||
if [ ! -f mfer/mf.pb.go ] ||
|
|
||||||
[ -n "$(find mfer/mf.proto -newer mfer/mf.pb.go 2>/dev/null)" ]; then
|
|
||||||
(cd mfer && go generate .)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
ensure_pb
|
|
||||||
go test -timeout 30s -race -cover ./... ||
|
go test -timeout 30s -race -cover ./... ||
|
||||||
{
|
{
|
||||||
echo "--- Rerunning with -v for details ---"
|
echo "--- Rerunning with -v for details ---"
|
||||||
|
|||||||
Reference in New Issue
Block a user