Skip to content

Commit

Permalink
Merge pull request #73 from jaeyson/72-move-benchmark-as-a-mix-task
Browse files Browse the repository at this point in the history
Move benchmark as a mix task
  • Loading branch information
jaeyson authored Apr 13, 2024
2 parents b6c78e0 + 485c18d commit 51f8fdb
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 149 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "mix" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
labels:
- "hex"
- "dependencies"
57 changes: 18 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,41 @@ on:
push:

jobs:
check_commit_message:
name: skips CI and prints cli message, without fail build badge
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, '[skip ci]')"
steps:
- run: echo "no need to build, based from commit message"

# https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# Workflows that would otherwise be triggered using `on: push` or
# `on: pull_request` won't be triggered if you add any of the
# following strings to the commit message in a push, or the HEAD
# commit of a pull request:
# - [skip ci]
# - [ci skip]
# - [no ci]
# - [skip actions]
# - [actions skip]
test:
name: Elixir v${{ matrix.elixir }}/OTP v${{ matrix.otp }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
# - elixir: 1.11.x
# otp: 22
# - elixir: 1.11.x
# otp: 23
# - elixir: 1.12.x
# otp: 23
# - elixir: 1.13.x
# otp: 24
- elixir: 1.14.x
otp: 25
warnings_as_errors: true
static_analysis: true
name: Elixir setup and test
runs-on: ubuntu-20.04
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# doesn't contain "ci skip" in commit message
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Erlang/OTP & Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
otp-version: "26"
elixir-version: "1.16.x"

- name: Cache artifacts
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('**/mix.lock') }}
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
${{ runner.os }}-mix-
- name: Install Dependencies
run: |
Expand All @@ -73,9 +58,3 @@ jobs:
run: mix coveralls.github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to Hex
if: "contains(github.event.head_commit.message, '[publish to hex]')"
run: |
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
mix hex.publish --yes
28 changes: 28 additions & 0 deletions .github/workflows/hex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
check_commit_message:
name: skips CI and prints cli message, without fail build badge
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, '[skip ci]')"
steps:
- run: echo "no need to build, based from commit message"

publish_to_hex:
name: "Publish to Hex"
runs-on: ubuntu-latest

# doesn't contain "ci skip" in commit message
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
run: |
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
mix hex.publish --yes
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ sample-*.tar
# Temporary files, for example, from tests.
/tmp/

# Benchmarks from benchee
/benchmarks/

.elixir_ls

.DS_Store
2 changes: 1 addition & 1 deletion .iex.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
alias FreecodecampElixir.AlgoProjects
alias FreecodecampElixir.BasicAlgo
alias FreecodecampElixir.IntermediateAlgo
alias FreecodecampElixir.Benchmarks

require Logger
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.2.0 (2024.12.04)

- Benchmarks as mix task
- Bump dependencies' versions
- Tidy docs

## 0.1.0 (2022.09.04)

* Initial release
- Initial release
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Solving exercises from Freecodecamp.org using Elixir programming language. Includes benchmarks and tests for every functions.

[//]: # "Badges"

[![Last Commit][commit-badge]](https://github.com/jaeyson/freecodecamp_elixir/commit/main)
[![Commit activity][pulse-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulse)
[![Dependabot][dependabot-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulls/app%2Fdependabot)
Expand Down Expand Up @@ -112,7 +113,6 @@ mix selective_test basic_algo intermediate_algo

# basic_algo = Basic Algorithm Scripting
# intermediate_algo = Intermediate Algorithm Scripting
# algo_projects = Algorithm Projects
```

## Generate `HTML` Docs
Expand All @@ -124,22 +124,22 @@ mix docs

## Benchmarks (using Benchee)

If you want to benchmark a specific function:

```bash
# NOTE: file path is at
# freecodecamp_elixir/benchmarks/basic_algo.exs
# view benchmark commands
mix help benchmark
```

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

# you can use the default formatter (console)
BasicAlgo.run("repeat_string", Console)
```bash
# specific function
mix benchmark mutation
```

```bash
mix run benchmarks/basic_algo.exs
# benchmark results saved as html in "benchmarks/" directory
mix benchmark mutation --html
```
13 changes: 5 additions & 8 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"skip_files": [
"benchmarks/",
"lib/mix/"
],
"terminal_options": {
"file_column_width": 60
}
}
"skip_files": ["lib/freecodecamp_elixir/benchmarks/", "lib/mix/"],
"terminal_options": {
"file_column_width": 60
}
}
6 changes: 0 additions & 6 deletions lib/freecodecamp_elixir/algo_projects.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/freecodecamp_elixir/basic_algo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ defmodule FreecodecampElixir.BasicAlgo do
end

@spec do_get_index_to_ins(non_neg_integer | nil) :: non_neg_integer
def do_get_index_to_ins(nil), do: 0
def do_get_index_to_ins(result), do: result
defp do_get_index_to_ins(nil), do: 0
defp do_get_index_to_ins(result), do: result

@doc """
Check if a string (first argument, `string`) ends with the
Expand Down
Loading

0 comments on commit 51f8fdb

Please sign in to comment.