forked from saleyn/typedstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmix.exs
More file actions
149 lines (134 loc) · 3.94 KB
/
mix.exs
File metadata and controls
149 lines (134 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
defmodule TypedStruct.MixProject do
use Mix.Project
#@version "0.5.1"
@repo_url "https://github.com/saleyn/typedstruct"
def project do
version = vsn()
[
app: :typedstruct,
version: version,
elixir: "~> 1.13",
start_permanent: false,
deps: deps(),
elixirc_paths: elixirc_paths(),
# Tools
dialyzer: dialyzer(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: cli_env(),
# Docs
name: "TypedStruct",
docs: [
extras: [
"README.md": [title: "Overview"],
"CHANGELOG.md": [title: "Changelog"],
"CONTRIBUTING.md": [title: "Contributing"],
"LICENSE.md": [title: "License"]
],
main: "readme",
source_url: @repo_url,
source_ref: "v#{version}",
formatters: ["html"]
],
# Package
package: package(),
description:
"A library for defining structs with a type without writing " <>
"boilerplate code."
]
end
defp deps do
[
# Development and test dependencies
{:ex_check, "~> 0.14.0", only: :dev, runtime: false},
{:credo, "~> 1.0", only: :dev, runtime: false},
{:dialyxir, "~> 1.0", only: :dev, runtime: false},
{:excoveralls, ">= 0.0.0", only: :test, runtime: false},
{:mix_test_watch, ">= 0.0.0", only: :test, runtime: false},
{:ex_unit_notifier, ">= 0.0.0", only: :test, runtime: false},
# Project dependencies
# Documentation dependencies
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end
defp elixirc_paths(), do: (Mix.env() == :test && ["lib", "test"]) || ["lib"]
# Dialyzer configuration
defp dialyzer do
[
# Use a custom PLT directory for continuous integration caching.
plt_core_path: System.get_env("PLT_DIR"),
plt_file: plt_file(),
plt_add_deps: :app_tree,
flags: [
:unmatched_returns,
:error_handling
],
ignore_warnings: ".dialyzer_ignore"
]
end
defp plt_file do
case System.get_env("PLT_DIR") do
nil -> nil
plt_dir -> {:no_warn, Path.join(plt_dir, "typedstruct.plt")}
end
end
defp cli_env do
[
# Run mix test.watch in `:test` env.
"test.watch": :test,
# Always run Coveralls Mix tasks in `:test` env.
coveralls: :test,
"coveralls.detail": :test,
"coveralls.html": :test,
# Use a custom env for docs.
docs: :docs
]
end
defp package do
[
licenses: ["MIT"],
links: %{
"Changelog" => "https://hexdocs.pm/typedstruct/changelog.html",
"GitHub" => @repo_url
}
]
end
# Obtain the version of this library
# If it's loaded as a dependency from Hex.pm, then the project contains
# ".hex" file, which contains the version. If it's loaded from git, then
# we can use "git describe" command to format the version with a revision.
# Otherwise use a verbatim version from the attribute.
#
# NOTE: with this method of calculating the version number, you need to make
# sure that in the Github action the checkout includes:
# ```
# - name: Checkout the repository
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# ```
# This ensures that the git history is checked out with tags so that
# `git describe --tags` returns the proper version number.
defp vsn() do
hex_spec = Mix.Project.deps_path() |> Path.dirname() |> Path.join(".hex")
version =
if File.exists?(hex_spec) do
hex_spec
|> File.read!()
|> :erlang.binary_to_term()
|> elem(1)
|> Map.get(:version)
else
with {ver, 0} <-
System.cmd("git", ~w(describe --always --tags),
stderr_to_stdout: true
) do
ver
|> String.trim()
|> String.replace(~r/^v/, "")
else _ ->
raise "Cannot determine application version!"
end
end
version
end
end