Skip to content

Commit 92506fc

Browse files
committed
feat(elixir): init elixir project
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
1 parent db59885 commit 92506fc

File tree

17 files changed

+304
-2
lines changed

17 files changed

+304
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ jobs:
2424
rust-check:
2525
needs: [codegen-check]
2626
uses: ./.github/workflows/rust-check.yaml
27+
elixir-check:
28+
needs: [codegen-check]
29+
uses: ./.github/workflows/elixir-check.yaml

.github/workflows/codegen-check.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ jobs:
2626
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
2727
- name: Install rust toolchain
2828
uses: dtolnay/rust-toolchain@stable
29+
- uses: erlef/setup-beam@v1
30+
with:
31+
otp-version: '26'
32+
elixir-version: '1.15.6'
33+
- name: Install elixir protobuf compiler
34+
run: |
35+
mix escript.install hex protobuf --force
36+
echo "$HOME/.mix/escripts" >> "$GITHUB_PATH"
2937
- name: Generate code
3038
run: make
3139
- name: Check diff in generated code
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
permissions:
5+
contents: read
6+
on:
7+
workflow_call:
8+
9+
defaults:
10+
run:
11+
working-directory: elixir/edgehog_device_forwarder_proto
12+
jobs:
13+
format:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: erlef/setup-beam@v1
18+
with:
19+
otp-version: '26'
20+
elixir-version: '1.15.6'
21+
- name: Fetch dependencies
22+
run: mix do deps.get --only test, deps.compile
23+
- name: Check formatting
24+
run: mix format --check-formatted
25+
tests:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: erlef/setup-beam@v1
30+
with:
31+
otp-version: '26'
32+
elixir-version: '1.15.6'
33+
- name: Fetch dependencies
34+
run: mix do deps.get --only test, deps.compile
35+
- name: Run tests
36+
run: mix test

.reuse/dep5

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Upstream-Name: edgehog-device-forwarder-proto
33
Source: https://github.com/edgehog-device-manager/edgehog-device-forwarder-proto
44

