Skip to content

Commit 40ecbdc

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

File tree

15 files changed

+228
-4
lines changed

15 files changed

+228
-4
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 all
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: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# we want bash as shell
77
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
8-
else if [ -x BASH_PATH="$(command -v bash)" ]; then echo $$BASH_PATH; \
8+
else if [ -x BASH_PATH="$$(command -v bash)" ]; then echo $$BASH_PATH; \
99
else echo sh; fi; fi)
1010

1111
# Set O variable if not already done on the command line;
@@ -27,24 +27,33 @@ 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: protoc-check $(RUST_LANG) $(ELIXIR_LANG)
4857

4958
.PHONY: install
5059
install: rust-install
@@ -71,6 +80,29 @@ 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+
91+
elixir-dependencies-check: $(ELIXIR_DEPS_CHECK_SCRIPT)
92+
$(SHELL) $(ELIXIR_DEPS_CHECK_SCRIPT)
93+
94+
.PHONY: elixir
95+
elixir: protoc-check elixir-dependencies-check $(ELIXIR_LANG)
96+
97+
.PHONY: elixir-install
98+
elixir-install: elixir
99+
mkdir -p "$(ELIXIR_LANG_LIB)/edgehog/device/forwarder/"
100+
install -m 644 "$(ELIXIR_BUILD_DIR)/edgehog/device/forwarder/"{http,ws,message}.pb.ex "$(ELIXIR_LANG_LIB)/edgehog/device/forwarder/"
101+
102+
.PHONY: elixir-dirclean
103+
elixir-dirclean:
104+
rm -rf $(ELIXIR_BUILD_DIR)
105+
74106
.PHONY: help
75107
help:
76108
@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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
defmodule EdgehogDeviceForwarderProto.MixProject do
5+
use Mix.Project
6+
7+
def project do
8+
[
9+
app: :edgehog_device_forwarder_proto,
10+
version: "0.0.1",
11+
elixir: "~> 1.15",
12+
start_permanent: Mix.env() == :prod,
13+
deps: deps()
14+
]
15+
end
16+
17+
def application do
18+
[
19+
extra_applications: [:logger]
20+
]
21+
end
22+
23+
defp deps do
24+
[
25+
{:protobuf, "~> 0.12"}
26+
]
27+
end
28+
end

0 commit comments

Comments
 (0)