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

Use singular in plugin option #2

Merged
merged 4 commits into from
Mar 28, 2024
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
50 changes: 27 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@ name: Elixir CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

permissions:
contents: read

jobs:
build:

name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
otp: [24]
elixir: [1.12]

steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
with:
elixir-version: '1.12.3' # Define the elixir version [required]
otp-version: '24.1' # Define the OTP version [required]
- uses: actions/checkout@v3

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}} # Define the OTP version [required]

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: "3.17.3"
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: "3.17.3"

- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
21 changes: 10 additions & 11 deletions lib/mix/protobuf.generate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Mix.Tasks.Protobuf.Generate do
* `--generate-descriptors` - Includes raw descriptors in the generated modules
* `--one-file-per-module` - Changes the way files are generated into directories. This option creates a file for each generated Elixir module.
* `--include-documentation` - Controls visibility of documentation of the generated modules. Setting `true` will not have `@moduleoc false`
* `--plugins` - If you write services in protobuf, you can generate gRPC code by passing `--plugins=grpc`.
* `--plugin` - If you write services in protobuf, you can generate gRPC code by passing `--plugin=grpc`.

## Examples

Expand All @@ -29,7 +29,7 @@ defmodule Mix.Tasks.Protobuf.Generate do
--include-path=deps/googleapis \
--generate-descriptors=true \
--output-path=./lib \
--plugins=ProtobufGenerate.Plugins.GRPC
--plugin=ProtobufGenerate.Plugins.GRPC
google/api/annotations.proto google/api/http.proto helloworld.proto

"""
Expand All @@ -49,14 +49,14 @@ defmodule Mix.Tasks.Protobuf.Generate do
transform_module: :string,
include_docs: :boolean,
one_file_per_module: :boolean,
plugins: :keep
plugin: :keep
]

@impl Mix.Task
@spec run(any) :: any
def run(args) do
{opts, files} = OptionParser.parse!(args, strict: @switches)
{plugins, opts} = pop_values(opts, :plugins)
{plugins, opts} = pop_values(opts, :plugin)
{imports, opts} = pop_values(opts, :include_path)

transform_module =
Expand Down Expand Up @@ -104,10 +104,10 @@ defmodule Mix.Tasks.Protobuf.Generate do

files = normalize_import_paths(files, imports, [])

Google.Protobuf.Compiler.CodeGeneratorRequest.new(
%Google.Protobuf.Compiler.CodeGeneratorRequest{
file_to_generate: files,
proto_file: file_descriptors
)
}
end

defp generate(ctx, request) do
Expand All @@ -126,11 +126,10 @@ defmodule Mix.Tasks.Protobuf.Generate do
CodeGen.generate(ctx, desc, plugins)
end)

response =
Google.Protobuf.Compiler.CodeGeneratorResponse.new(
file: files,
supported_features: Protobuf.Protoc.CLI.supported_features()
)
response = %Google.Protobuf.Compiler.CodeGeneratorResponse{
file: files,
supported_features: Protobuf.Protoc.CLI.supported_features()
}

response
end
Expand Down
8 changes: 4 additions & 4 deletions lib/protobuf_generate/code_gen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ defmodule ProtobufGenerate.CodeGen do
for {mod_name, content} <- module_definitions do
file_name = Macro.underscore(mod_name) <> ".pb.ex"

Google.Protobuf.Compiler.CodeGeneratorResponse.File.new(
%Google.Protobuf.Compiler.CodeGeneratorResponse.File{
name: file_name,
content: content
)
}
end
end

Expand All @@ -71,10 +71,10 @@ defmodule ProtobufGenerate.CodeGen do
|> Util.format()

[
Google.Protobuf.Compiler.CodeGeneratorResponse.File.new(
%Google.Protobuf.Compiler.CodeGeneratorResponse.File{
name: file_name,
content: content
)
}
]
end

Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/protobuf.generate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ defmodule Mix.Tasks.Protobuf.GenerateTest do
"--include-path=#{tmp_dir}",
"--include-path=#{Mix.Project.deps_paths().google_protobuf}/src",
"--output-path=#{tmp_dir}",
"--plugins=ProtobufGenerate.Plugins.GRPC",
"--plugin=ProtobufGenerate.Plugins.GRPC",
proto_path
])

Expand Down
Loading