Skip to content

Commit

Permalink
Merge branch 'master' into ignore-dev-and-umbrella
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergő Papp-Szentannai committed May 25, 2021
2 parents 93c5e6b + c4dba4d commit 981f475
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"]
]
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- pair:
elixir: 1.7.4
otp: 21.3.8.17
- pair:
elixir: 1.12.0
otp: 24.0.1
lint: lint

steps:
- uses: actions/checkout@v2

- name: Setup elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.pair.otp}}
elixir-version: ${{matrix.pair.elixir}}

- name: Install Dependencies
run: mix deps.get

- run: mix format --check-formatted
if: ${{ matrix.lint }}

- run: mix test
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish

on:
push:
tags:
- v*

jobs:
publish:
runs-on: ubuntu-latest
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-elixir@v1
with:
otp-version: 22.x
elixir-version: 1.10.x
- run: mix deps.get
- run: mix hex.publish --yes
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kudos

[![Build Status](https://travis-ci.org/semlabs/kudos.svg?branch=master)](https://travis-ci.org/semlabs/kudos)
![Elixir CI](https://github.com/dschniepp/kudos/workflows/Elixir%20CI/badge.svg)

Kudos generates a licenses file in the root dir with the licenses of all dependencies.

Expand All @@ -9,7 +9,7 @@ Kudos generates a licenses file in the root dir with the licenses of all depende
```elixir
def deps do
[
{:kudos, "~> 0.1.0"}
{:kudos, "~> 0.2.0"}
]
end
```
Expand Down
12 changes: 9 additions & 3 deletions lib/kudos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Kudos do
"""
def generate do
load_deps_meta_data()
|> Enum.reduce(header(), fn(meta_data, resp) ->
|> Enum.reduce(header(), fn meta_data, resp ->
resp <> format(meta_data)
end)
|> String.trim()
Expand Down Expand Up @@ -55,24 +55,28 @@ defmodule Kudos do
defp checksum(value) when is_list(value) do
value[:branch]
end

defp checksum(value) do
value
end

defp maintainers(values) when is_nil(values) do
""
end

defp maintainers(values) when is_map(values) do
Map.to_list(values)
|> maintainers()
end

defp maintainers(values) when is_list(values) do
Enum.join(values, ", ")
end

defp links(values) when is_nil(values) do
""
end

defp links(values) when is_map(values) do
Map.to_list(values)
|> Enum.map(&prepare_link(&1))
Expand All @@ -82,13 +86,14 @@ defmodule Kudos do
defp prepare_link(value) when is_tuple(value) do
"[#{elem(value, 0)}](#{elem(value, 1)})"
end

defp prepare_link({key, value}) do
"[#{key}](#{value})"
end

defp load_deps_meta_data() do
Mix.Dep.load_on_environment([])
|> Enum.map(fn(dep) ->
|> Enum.map(fn dep ->
Mix.Dep.in_dependency(dep, fn _ ->
case is_umbrella?(dep) do
true -> :umbrella
Expand Down Expand Up @@ -136,13 +141,14 @@ defmodule Kudos do
end

defp get_license_file_content(path) do
File.ls!(path) -- (File.ls!(path) -- @license_file_names)
(File.ls!(path) -- File.ls!(path) -- @license_file_names)
|> read_license_file(path)
end

defp read_license_file([], _path) do
"Full license text not found in dependency source."
end

defp read_license_file([first_file_name | _], path) do
Path.join(path, first_file_name)
|> File.read!()
Expand Down
50 changes: 25 additions & 25 deletions lib/mix/tasks/kudos.generate.ex
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
defmodule Mix.Tasks.Kudos.Generate do
use Mix.Task

@shortdoc "Generates a licenses file"
@recursive false
use Mix.Task

def run(args \\ []) do
IO.puts("Generating Licenses file...")
@shortdoc "Generates a licenses file"
@recursive false

resp =
Kudos.generate()
|> handle_licenses(dry_run?(args))
def run(args \\ []) do
IO.puts("Generating Licenses file...")

case resp do
:ok -> IO.puts("Done!")
_ -> IO.puts("Failed!")
end
end
resp =
Kudos.generate()
|> handle_licenses(dry_run?(args))

defp handle_licenses(content, true) do
IO.puts(content)
:ok
case resp do
:ok -> IO.puts("Done!")
_ -> IO.puts("Failed!")
end
end

defp handle_licenses(content, false) do
File.write("licenses.md", content)
end

defp dry_run?(args) do
Enum.member?(args, "--dry-run")
end
end
defp handle_licenses(content, true) do
IO.puts(content)
:ok
end

defp handle_licenses(content, false) do
File.write("licenses.md", content)
end

defp dry_run?(args) do
Enum.member?(args, "--dry-run")
end
end
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ defmodule Kudos.Mixfile do
def project do
[
app: :kudos,
version: "0.1.1",
elixir: "~> 1.8",
start_permanent: Mix.env == :prod,
version: "0.2.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
description: description(),
package: package(),
deps: deps(),
name: "Kudos",
source_url: "https://github.com/semlabs/kudos"
source_url: "https://github.com/dschniepp/kudos"
]
end

Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule Kudos.Mixfile do
files: ["lib", "mix.exs", "README*", "LICENSE*"],
maintainers: ["Daniel Schniepp"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/semlabs/kudos"}
links: %{"GitHub" => "https://github.com/dschniepp/kudos"}
]
end
end

0 comments on commit 981f475

Please sign in to comment.