Skip to content

Commit 4aadd37

Browse files
committed
feat(elixir): init elixir project
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
1 parent 0655b43 commit 4aadd37

File tree

18 files changed

+336
-3
lines changed

18 files changed

+336
-3
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.7'
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 install --always-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.7'
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.7'
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ Source: https://github.com/edgehog-device-manager/edgehog-device-forwarder-proto
55
Files: out/* rust/Cargo.lock rust/edgehog-device-forwarder-proto/src/proto.rs
66
Copyright: 2023 SECO Mind Srl
77
License: Apache-2.0
8+
9+
Files: elixir/edgehog_device_forwarder_proto/lib/edgehog_device_forwarder_proto/**/*.ex
10+
Copyright: 2023 SECO Mind Srl
11+
License: Apache-2.0

Makefile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,36 @@ CANONICAL_CURDIR = $(realpath $(CURDIR))
2727

2828
PROTO_DIR = $(CANONICAL_CURDIR)/proto
2929
RUST_LANG_DIR = $(CANONICAL_CURDIR)/rust
30+
ELIXIR_LANG_DIR = $(CANONICAL_CURDIR)/elixir
31+
ELIXIR_LANG_LIB=$(ELIXIR_LANG_DIR)/edgehog_device_forwarder_proto/lib/edgehog_device_forwarder_proto
3032

3133
BASE_DIR := $(CANONICAL_O)
3234
$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
3335

3436
BUILD_DIR := $(BASE_DIR)/build
3537
RUST_BUILD_DIR := $(BUILD_DIR)/rust
38+
ELIXIR_BUILD_DIR := $(BUILD_DIR)/elixir
3639

37-
FILES=$(wildcard proto/edgehog/device/forwarder/*.proto)
40+
FILES=$(wildcard $(PROTO_DIR)/edgehog/device/forwarder/*.proto)
3841

3942
PROTOC_CHECK_SCRIPT=$(CANONICAL_CURDIR)/scripts/protoc_check.sh
43+
ELIXIR_DEPS_CHECK_SCRIPT=$(CANONICAL_CURDIR)/scripts/elixir_deps_check.sh
4044

4145
RUST_LANG=$(RUST_BUILD_DIR)/proto.rs
4246
RUST_FILES=$(shell find "$(RUST_LANG_DIR)/rust-codegen" -type f -regex '.*(rs|Cargo.toml|Cargo.lock)$$') \
4347
$(RUST_LANG_DIR)/Cargo.toml $(RUST_LANG_DIR)/Cargo.lock
4448

49+
ELIXIR_LANG=$(ELIXIR_BUILD_DIR)/edgehog/device/forwarder/http.pb.ex \
50+
$(ELIXIR_BUILD_DIR)/edgehog/device/forwarder/ws.pb.ex \
51+
$(ELIXIR_BUILD_DIR)/edgehog/device/forwarder/message.pb.ex
52+
ELIXIR_FILES="$(ELIXIR_LANG_LIB)/edgehog/device/forwarder/"{http,ws,message}.pb.ex
53+
4554
# This is our default rule, so must come first
4655
.PHONY: all
47-
all: rust
56+
all: rust elixir
4857

4958
.PHONY: install
50-
install: rust-install
59+
install: rust-install elixir-install
5160

5261
.PHONY: clean
5362
clean:
@@ -71,6 +80,30 @@ rust-install: rust
7180
rust-dirclean:
7281
rm -rf $(RUST_BUILD_DIR)
7382

83+
$(ELIXIR_LANG) &: $(FILES)
84+
mkdir -p $(ELIXIR_BUILD_DIR)
85+
protoc \
86+
--elixir_out=$(ELIXIR_BUILD_DIR) \
87+
--elixir_opt=package_prefix=EdgehogDeviceForwarderProto \
88+
--proto_path=$(PROTO_DIR) \
89+
$(FILES)
90+
mix format $(ELIXIR_LANG)
91+
92+
elixir-dependencies-check: $(ELIXIR_DEPS_CHECK_SCRIPT)
93+
$(SHELL) $(ELIXIR_DEPS_CHECK_SCRIPT)
94+
95+
.PHONY: elixir
96+
elixir: protoc-check elixir-dependencies-check $(ELIXIR_LANG)
97+
98+
.PHONY: elixir-install
99+
elixir-install: elixir
100+
mkdir -p "$(ELIXIR_LANG_LIB)/edgehog/device/forwarder/"
101+
install -m 644 $(ELIXIR_LANG) "$(ELIXIR_LANG_LIB)/edgehog/device/forwarder/"
102+
103+
.PHONY: elixir-dirclean
104+
elixir-dirclean:
105+
rm -rf $(ELIXIR_BUILD_DIR)
106+
74107
.PHONY: help
75108
help:
76109
@echo 'Cleaning:'
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
defmodule EdgehogDeviceForwarderProto do
5+
end
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, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
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, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
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, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
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, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
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, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
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

0 commit comments

Comments
 (0)