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

feat: compare generated files on e2e #15

Merged
merged 6 commits into from
Oct 12, 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
2 changes: 0 additions & 2 deletions .github/workflows/build-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:

- name: Test e2e
run: make e2e
- name: Test e2e (cached)
run: make e2e

- name: Upload build
uses: actions/upload-artifact@v3
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ lint-fix: ## Lints files, and fixes ones that are fixable

e2e: $(if $(CI),,build) ## Runs e2e tests
echo "Running e2e tests..."
cd e2e/
$(TARGET)
e2e/run.sh

clean: ## Cleans build files
rm -rfv $(OUT_DIR)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Various environment variables are available for configuration:
- `GO_GENERATE_FAST_DISABLE`: Completely ignores caching.
- `GO_GENERATE_FAST_READ_ONLY`: Uses the existing cache but prevents any new
cache entries.
- `GO_GENERATE_FAST_FORCE_USE_CACHE`: Forceably uses cache. If it does not exist, the command fails.
- `GO_GENERATE_FAST_RECACHE`: Sets the cache to overwrite existing entries. The
new results will be cached.

Expand Down
1 change: 1 addition & 0 deletions e2e/custom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a.moved.go
5 changes: 5 additions & 0 deletions e2e/custom/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package custom

//go:generate_input a.go
//go:generate_output a.moved.go
//go:generate bash script.sh
3 changes: 3 additions & 0 deletions e2e/custom/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cp -v a.go a.moved.go
19 changes: 19 additions & 0 deletions e2e/generated_hashes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
102 42dcf71179e23b112de0a76f610c563e *custom/a.moved.go
4762 03432f47ba5948d71bbdc83573d843aa *esc/static.go
12690 292ec370e175a885610da9a79821d6d2 *genny/gen-a.go
6717 ccab3d231701a1aec563075185aa8ba5 *go-bindata/static.go
84447 5e1a6e4c535ce8c01d9b2d44fdbbab34 *gqlgen/graph/generated/prelude.generated.go
188 d0921c0300cfdfb045a355d78c26d8b5 *gqlgen/graph/generated/resolver.go
6129 28e965bd6382fa1c087fd09b4c421d57 *gqlgen/graph/generated/root_.generated.go
24123 7568475e4de71322f9a7c1fbfc66d8d7 *gqlgen/graph/generated/schema.generated.go
1037 67a38c553526f58c547126326d10d838 *gqlgen/graph/generated/schema.resolvers.go
6800 c9cba1f8e5121d2c4e65522478fe9ab2 *gqlgen/graph/generated/schema2.generated.go
764 7fa6f277efb86b4a5006017f8aea447a *gqlgen/graph/generated/schema2.resolvers.go
237 f0c4b165baa306042455028d7badad99 *gqlgen/graph/model/models_gen.go
1208 38c7e8eba5087fa9e0b1a38d723869ac *mockgen/a.mock.go
1269 f5217ea75d9d28aaf4ac4bc65cb8d2ad *mockgen/b.mock.go
4117 6bfc15a24e5ca32e58de5171563cf1ac *protobuf/testdata/example/gender.pb.go
5266 4a0784ead1d20bf1778973d202f9238b *protobuf/testdata/person/person.pb.go
572 42e0312c59e136c58ec934981c5ce7f5 *stringer/a_string.go
560 c8afd55998c7f62a93ad6e800cf9c4c1 *stringer/c_string.go
585 89286bff4394353d22d8bb35fc0ff475 *stringer/stringer_out.go
51 changes: 51 additions & 0 deletions e2e/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")"

GENERATED_HASHES_FILE="generated_hashes.txt"
GO_GENERATE_ARGS="./..."

compare_hashes() {
computed_hashes_file=$(mktemp)
files=$(git ls-files . -o --ignored --exclude-standard)
for file in ${files}; do
hash=$(openssl dgst -r -md5 "${file}")
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
size=$(stat -c"%s" "${file}")
elif [[ "${OSTYPE}" == "darwin"* ]]; then
size=$(stat -f"%z" "${file}")
else
echo "Cannot compute file size: Unknown OS"
exit 1
fi

echo "${size} ${hash}" >> "${computed_hashes_file}"
done

if ! diff -ru "${GENERATED_HASHES_FILE}" "${computed_hashes_file}"; then
echo "Generated files are different. E2e failed."
exit 1
fi
}

# Use same modtimes for files
find . -type f -exec touch -m -t 202212311330 {} \;

echo "- Running original go generate..."
git clean -dfx . > /dev/null 2>&1
go generate "${GO_GENERATE_ARGS[@]}"
compare_hashes

echo "- Running go-generate-fast with ONLY generation..."
git clean -dfx . > /dev/null 2>&1
GO_GENERATE_FAST_RECACHE=1 ../bin/go-generate-fast "${GO_GENERATE_ARGS[@]}"
compare_hashes

echo "- Running go-generate-fast with ONLY cache..."
git clean -dfx . > /dev/null 2>&1
GO_GENERATE_FAST_FORCE_USE_CACHE=1 ../bin/go-generate-fast "${GO_GENERATE_ARGS[@]}"
compare_hashes


5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/cheekybits/genny v1.0.0
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golangci/golangci-lint v1.54.2
github.com/jessevdk/go-flags v1.5.0
github.com/mjibson/esc v0.2.0
github.com/spf13/viper v1.16.0
Expand All @@ -17,6 +18,7 @@ require (
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/tools v0.13.0
gotest.tools/gotestsum v1.11.0
)

require (
Expand Down Expand Up @@ -80,7 +82,6 @@ require (
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe // indirect
github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2 // indirect
github.com/golangci/golangci-lint v1.54.2 // indirect
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 // indirect
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca // indirect
github.com/golangci/misspell v0.4.1 // indirect
Expand Down Expand Up @@ -186,7 +187,6 @@ require (
github.com/ykadowak/zerologlint v0.1.3 // indirect
gitlab.com/bosi/decorder v0.4.0 // indirect
go.tmz.dev/musttag v0.7.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/mod v0.13.0 // indirect
Expand All @@ -198,7 +198,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/gotestsum v1.11.0 // indirect
honnef.co/go/tools v0.4.5 // indirect
mvdan.cc/gofumpt v0.5.0 // indirect
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
Expand Down
Loading
Loading