5-
Files: out/* rust/Cargo.lock rust/edgehog-device-forwarder-proto/src/proto.rs
5+
Files: rust/Cargo.lock rust/edgehog-device-forwarder-proto/src/proto.rs
6+
Copyright: 2023 SECO Mind Srl
7+
License: Apache-2.0
8+
9+
Files: elixir/edgehog_device_forwarder_proto/lib/edgehog/device/forwarder/*.ex
610
Copyright: 2023 SECO Mind Srl
711
License: Apache-2.0

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,28 @@ export PROTO_FILES
1212
RUST_OUT_DIR=rust/edgehog-device-forwarder-proto/src
1313
RUST_OUTPUT=$(RUST_OUT_DIR)/proto.rs
1414

15-
all: check $(RUST_OUTPUT)
15+
# Elixir
16+
ELIXIR_PROJECT=EdgehogDeviceForwarderProto
17+
ELIXIR_PROJECT_DIR=elixir/edgehog_device_forwarder_proto
18+
ELIXIR_OUT_DIR=$(ELIXIR_PROJECT_DIR)/lib
19+
ELIXIR_OUTPUT=$(ELIXIR_OUT_DIR)/edgehog/device/forwarder/message.pb.ex \
20+
$(ELIXIR_OUT_DIR)/edgehog/device/forwarder/http.pb.ex \
21+
$(ELIXIR_OUT_DIR)/edgehog/device/forwarder/ws.pb.ex
22+
23+
all: check $(RUST_OUTPUT) $(ELIXIR_OUTPUT)
1624

1725
check:
1826
./scripts/check-dependencies.sh
1927

2028
$(RUST_OUTPUT): $(PROTO_FILES)
2129
cargo run --manifest-path rust/Cargo.toml -p rust-codegen -- -w proto -o $(RUST_OUT_DIR)
2230
mv $(RUST_OUT_DIR)/edgehog.device.forwarder.rs $(RUST_OUTPUT)
31+
32+
$(ELIXIR_OUTPUT) &: $(PROTO_FILES)
33+
mkdir -p $(ELIXIR_OUT_DIR)
34+
protoc \
35+
--elixir_out=$(ELIXIR_OUT_DIR) \
36+
--elixir_opt=package_prefix=$(ELIXIR_PROJECT) \
37+
--proto_path=$(PROTO_DIR) \
38+
$(PROTO_FILES)
39+
cd $(ELIXIR_PROJECT_DIR) && mix format lib/edgehog/device/forwarder/{message,http,ws}.pb.ex
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[
5+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
6+
import_deps: [:protobuf]
7+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# The directory Mix will write compiled artifacts to.
5+
/_build/
6+
7+
# If you run "mix test --cover", coverage assets end up here.
8+
/cover/
9+
10+
# The directory Mix downloads your dependencies sources to.
11+
/deps/
12+
13+
# Where third-party dependencies like ExDoc output generated docs.
14+
/doc/
15+
16+
# Ignore .fetch files in case you like to edit your project deps locally.
17+
/.fetch
18+
19+
# If the VM crashes, it generates a dump, let's ignore it too.
20+
erl_crash.dump
21+
22+
# Also ignore archive artifacts (built via "mix archive.build").
23+
*.ez
24+
25+
# Ignore package tarball (built via "mix hex.build").
26+
edgehog_device_forwarder_proto-*.tar
27+
28+
# Temporary files, for example, from tests.
29+
/tmp/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Copyright 2023 SECO Mind Srl
3+
SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
# EdgehogDeviceForwarderProto
7+
8+
**TODO: Add description**
9+
10+
## Installation
11+
12+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
13+
by adding `edgehog_device_forwarder_proto` to your list of dependencies in `mix.exs`:
14+
15+
```elixir
16+
def deps do
17+
[
18+
{:edgehog_device_forwarder_proto, "~> 0.1.0"}
19+
]
20+
end
21+
```
22+
23+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
24+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
25+
be found at <https://hexdocs.pm/edgehog_device_forwarder_proto>.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request.HeadersEntry do
2+
@moduledoc false
3+
4+
use Protobuf, map: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
5+
6+
field(:key, 1, type: :string)
7+
field(:value, 2, type: :string)
8+
end
9+
10+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request do
11+
@moduledoc false
12+
13+
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
14+
15+
field(:path, 1, type: :string)
16+
field(:method, 2, type: :string)
17+
field(:query_string, 3, type: :string, json_name: "queryString")
18+
19+
field(:headers, 4,
20+
repeated: true,
21+
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request.HeadersEntry,
22+
map: true
23+
)
24+
25+
field(:body, 5, type: :bytes)
26+
field(:port, 6, type: :uint32)
27+
end
28+
29+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response.HeadersEntry do
30+
@moduledoc false
31+
32+
use Protobuf, map: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
33+
34+
field(:key, 1, type: :string)
35+
field(:value, 2, type: :string)
36+
end
37+
38+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response do
39+
@moduledoc false
40+
41+
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
42+
43+
field(:status_code, 1, type: :uint32, json_name: "statusCode")
44+
45+
field(:headers, 2,
46+
repeated: true,
47+
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response.HeadersEntry,
48+
map: true
49+
)
50+
51+
field(:body, 3, type: :bytes)
52+
end
53+
54+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http do
55+
@moduledoc false
56+
57+
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
58+
59+
oneof(:message, 0)
60+
61+
field(:request_id, 1, type: :bytes, json_name: "requestId")
62+
63+
field(:request, 2,
64+
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Request,
65+
oneof: 0
66+
)
67+
68+
field(:response, 3,
69+
type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http.Response,
70+
oneof: 0
71+
)
72+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Message do
2+
@moduledoc false
3+
4+
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
5+
6+
oneof(:protocol, 0)
7+
8+
field(:http, 1, type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.Http, oneof: 0)
9+
field(:ws, 2, type: EdgehogDeviceForwarderProto.Edgehog.Device.Forwarder.WebSocket, oneof: 0)
10+
end

0 commit comments

Comments
 (0)