Skip to content

Commit 19b0f37

Browse files
authored
Merge pull request #29 from petermm/ci-add-check-formatting
CI: formatting check and test Elixir builds
2 parents 68c631b + 9831d5c commit 19b0f37

13 files changed

Lines changed: 152 additions & 79 deletions

File tree

.github/workflows/build-examples.yaml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,22 @@ on: ["push", "pull_request"]
1010

1111
jobs:
1212
build_erlang_examples:
13-
name: "Build Erlang Examples"
13+
name: "Build Erlang/Elixir Examples"
1414
runs-on: ubuntu-latest
1515

1616
strategy:
1717
fail-fast: true
1818

1919
steps:
20-
21-
- uses: erlef/setup-beam@v1
22-
with:
23-
otp-version: "24"
24-
elixir-version: "1.11"
25-
26-
- name: Checkout repo
27-
uses: actions/checkout@v2
28-
29-
# - name: "APT update"
30-
# run: sudo apt update -y
31-
32-
- name: "Build rebar3"
33-
run: |
34-
cd /tmp
35-
git clone https://github.com/erlang/rebar3.git
36-
cd rebar3
37-
./bootstrap
38-
39-
- name: "Build Erlang Example Programs"
40-
run: |
41-
PATH=/tmp/rebar3:$PATH ./build.sh
20+
- uses: erlef/setup-beam@v1
21+
with:
22+
otp-version: "26"
23+
elixir-version: "1.18"
24+
rebar3-version: "3.24.0"
25+
26+
- name: Checkout repo
27+
uses: actions/checkout@v6
28+
29+
- name: "Build Erlang/Elixir Example Programs"
30+
run: |
31+
./build.sh
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright 2022 Davide Bettio <davide@uninstall.it>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
5+
#
6+
7+
name: "Check formatting"
8+
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/**"
13+
- "**/*.ex"
14+
- "**/*.exs"
15+
- "**/*.erl"
16+
- "**/*.hrl"
17+
- "**/*.src"
18+
- "**/rebar.config"
19+
pull_request:
20+
paths:
21+
- ".github/workflows/**"
22+
- "**/*.ex"
23+
- "**/*.exs"
24+
- "**/*.erl"
25+
- "**/*.hrl"
26+
- "**/*.src"
27+
- "**/rebar.config"
28+
29+
concurrency:
30+
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }}
31+
cancel-in-progress: true
32+
33+
jobs:
34+
erlfmt-check:
35+
runs-on: ubuntu-24.04
36+
container: erlang:28
37+
steps:
38+
- uses: actions/checkout@v6
39+
- name: "Check formatting with Erlang fmt"
40+
run: |
41+
cd ..
42+
git clone --depth 1 -b v1.7.0 https://github.com/WhatsApp/erlfmt.git
43+
cd erlfmt
44+
rebar3 as release escriptize
45+
cd ../atomvm_examples
46+
find . -name *.erl | xargs ../erlfmt/_build/release/bin/erlfmt -c
47+
48+
mix-format-check:
49+
runs-on: ubuntu-24.04
50+
container: elixir:1.17.1
51+
steps:
52+
- uses: actions/checkout@v6
53+
- name: "Check formatting with Elixir mix format"
54+
run: |
55+
mix format --check-formatted "**/*.{ex,exs}"

.github/workflows/reuse-lint.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
test:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- name: REUSE Compliance Check
19-
uses: fsfe/reuse-action@v1
17+
- uses: actions/checkout@v6
18+
- name: REUSE Compliance Check
19+
uses: fsfe/reuse-action@v1

