Skip to content

Commit 51f8fdb

Browse files
authored
Merge pull request #73 from jaeyson/72-move-benchmark-as-a-mix-task
Move benchmark as a mix task
2 parents b6c78e0 + 485c18d commit 51f8fdb

File tree

17 files changed

+337
-149
lines changed

17 files changed

+337
-149
lines changed

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "mix" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
labels:
13+
- "hex"
14+
- "dependencies"

.github/workflows/ci.yml

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,41 @@ on:
55
push:
66

77
jobs:
8-
check_commit_message:
9-
name: skips CI and prints cli message, without fail build badge
10-
runs-on: ubuntu-latest
11-
if: "contains(github.event.head_commit.message, '[skip ci]')"
12-
steps:
13-
- run: echo "no need to build, based from commit message"
14-
8+
# https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
9+
# Workflows that would otherwise be triggered using `on: push` or
10+
# `on: pull_request` won't be triggered if you add any of the
11+
# following strings to the commit message in a push, or the HEAD
12+
# commit of a pull request:
13+
# - [skip ci]
14+
# - [ci skip]
15+
# - [no ci]
16+
# - [skip actions]
17+
# - [actions skip]
1518
test:
16-
name: Elixir v${{ matrix.elixir }}/OTP v${{ matrix.otp }}
17-
runs-on: ubuntu-latest
18-
strategy:
19-
matrix:
20-
include:
21-
# - elixir: 1.11.x
22-
# otp: 22
23-
# - elixir: 1.11.x
24-
# otp: 23
25-
# - elixir: 1.12.x
26-
# otp: 23
27-
# - elixir: 1.13.x
28-
# otp: 24
29-
- elixir: 1.14.x
30-
otp: 25
31-
warnings_as_errors: true
32-
static_analysis: true
19+
name: Elixir setup and test
20+
runs-on: ubuntu-20.04
3321
env:
3422
MIX_ENV: test
3523
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
37-
# doesn't contain "ci skip" in commit message
38-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
3924
steps:
4025
- name: Checkout repo
41-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
4227

4328
- name: Setup Erlang/OTP & Elixir
4429
uses: erlef/setup-beam@v1
4530
with:
46-
otp-version: ${{ matrix.otp }}
47-
elixir-version: ${{ matrix.elixir }}
31+
otp-version: "26"
32+
elixir-version: "1.16.x"
4833

4934
- name: Cache artifacts
50-
uses: actions/cache@v2
35+
uses: actions/cache@v4
5136
with:
5237
path: |
5338
deps
5439
_build
55-
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('**/mix.lock') }}
40+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
5641
restore-keys: |
57-
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
42+
${{ runner.os }}-mix-
5843
5944
- name: Install Dependencies
6045
run: |
@@ -73,9 +58,3 @@ jobs:
7358
run: mix coveralls.github
7459
env:
7560
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76-
77-
- name: Publish to Hex
78-
if: "contains(github.event.head_commit.message, '[publish to hex]')"
79-
run: |
80-
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
81-
mix hex.publish --yes

.github/workflows/hex.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check_commit_message:
13+
name: skips CI and prints cli message, without fail build badge
14+
runs-on: ubuntu-latest
15+
if: "contains(github.event.head_commit.message, '[skip ci]')"
16+
steps:
17+
- run: echo "no need to build, based from commit message"
18+
19+
publish_to_hex:
20+
name: "Publish to Hex"
21+
runs-on: ubuntu-latest
22+
23+
# doesn't contain "ci skip" in commit message
24+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
25+
steps:
26+
run: |
27+
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
28+
mix hex.publish --yes

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ sample-*.tar
2525
# Temporary files, for example, from tests.
2626
/tmp/
2727

28+
# Benchmarks from benchee
29+
/benchmarks/
30+
2831
.elixir_ls
2932

3033
.DS_Store

.iex.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
alias FreecodecampElixir.AlgoProjects
21
alias FreecodecampElixir.BasicAlgo
32
alias FreecodecampElixir.IntermediateAlgo
3+
alias FreecodecampElixir.Benchmarks
44

55
require Logger

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.2.0 (2024.12.04)
4+
5+
- Benchmarks as mix task
6+
- Bump dependencies' versions
7+
- Tidy docs
8+
39
## 0.1.0 (2022.09.04)
410

5-
* Initial release
11+
- Initial release

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Solving exercises from Freecodecamp.org using Elixir programming language. Includes benchmarks and tests for every functions.
44

55
[//]: # "Badges"
6+
67
[![Last Commit][commit-badge]](https://github.com/jaeyson/freecodecamp_elixir/commit/main)
78
[![Commit activity][pulse-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulse)
89
[![Dependabot][dependabot-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulls/app%2Fdependabot)
@@ -112,7 +113,6 @@ mix selective_test basic_algo intermediate_algo
112113

113114
# basic_algo = Basic Algorithm Scripting
114115
# intermediate_algo = Intermediate Algorithm Scripting
115-
# algo_projects = Algorithm Projects
116116
```
117117

118118
## Generate `HTML` Docs
@@ -124,22 +124,22 @@ mix docs
124124

125125
## Benchmarks (using Benchee)
126126

127-
If you want to benchmark a specific function:
128-
129127
```bash
130-
# NOTE: file path is at
131-
# freecodecamp_elixir/benchmarks/basic_algo.exs
128+
# view benchmark commands
129+
mix help benchmark
130+
```
132131

133-
# Example: change the function name from
134-
# "mutation" to "repeat_string"
135-
# BasicAlgo.run("mutation", HTML)
136-
# or uncomment lines to use that instead
137-
BasicAlgo.run("repeat_string", HTML)
132+
```bash
133+
# list available functions
134+
mix benchmark --list
135+
```
138136

139-
# you can use the default formatter (console)
140-
BasicAlgo.run("repeat_string", Console)
137+
```bash
138+
# specific function
139+
mix benchmark mutation
141140
```
142141

143142
```bash
144-
mix run benchmarks/basic_algo.exs
143+
# benchmark results saved as html in "benchmarks/" directory
144+
mix benchmark mutation --html
145145
```

coveralls.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
2-
"skip_files": [
3-
"benchmarks/",
4-
"lib/mix/"
5-
],
6-
"terminal_options": {
7-
"file_column_width": 60
8-
}
9-
}
2+
"skip_files": ["lib/freecodecamp_elixir/benchmarks/", "lib/mix/"],
3+
"terminal_options": {
4+
"file_column_width": 60
5+
}
6+
}

lib/freecodecamp_elixir/algo_projects.ex

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/freecodecamp_elixir/basic_algo.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ defmodule FreecodecampElixir.BasicAlgo do
284284
end
285285

286286
@spec do_get_index_to_ins(non_neg_integer | nil) :: non_neg_integer
287-
def do_get_index_to_ins(nil), do: 0
288-
def do_get_index_to_ins(result), do: result
287+
defp do_get_index_to_ins(nil), do: 0
288+
defp do_get_index_to_ins(result), do: result
289289

290290
@doc """
291291
Check if a string (first argument, `string`) ends with the

0 commit comments

Comments
 (0)