diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1562af8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: CI +on: + pull_request: + push: + branches: + - main +jobs: + test: + runs-on: ubuntu-20.04 + env: + MIX_ENV: test + strategy: + fail-fast: false + matrix: + include: + - pair: + elixir: "1.10" + otp: 21 + - pair: + elixir: "1.14" + otp: 25.1 + lint: lint + steps: + - uses: actions/checkout@v2 + + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.pair.otp}} + elixir-version: ${{matrix.pair.elixir}} + + - uses: actions/cache@v2 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + - run: mix deps.get + - run: mix format --check-formatted + if: ${{ matrix.lint }} + + - run: mix deps.unlock --check-unused + if: ${{ matrix.lint }} + + - run: mix deps.compile + + - run: mix compile --warnings-as-errors + if: ${{ matrix.lint }} + + - run: mix test + if: ${{ ! matrix.lint }} + + - run: mix test --warnings-as-errors + if: ${{ matrix.lint }} diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..4ab3b2e --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.14.0-otp-25 +erlang 25.1 diff --git a/lib/proto_validator/protoc/generator.ex b/lib/proto_validator/protoc/generator.ex index 6a00ea2..8cd676f 100644 --- a/lib/proto_validator/protoc/generator.ex +++ b/lib/proto_validator/protoc/generator.ex @@ -106,7 +106,8 @@ defmodule ProtoValidator.Protoc.Generator do get_type_name(type, type_name, type_mappings) end - defp get_type_name(type, nil, _type_mappings), do: ":#{ProtoValidator.Protoc.Utils.from_enum(type)}" + defp get_type_name(type, nil, _type_mappings), + do: ":#{ProtoValidator.Protoc.Utils.from_enum(type)}" defp get_type_name(_type, type_name, type_mappings) do <> = type_name diff --git a/lib/validate.pb.ex b/lib/validate.pb.ex index 3aeedbc..ca473d3 100644 --- a/lib/validate.pb.ex +++ b/lib/validate.pb.ex @@ -61,4 +61,4 @@ defmodule Validate.PbExtension do use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto2 extend Google.Protobuf.FieldOptions, :rules, 1071, optional: true, type: Validate.FieldRules -end \ No newline at end of file +end diff --git a/lib/validator.ex b/lib/validator.ex index 2971958..4a7587a 100644 --- a/lib/validator.ex +++ b/lib/validator.ex @@ -1,5 +1,5 @@ defmodule ProtoValidator.Validator do - @validator Application.get_env(:proto_validator, :validator, :vex) + @validator Application.compile_env(:proto_validator, :validator, :vex) import ProtoValidator.Utils, only: [pipe_validates: 2] diff --git a/mix.lock b/mix.lock index 6af8e1d..7e45b83 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,4 @@ %{ - "google_protobuf": {:git, "https://github.com/protocolbuffers/protobuf.git", "fcd26beabe034142c0f1a693f7cb6e1517b03de3", [branch: "main", submodules: true]}, - "google_protos": {:hex, :google_protos, "0.2.0", "7c6280e288d7f04a58448444b12d937ddc8cc40dc3d1e4f61c69936ef71d4739", [:mix], [{:protobuf, "~> 0.8", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "5de24802e89867cea544d0ee8cbd36f6c9c1ebd4a9fcc55276d6eeadeedcc1f5"}, "protobuf": {:hex, :protobuf, "0.11.0", "58d5531abadea3f71135e97bd214da53b21adcdb5b1420aee63f4be8173ec927", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "30ad9a867a5c5a0616cac9765c4d2c2b7b0030fa81ea6d0c14c2eb5affb6ac52"}, "vex": {:hex, :vex, "0.9.0", "613ea5eb3055662e7178b83e25b2df0975f68c3d8bb67c1645f0573e1a78d606", [:mix], [], "hexpm", "c69fff44d5c8aa3f1faee71bba1dcab05dd36364c5a629df8bb11751240c857f"}, } diff --git a/test/proto_gen/example.pb.ex b/test/proto_gen/example.pb.ex index d0b20be..a2c0353 100644 --- a/test/proto_gen/example.pb.ex +++ b/test/proto_gen/example.pb.ex @@ -35,4 +35,4 @@ defmodule Examplepb.Foo do use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3 field :int32, 1, type: :int32, deprecated: false -end \ No newline at end of file +end diff --git a/test/proto_gen/example.pb.validate.ex b/test/proto_gen/example.pb.validate.ex index 08304ac..d5a0ea1 100644 --- a/test/proto_gen/example.pb.validate.ex +++ b/test/proto_gen/example.pb.validate.ex @@ -25,4 +25,4 @@ defmodule ProtoValidator.Gen.Examplepb.Foo do use ProtoValidator, entity: Examplepb.Foo validate(:int32, type: :int32, int32: [gte: 0, lte: 10]) -end \ No newline at end of file +end