build.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ for i in ${ERLANG_EXAMPLES}; do
2626
cd $i
2727
rm -rf _build
2828
${REBAR} atomvm packbeam -l || exit 1
29-
${REBAR} as check fmt -c || exit 1
29+
cd ..
30+
done
31+
cd ..
32+
cd elixir
33+
ELIXIR_EXAMPLES="$(/bin/ls | grep -v README.md)"
34+
for i in ${ELIXIR_EXAMPLES}; do
35+
cd $i
36+
rm -rf _build
37+
mix deps.get && mix atomvm.packbeam || exit 1
38+
cd ..
39+
done
40+
cd ..
41+
cd demos
42+
DEMO_EXAMPLES="$(/bin/ls | grep -v README.md)"
43+
for i in ${DEMO_EXAMPLES}; do
44+
cd $i
45+
rm -rf _build
46+
if [ -f mix.exs ]; then
47+
mix deps.get && mix atomvm.packbeam || exit 1
48+
else
49+
${REBAR} atomvm packbeam -l || exit 1
50+
fi
3051
cd ..
3152
done

demos/lisp_faces/lib/main.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule Main do
4141
:gen_server.call(
4242
t,
4343
{:write,
44-
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ' running processes.\n'},
44+
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ~c" running processes.\n"},
4545
60000
4646
)
4747

demos/morse_server/src/morse_server.app.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
{applications, [
2626
kernel, stdlib
2727
]},
28-
{env,[]},
28+
{env, []},
2929
{modules, []},
3030
{licenses, ["Apache 2.0"]},
3131
{links, []}
32-
]}.
32+
]}.

