Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore (workflows): add make-gen-delta workflow #44

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/make-gen-delta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "make-gen-delta"
on:
- workflow_dispatch
- push
- workflow_call

permissions:
contents: read

jobs:
make-gen-delta:
name: "Check for uncommitted changes from make gen"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: '0'
- name: Determine Go version
id: get-go-version
# We use .go-version as our source of truth for current Go
# version, because "goenv" can react to it automatically.
run: |
echo "Building with Go $(cat .go-version)"
echo "go-version=$(cat .go-version)" >> "$GITHUB_OUTPUT"
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "${{ steps.get-go-version.outputs.go-version }}"
- name: Running go mod tidy
run: |
go mod tidy
- name: Install Dependencies
run: |
make tools
- name: Running make gen
run: |
make gen
- name: Check for changes
run: |
git diff --exit-code
git status --porcelain
test -z "$(git status --porcelain)"
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ REPO_PATH := github.com/hashicorp/dbw
.PHONY: tools
tools:
go generate -tags tools tools/tools.go
go install github.com/bufbuild/buf/cmd/buf@v1.15.1
go install github.com/hashicorp/copywrite@v0.15.0

.PHONY: fmt
fmt:
gofumpt -w $$(find . -name '*.go' | grep -v pb.go)
gofumpt -w $$(find . -name '*.go' ! -name '*pb.go')
buf format -w

.PHONY: copywrite
copywrite:
copywrite headers

.PHONY: gen
gen: proto fmt copywrite

.PHONY: test
test:
Expand All @@ -39,11 +49,7 @@ proto: protolint protobuild

.PHONY: protobuild
protobuild:
protoc \
./internal/proto/local/dbtest/storage/v1/dbtest.proto \
--proto_path=internal/proto/local \
--go_out=:.

buf generate
@protoc-go-inject-tag -input=./internal/dbtest/dbtest.pb.go

.PHONY: protolint
Expand Down
9 changes: 9 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

version: v1
plugins:
- name: go
out: .
opt:
- paths=import
1 change: 0 additions & 1 deletion clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func SetColumns(names []string) []ColumnValue {
// OnConflict specifies how to handle alternative actions to take when an insert
// results in a unique constraint or exclusion constraint error.
type OnConflict struct {

// Target specifies what conflict you want to define a policy for. This can
// be any one of these:
// Columns: the name of a specific column or columns
Expand Down
3 changes: 1 addition & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ func TestOpen(t *testing.T) {
rows, err := rw.Query(context.Background(), "PRAGMA foreign_keys", nil)
require.NoError(err)
require.True(rows.Next())
type foo struct {
}
type foo struct{}
f := struct {
ForeignKeys int
}{}
Expand Down
4 changes: 2 additions & 2 deletions internal/dbtest/dbtest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions internal/proto/local/dbtest/storage/v1/dbtest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ syntax = "proto3";
// are only used for unit tests and are not part of the rest of the domain model

package dbtest.storage.v1;
option go_package = "internal/dbtest;dbtest";

import "google/protobuf/timestamp.proto";

option go_package = "internal/dbtest;dbtest";

// Timestamp for storage messages. We've defined a new local type wrapper
// of google.protobuf.Timestamp so we can implement sql.Scanner and sql.Valuer
// interfaces. See:
Expand Down Expand Up @@ -126,4 +127,4 @@ message StoreTestScooter {

// @inject_tag: `gorm:"-"`
string read_only_field = 6;
}
}
1 change: 1 addition & 0 deletions rw.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func (rw *RW) clearDefaultNullResourceFields(ctx context.Context, i interface{})
}
return nil
}

func (rw *RW) primaryKeysWhere(ctx context.Context, i interface{}) (string, []interface{}, error) {
const op = "dbw.primaryKeysWhere"
var fieldNames []string
Expand Down