Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.2.0 #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI Checks

on:
push:
branches-ignore: [main]

permissions:
contents: read

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Elixir
id: beam
uses: erlef/setup-beam@v1
with:
elixir-version: "1.14.2"
otp-version: "25.1.2"

- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-

- name: Install dependencies
run: mix deps.get

- name: compile
run: mix compile --warnings-as-errors

- name: credo
run: mix credo --strict

- name: Run tests
run: mix test

# Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
# Cache key based on Elixir & Erlang version (also useful when running in matrix)
- name: Restore PLT cache
uses: actions/cache@v3
id: plt_cache
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
restore-keys: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
path: |
priv/plts

# Create PLTs if no cache was found
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

- name: Run dialyzer
run: mix dialyzer --format github
14 changes: 14 additions & 0 deletions .github/workflows/dev_branch_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Dev Branch Deploy

on:
push:
branches:
- "v*.*.*-dev"

jobs:
build:
name: No Op
runs-on: ubuntu-latest

steps:
- run: echo "Yep It's a Dev Branch"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ erl_crash.dump
*.beam
/config/*.secret.exs
.elixir_ls/

# Dialyzer Files
/priv/plts/*.plt
/priv/plts/*.plt.hash
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
elixir 1.14.2-otp-25
69 changes: 62 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ by adding `todo_txt` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:todo_txt, "~> 0.1.0"}
{:todo_txt, "~> 0.2.0"}
]
end
```
Expand All @@ -27,18 +27,18 @@ end
### Read Todos From todo.txt File

```elixir
todos =
File.read!("todo.txt")
|> String.split("\n")
todos =
File.read!("todo.txt")
|> String.split("\n")
|> Enum.map(&Todo.parse/1)
```

### Write Todos To todo.txt File

```elixir
to_write =
todos
|> Enum.map(&Todo.to_string/1)
to_write =
todos
|> Enum.map(&Todo.to_string/1)
|> Enum.join("\n")

File.write!("todo.txt.diff", to_write)
Expand All @@ -53,6 +53,61 @@ File.write!("todo.txt", Enum.join(Enum.map(todo, &Todo.to_string/1), "\n"))
File.write!("done.txt", Enum.join(Enum.map(done, &Todo.to_string/1), "\n"))
```

## CI/CD Publishing
GitHub Actions Workflows are used to manage the publishing of new versions to [Hex PM](https://hexdocs.pm/)

### CI Workflows
- [ci.yml](.github/workflows/ci.yml) runs each time a PR is merged

### CD
This process assumes each merged PR passes CI checks before being merged

#### New Branch Workflow
- [ci.yml](.github/workflows/ci.yml)
- [check_new_branch.yml](.github/workflows/check_version_branch.yml)
```mermaid
graph TD
A[New $BRANCH] --> A1["Run check_new_branch.yml workflow"]
A1 --> B($BRANCH's $VERSION greater than main's?)
B -->|Yes| C["Create New `v$VERSION-dev` branch"]
B -->|No| D("Existing branch named `v$VERSION-dev`?")
D -->|Yes| E["Create PR for $BRANCH into `v$VERSION-dev` branch"]
D -->|No| C
C --> E
```

#### Merge Into Dev Branch Workflow
- [ci.yml](.github/workflows/ci.yml)
- [dev_branch.yml](.github/workflows/dev_branch.yml)
- [deploy_to_hex.yml](.github/workflows/deploy_to_hex.yml)
```mermaid
graph TD
E[$BRANCH PR Merged] --> E1["run ci.ym workflow"]
E1 -->|CI Checks Pass| E2["run dev_branch.yml workflow"]
E2 --> F("PR for `v$VERSION-dev` into main exists?")
F -->|Yes| G["Run deploy_to_hex.yml workflow"]
F -->|No| I["Create PR for `v$VERSION-dev` into main"]
I --> G
G --> G1["*Generate docs and commit to `v$VERSION-dev`"]
G1 --> G2["Publish `v$Version` to Hex"]
G2 --> G3["Check CHANGELOG.md for $VERSION"]
```

#### Merge Into Main Branch Workflow
- [ci.yml](.github/workflows/ci.yml)
- [deploy_new_version.yml](.github/workflows/merged_into_dev_branch.yml)
- [deploy_to_hex.yml](.github/workflows/deploy_to_hex.yml)
```mermaid
graph TD
J["`v$VERSION-dev` PR merged into main"] --> J1["run ci.yml workflow"]
J1 -->|CI Checks Pass| J2["run deploy_new_version.yml workflow"]
J2 --> J3["Create `v$VERSION` tag"]
J3 --> K["Create `v$VERSION` release"]
K --> L["Run deploy_to_hex.yml workflow"]
L --> L1["Publish `v$Version` to Hex"]
L1 --> L2["Delete v$VERSION-dev` package from Hex"]
```

## Roadmap
- Add a File Watcher for Local todo.txt
- Add a File Watcher for Google Drive todo.txt
28 changes: 28 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
import Config

# somewhere in your config file
if Mix.env() == :dev do
config :git_hooks,
auto_install: true,
verbose: true,
branches: [
blacklist: ["main"]
],
hooks: [
pre_commit: [
tasks: [
{:cmd, "mix format --check-formatted"}
]
],
pre_push: [
verbose: false,
tasks: [
{:cmd, "mix clean"},
{:cmd, "mix compile --warnings-as-errors"},
{:cmd, "mix credo --strict"},
{:cmd, "mix test --color"},
{:cmd, "mix dialyzer --format dialyxir"},
{:cmd, "echo 'success!'"}
]
]
]
end
18 changes: 0 additions & 18 deletions config/dev.exs

This file was deleted.

1 change: 0 additions & 1 deletion config/prod.exs

This file was deleted.

1 change: 0 additions & 1 deletion config/test.exs

This file was deleted.

25 changes: 12 additions & 13 deletions lib/todo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,23 @@ defmodule Todo do
description
|> todo_date_to_string(creation_date)
|> todo_date_to_string(completion_date)
|> (fn str -> if priority == :none, do: str, else: "(#{priority}) #{str}" end).()
|> (fn str -> if done, do: "x #{str}", else: str end).()
|> add_priority_to_string(priority)
|> add_done_to_string(done)
|> add_atom_list("@", contexts)
|> add_atom_list("+", projects)
|> todo_due_date_to_string(due_date)
|> append_additional_fields(additional_fields)
|> add_pomo(pomodori)
end

defp add_priority_to_string(str, :none), do: str

defp add_priority_to_string(str, priority) when is_atom(priority), do: "(#{priority}) #{str}"

defp add_done_to_string(str, true), do: "x #{str}"

defp add_done_to_string(str, false), do: str

defp add_pomo(str, :none), do: str

defp add_pomo(str, {completed, total}) do
Expand Down Expand Up @@ -294,17 +302,8 @@ defmodule Todo do
end

defp set_from_parsed({:description, description}, todo) do
contexts =
case context_parser(description) do
{:ok, contexts, _, _, _, _} -> contexts
{:error, message, _, _, _, _} -> {:error, message}
end

projects =
case project_parser(description) do
{:ok, projects, _, _, _, _} -> projects
{:error, message, _, _, _, _} -> {:error, message}
end
{:ok, contexts, _, _, _, _} = context_parser(description)
{:ok, projects, _, _, _, _} = project_parser(description)

Map.put(todo, :description, description)
|> Map.put(:contexts, contexts)
Expand Down
18 changes: 9 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ defmodule TodoTxt.MixProject do
dialyzer: [
ignore_warnings: ".dialyzer_ignore.exs",
list_unused_filters: true,
plt_file: {:no_warn, "todo_txt.plt"}
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
],
app: :todo_txt,
version: "0.1.0",
elixir: "~> 1.12.2",
version: "0.2.0",
elixir: "~> 1.14.2",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: description(),
Expand All @@ -27,7 +27,7 @@ defmodule TodoTxt.MixProject do
source_url: "https://github.com/KTSCode/todo_txt",
docs: [
# The main page in the docs
main: "Todo",
main: "TodoTxt",
logo: "todotxt_logo_2012.png",
extras: ["README.md"]
]
Expand All @@ -42,26 +42,26 @@ defmodule TodoTxt.MixProject do
end

defp description() do
"A library for reading/parseing/writing todo.txt files"
"A library for reading/parsing/writing todo.txt files"
end

defp package() do
[
# These are the default files included in the package
files: ~w(lib .formatter.exs mix.exs README* LICENSE*),
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/KTSCode/todo_txt"}
links: %{"GitHub" => "https://github.com/KTSCode/todo_txt_elixir"}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:credo, "~> 1.5.5", only: :dev, runtime: false},
{:credo, "~> 1.6.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0.0", only: :dev, runtime: false},
{:ex_doc, "~> 0.23.0", only: :dev, runtime: false},
{:ex_doc, "~> 0.29.1", only: :dev, runtime: false},
{:excoveralls, "~> 0.13.0", only: :test},
{:git_hooks, "~> 0.5.2", only: :dev, runtime: false},
{:git_hooks, "~> 0.7.3", only: [:dev], runtime: false},
{:mix_test_watch, "~> 1.0.2", only: :dev, runtime: false},
{:nimble_parsec, "~> 1.1.0"},
{:recon, "~> 2.5.2", only: :dev, runtime: false}
Expand Down
Loading