demos/morse_server/src/morse_server.erl

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ start() ->
2727
Config = [
2828
{sta, [
2929
{ssid, esp:nvs_get_binary(atomvm, sta_ssid, <<"myssid">>)},
30-
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
30+
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
3131
{connected, fun() -> Self ! connected end},
3232
{got_ip, fun(IpInfo) -> Self ! {ok, IpInfo} end},
3333
{disconnected, fun() -> Self ! disconnected end}
@@ -41,18 +41,20 @@ start() ->
4141
end.
4242

4343
handle_req("GET", [], Conn) ->
44-
Body = <<"<html>
45-
<body>
46-
<h1>Morse Encoder</h1>
47-
<form method=\"post\">
48-
<p>Text: <input type=\"text\" name=\"text\"></p>
49-
<p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>
50-
<input type=\"submit\" value=\"Submit\">
51-
</form>
52-
</body>
53-
</html>">>,
44+
Body =
45+
<<
46+
"<html>\n"
47+
" <body>\n"
48+
" <h1>Morse Encoder</h1>\n"
49+
" <form method=\"post\">\n"
50+
" <p>Text: <input type=\"text\" name=\"text\"></p>\n"
51+
" <p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>\n"
52+
" <input type=\"submit\" value=\"Submit\">\n"
53+
" </form>\n"
54+
" </body>\n"
55+
" </html>"
56+
>>,
5457
http_server:reply(200, Body, Conn);
55-
5658
handle_req("POST", [], Conn) ->
5759
ParamsBody = proplists:get_value(body_chunk, Conn),
5860
Params = http_server:parse_query_string(ParamsBody),
@@ -65,14 +67,21 @@ handle_req("POST", [], Conn) ->
6567

6668
spawn(fun() -> blink_led(GPIONum, MorseText) end),
6769

68-
Body = [<<"<html>
69-
<body>
70-
<h1>Text Encoded</h1>">>,
71-
<<"<p>">>, MorseText, <<"</p1>
72-
</body>
73-
</html>">>],
70+
Body = [
71+
<<
72+
"<html>\n"
73+
" <body>\n"
74+
" <h1>Text Encoded</h1>"
75+
>>,
76+
<<"<p>">>,
77+
MorseText,
78+
<<
79+
"</p1>\n"
80+
" </body>\n"
81+
" </html>"
82+
>>
83+
],
7484
http_server:reply(200, Body, Conn);
75-
7685
handle_req(Method, Path, Conn) ->
7786
erlang:display(Conn),
7887
erlang:display({Method, Path}),
@@ -108,34 +117,29 @@ get_gpio() ->
108117
undefined ->
109118
GPIO = gpio:open(),
110119
GPIO;
111-
112120
GPIO ->
113121
GPIO
114122
end.
115123

116124
blink_led(undefined, _L) ->
117125
ok;
118-
119126
blink_led(GPIONum, L) ->
120127
GPIO = get_gpio(),
121128
gpio:set_direction(GPIO, GPIONum, output),
122129
blink_led(GPIO, GPIONum, L).
123130

124131
blink_led(_GPIO, _GPIONum, []) ->
125132
ok;
126-
127133
blink_led(GPIO, GPIONum, [H | T]) ->
128134
case H of
129135
$\s ->
130136
gpio:set_level(GPIO, GPIONum, low),
131137
timer:sleep(120);
132-
133138
$. ->
134139
gpio:set_level(GPIO, GPIONum, high),
135140
timer:sleep(120),
136141
gpio:set_level(GPIO, GPIONum, low),
137142
timer:sleep(120);
138-
139143
$- ->
140144
gpio:set_level(GPIO, GPIONum, high),
141145
timer:sleep(120 * 3),
@@ -149,7 +153,6 @@ morse_encode(L) ->
149153

150154
morse_encode([], Acc) ->
151155
Acc;
152-
153156
morse_encode([H | L], Acc) ->
154157
M = to_morse(string:to_upper(H)),
155158
morse_encode(L, Acc ++ M).
@@ -167,7 +170,7 @@ to_morse(C) ->
167170
$7 -> "--... ";
168171
$8 -> "---.. ";
169172
$9 -> "----. ";
170-
$A -> ".-" ;
173+
$A -> ".-";
171174
$B -> "-... ";
172175
$C -> "-.-. ";
173176
$D -> "-.. ";

elixir/Blinky/lib/Blinky.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Blinky do
3030
end
3131

3232
defp loop(pin, level) do
33-
:io.format('Setting pin ~p ~p~n', [pin, level])
33+
:io.format(~c"Setting pin ~p ~p~n", [pin, level])
3434
GPIO.digital_write(pin, level)
3535
Process.sleep(1000)
3636
loop(pin, toggle(level))
@@ -55,19 +55,25 @@ defmodule Blinky do
5555

5656
defp platform_gpio_setup() do
5757
case :atomvm.platform() do
58-
:esp32 -> GPIO.set_pin_mode(pin(), :output)
59-
:stm32 -> GPIO.set_pin_mode(pin(), :output)
58+
:esp32 ->
59+
GPIO.set_pin_mode(pin(), :output)
60+
61+
:stm32 ->
62+
GPIO.set_pin_mode(pin(), :output)
63+
6064
:pico ->
6165
case @pin do
62-
{:wl, 0} -> :ok
66+
{:wl, 0} ->
67+
:ok
68+
6369
pin ->
6470
GPIO.init(pin)
6571
GPIO.set_pin_mode(pin, :output)
6672
end
73+
6774
unsupported ->
6875
:io.format("Platform ~p is not supported.~n", [unsupported])
6976
:erlang.exit({:error, {:unsupported_platform, unsupported}})
7077
end
7178
end
72-
7379
end

elixir/EspRtcMemory/lib/esp_rtc_memory.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ defmodule EspRtcMemory do
8383
|> :esp.rtc_slow_set_binary()
8484
end
8585

86-
defp increment_state(%RebootState{count: count} = state) when is_integer(count) and count >= 0 do
86+
defp increment_state(%RebootState{count: count} = state)
87+
when is_integer(count) and count >= 0 do
8788
new_count = count + 1
8889
IO.puts("This device has restarted #{new_count} time(s).")
8990
%RebootState{state | count: new_count}
@@ -97,4 +98,3 @@ defmodule EspRtcMemory do
9798
defp verify_platform(:esp32), do: :ok
9899
defp verify_platform(platform), do: {:error, {:unsupported_platform, platform}}
99100
end
100-

elixir/EspRtcMemory/lib/reboot_state.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ defmodule RebootState do
2525

2626
defstruct count: 0
2727
end
28-

0 commit comments

Comments
 (0)