Skip to content

Commit 38805c8

Browse files
authored
Merge pull request #16 from ausimian/feature/build-conventions
Adopt build conventions
2 parents 9b1822e + b70b0e8 commit 38805c8

12 files changed

Lines changed: 511 additions & 26 deletions

File tree

.credo.exs

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs: [
11+
%{
12+
#
13+
# Run any config using `mix credo -C <name>`. If no config name is given
14+
# "default" is used.
15+
#
16+
name: "default",
17+
#
18+
# These are the files included in the analysis:
19+
files: %{
20+
#
21+
# You can give explicit globs or simply directories.
22+
# In the latter case `**/*.{ex,exs}` will be used.
23+
#
24+
included: [
25+
"lib/",
26+
"src/",
27+
"test/",
28+
"web/",
29+
"apps/*/lib/",
30+
"apps/*/src/",
31+
"apps/*/test/",
32+
"apps/*/web/"
33+
],
34+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
35+
},
36+
#
37+
# Load and configure plugins here:
38+
#
39+
plugins: [],
40+
#
41+
# If you create your own checks, you must specify the source files for
42+
# them here, so they can be loaded by Credo before running the analysis.
43+
#
44+
requires: [],
45+
#
46+
# If you want to enforce a style guide and need a more traditional linting
47+
# experience, you can change `strict` to `true` below:
48+
#
49+
strict: false,
50+
#
51+
# To modify the timeout for parsing files, change this value:
52+
#
53+
parse_timeout: 5000,
54+
#
55+
# If you want to use uncolored output by default, you can change `color`
56+
# to `false` below:
57+
#
58+
color: true,
59+
#
60+
# You can customize the parameters of any check by adding a second element
61+
# to the tuple.
62+
#
63+
# To disable a check put `false` as second element:
64+
#
65+
# {Credo.Check.Design.DuplicatedCode, false}
66+
#
67+
checks: %{
68+
enabled: [
69+
#
70+
## Consistency Checks
71+
#
72+
{Credo.Check.Consistency.ExceptionNames, []},
73+
{Credo.Check.Consistency.LineEndings, []},
74+
{Credo.Check.Consistency.ParameterPatternMatching, []},
75+
{Credo.Check.Consistency.SpaceAroundOperators, []},
76+
{Credo.Check.Consistency.SpaceInParentheses, []},
77+
{Credo.Check.Consistency.TabsOrSpaces, []},
78+
79+
#
80+
## Design Checks
81+
#
82+
# You can customize the priority of any check
83+
# Priority values are: `low, normal, high, higher`
84+
#
85+
{Credo.Check.Design.AliasUsage,
86+
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
87+
{Credo.Check.Design.TagFIXME, []},
88+
# You can also customize the exit_status of each check.
89+
# If you don't want TODO comments to cause `mix credo` to fail, just
90+
# set this value to 0 (zero).
91+
#
92+
{Credo.Check.Design.TagTODO, [exit_status: 2]},
93+
94+
#
95+
## Readability Checks
96+
#
97+
{Credo.Check.Readability.AliasOrder, []},
98+
{Credo.Check.Readability.FunctionNames, []},
99+
{Credo.Check.Readability.LargeNumbers, []},
100+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
101+
{Credo.Check.Readability.ModuleAttributeNames, []},
102+
{Credo.Check.Readability.ModuleDoc, []},
103+
{Credo.Check.Readability.ModuleNames, []},
104+
{Credo.Check.Readability.ParenthesesInCondition, []},
105+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
106+
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
107+
{Credo.Check.Readability.PredicateFunctionNames, []},
108+
{Credo.Check.Readability.PreferImplicitTry, []},
109+
{Credo.Check.Readability.RedundantBlankLines, []},
110+
{Credo.Check.Readability.Semicolons, []},
111+
{Credo.Check.Readability.SpaceAfterCommas, []},
112+
{Credo.Check.Readability.StringSigils, []},
113+
{Credo.Check.Readability.TrailingBlankLine, []},
114+
{Credo.Check.Readability.TrailingWhiteSpace, []},
115+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
116+
{Credo.Check.Readability.VariableNames, []},
117+
{Credo.Check.Readability.WithSingleClause, []},
118+
119+
#
120+
## Refactoring Opportunities
121+
#
122+
{Credo.Check.Refactor.Apply, []},
123+
{Credo.Check.Refactor.CondStatements, []},
124+
{Credo.Check.Refactor.CyclomaticComplexity, []},
125+
{Credo.Check.Refactor.FilterCount, []},
126+
{Credo.Check.Refactor.FilterFilter, []},
127+
{Credo.Check.Refactor.FunctionArity, []},
128+
{Credo.Check.Refactor.LongQuoteBlocks, []},
129+
{Credo.Check.Refactor.MapJoin, []},
130+
{Credo.Check.Refactor.MatchInCondition, []},
131+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
132+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
133+
{Credo.Check.Refactor.Nesting, []},
134+
{Credo.Check.Refactor.RedundantWithClauseResult, []},
135+
{Credo.Check.Refactor.RejectReject, []},
136+
{Credo.Check.Refactor.UnlessWithElse, []},
137+
{Credo.Check.Refactor.WithClauses, []},
138+
139+
#
140+
## Warnings
141+
#
142+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
143+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
144+
{Credo.Check.Warning.Dbg, []},
145+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
146+
{Credo.Check.Warning.IExPry, []},
147+
{Credo.Check.Warning.IoInspect, []},
148+
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
149+
{Credo.Check.Warning.OperationOnSameValues, []},
150+
{Credo.Check.Warning.OperationWithConstantResult, []},
151+
{Credo.Check.Warning.RaiseInsideRescue, []},
152+
{Credo.Check.Warning.SpecWithStruct, []},
153+
{Credo.Check.Warning.StructFieldAmount, []},
154+
{Credo.Check.Warning.UnsafeExec, []},
155+
{Credo.Check.Warning.UnusedEnumOperation, []},
156+
{Credo.Check.Warning.UnusedFileOperation, []},
157+
{Credo.Check.Warning.UnusedKeywordOperation, []},
158+
{Credo.Check.Warning.UnusedListOperation, []},
159+
{Credo.Check.Warning.UnusedMapOperation, []},
160+
{Credo.Check.Warning.UnusedPathOperation, []},
161+
{Credo.Check.Warning.UnusedRegexOperation, []},
162+
{Credo.Check.Warning.UnusedStringOperation, []},
163+
{Credo.Check.Warning.UnusedTupleOperation, []},
164+
{Credo.Check.Warning.WrongTestFilename, []}
165+
],
166+
disabled: [
167+
#
168+
# Checks scheduled for next check update (opt-in for now)
169+
{Credo.Check.Refactor.UtcNowTruncate, []},
170+
171+
#
172+
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
173+
# and be sure to use `mix credo --strict` to see low priority checks)
174+
#
175+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
176+
{Credo.Check.Consistency.UnusedVariableNames, []},
177+
{Credo.Check.Design.DuplicatedCode, []},
178+
{Credo.Check.Design.SkipTestWithoutComment, []},
179+
{Credo.Check.Readability.AliasAs, []},
180+
{Credo.Check.Readability.BlockPipe, []},
181+
{Credo.Check.Readability.ImplTrue, []},
182+
{Credo.Check.Readability.MultiAlias, []},
183+
{Credo.Check.Readability.NestedFunctionCalls, []},
184+
{Credo.Check.Readability.OneArityFunctionInPipe, []},
185+
{Credo.Check.Readability.OnePipePerLine, []},
186+
{Credo.Check.Readability.SeparateAliasRequire, []},
187+
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
188+
{Credo.Check.Readability.SinglePipe, []},
189+
{Credo.Check.Readability.Specs, []},
190+
{Credo.Check.Readability.StrictModuleLayout, []},
191+
{Credo.Check.Readability.WithCustomTaggedTuple, []},
192+
{Credo.Check.Refactor.ABCSize, []},
193+
{Credo.Check.Refactor.AppendSingleItem, []},
194+
{Credo.Check.Refactor.CondInsteadOfIfElse, []},
195+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
196+
{Credo.Check.Refactor.FilterReject, []},
197+
{Credo.Check.Refactor.IoPuts, []},
198+
{Credo.Check.Refactor.MapMap, []},
199+
{Credo.Check.Refactor.ModuleDependencies, []},
200+
{Credo.Check.Refactor.NegatedIsNil, []},
201+
{Credo.Check.Refactor.PassAsyncInTestCases, []},
202+
{Credo.Check.Refactor.PipeChainStart, []},
203+
{Credo.Check.Refactor.RejectFilter, []},
204+
{Credo.Check.Refactor.VariableRebinding, []},
205+
{Credo.Check.Warning.LazyLogging, []},
206+
{Credo.Check.Warning.LeakyEnvironment, []},
207+
{Credo.Check.Warning.MapGetUnsafePass, []},
208+
{Credo.Check.Warning.MixEnv, []},
209+
{Credo.Check.Warning.UnsafeToAtom, []}
210+
# {Credo.Check.Warning.UnusedOperation, [{MyMagicModule, [:fun1, :fun2]}]}
211+
212+
# {Credo.Check.Refactor.MapInto, []},
213+
214+
#
215+
# Custom checks can be created using `mix credo.gen.check`.
216+
#
217+
]
218+
}
219+
}
220+
]
221+
}

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
precommit:
11+
name: Precommit (Elixir 1.19 / OTP 28)
12+
runs-on: ubuntu-24.04
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v5
17+
18+
- name: Set up Elixir
19+
uses: erlef/setup-beam@v1
20+
with:
21+
elixir-version: '1.19'
22+
otp-version: '28'
23+
24+
- name: Restore dependencies cache
25+
uses: actions/cache@v5
26+
with:
27+
path: |
28+
deps
29+
_build
30+
key: ${{ runner.os }}-${{ runner.arch }}-mix-precommit-${{ hashFiles('**/mix.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-${{ runner.arch }}-mix-precommit-
33+
34+
- name: Install dependencies
35+
run: mix deps.get
36+
37+
- name: Run precommit checks
38+
run: mix precommit
39+
40+
test:
41+
name: Test (Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }})
42+
# Only Linux for now. Castle is pure Elixir talking to :release_handler,
43+
# with no shell scripts of its own and no suite that boots a release, so
44+
# there is nothing platform-sensitive to run. Add macos-15 alongside the
45+
# release fixture from castle#8.
46+
runs-on: ubuntu-24.04
47+
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
elixir: ['1.18', '1.19', '1.20']
52+
otp: ['27', '28', '29']
53+
exclude:
54+
# Elixir 1.18 supports Erlang/OTP 25-27
55+
- elixir: '1.18'
56+
otp: '28'
57+
- elixir: '1.18'
58+
otp: '29'
59+
# Elixir 1.19 supports Erlang/OTP 26-28
60+
- elixir: '1.19'
61+
otp: '29'
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v5
66+
67+
- name: Set up Elixir
68+
uses: erlef/setup-beam@v1
69+
with:
70+
elixir-version: ${{ matrix.elixir }}
71+
otp-version: ${{ matrix.otp }}
72+
73+
- name: Restore dependencies cache
74+
uses: actions/cache@v5
75+
with:
76+
path: |
77+
deps
78+
_build
79+
key: ${{ runner.os }}-${{ runner.arch }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
80+
restore-keys: |
81+
${{ runner.os }}-${{ runner.arch }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-
82+
83+
- name: Install dependencies
84+
run: mix deps.get
85+
86+
- name: Compile
87+
# Castle pokes at OTP release internals, so the deprecation surface across
88+
# the supported Elixir and OTP range is the point of this matrix until
89+
# there are tests to run on it.
90+
run: mix compile --warnings-as-errors
91+
92+
- name: Run tests
93+
run: mix test

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
# Bare semver tags, as produced by `mix publisho` (e.g. 0.4.0, 0.4.1-rc.1)
7+
- '[0-9]*'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
publish:
14+
name: Publish to Hex
15+
runs-on: ubuntu-24.04
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v5
20+
21+
- name: Set up Elixir
22+
uses: erlef/setup-beam@v1
23+
with:
24+
elixir-version: '1.19'
25+
otp-version: '28'
26+
27+
- name: Install dependencies
28+
run: mix deps.get
29+
30+
- name: Verify tag matches project version
31+
run: |
32+
version=$(grep -m1 -oE '@version "[^"]+"' mix.exs | cut -d'"' -f2)
33+
if [ "$version" != "$GITHUB_REF_NAME" ]; then
34+
echo "::error::Tag '$GITHUB_REF_NAME' does not match mix.exs @version '$version'"
35+
exit 1
36+
fi
37+
echo "Publishing version $version"
38+
39+
- name: Run tests
40+
run: mix test
41+
42+
- name: Publish to Hex
43+
run: mix hex.publish --yes
44+
env:
45+
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ castle-*.tar
2424

2525
# Temporary files, for example, from tests.
2626
/tmp/
27+
28+
# macOS directory metadata.
29+
.DS_Store

0 commit comments

Comments
 (0)