Skip to content

Commit

Permalink
initial github action
Browse files Browse the repository at this point in the history
  • Loading branch information
shortishly committed Jul 23, 2023
1 parent 765fcc1 commit 1103173
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
28 changes: 28 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: BEAM Coverdata to JSON
description: Easily convert BEAM coverdata into a JSON object
branding:
icon: 'download-cloud'
color: 'gray-dark'
inputs:
input:
description: Input coverdata location
default: _site/cover
otp-version:
description: OTP Version
default: 26
output:
description: coverage JSON filename
default: _site/cover/coverage.json
runs:
using: composite
steps:
- uses: erlef/setup-beam@v1
with:
otp-version: ${{inputs.otp-version}}
- run: |
make -C $GITHUB_ACTION_PATH escript
shell: bash
- run: |
$GITHUB_ACTION_PATH/coverdata --input ${{inputs.input}} --output ${{inputs.output}}
shell: bash
31 changes: 17 additions & 14 deletions src/coverdata.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ main(Args) ->
?FUNCTION_NAME(
Args,
#{"format" => "json",
"input" => begin
{ok, CWD} = file:get_cwd(),
CWD
end,
"precision" => "5",
"level" => "module" }).

Expand All @@ -47,29 +51,28 @@ main([], Arg) ->


process(#{"input" := Input, "output" := Output} = Arg) ->
ok = cover:import(Input),
ok = file:write_file(Output, format_report(Arg));

process(#{"output" := Output} = Arg) ->
case filelib:is_dir(Input) of
true ->
ok = import_dir(Input);
false ->
ok = cover:import(Input)
end,
ok = file:write_file(Output, format_report(Arg)).

{ok, CWD} = file:get_cwd(),

import_dir(Directory) ->
true = lists:all(
fun
(Result) ->
Result == ok
end,
[cover:import(CoverData)
|| CoverData
<- lists:map(
fun
(Relative) ->
filename:join(CWD, Relative)
end,
filelib:wildcard("**/*.coverdata"))
-- cover:imported()]),

ok = file:write_file(Output, format_report(Arg)).
<- filelib:wildcard(
filename:join(
Directory,
"**/*.coverdata"))]),
ok.


-spec format_report(#{}) -> iodata().
Expand Down

0 comments on commit 1103173

Please sign in to comment.