From f77d426a289eebfc3cda134de5bd72b938f9dd6f Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sun, 12 Sep 2021 15:46:38 +0300 Subject: [PATCH] Version 3.0.0 release (#177) * Version 3.0.0 release * Version 3.0.0 release * Version 3.0.0 release * Version 3.0.0 release * Version 3.0.0 release * Version 3.0.0 release --- .github/workflows/test.yml | 73 +++++++++++++++++++++++ .gitignore | 1 + .travis.yml | 23 ------- CHANGELOG.md | 15 +++++ README.md | 18 +++--- lib/ecto_autoslug_field/slug.ex | 6 +- lib/ecto_autoslug_field/slug_generator.ex | 12 ++-- mix.exs | 19 +++--- mix.lock | 4 +- 9 files changed, 118 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ea3ee52 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,73 @@ +name: test + +'on': + push: + pull_request: + branches: + # Branches from forks have the form 'user:branch-name'. Reference: + # https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662/9 + - '**:**' + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + env: + MIX_ENV: test + strategy: + matrix: + elixir: ['1.10', '1.11', '1.12'] + otp: ['23', '24'] + continue-on-error: false + + steps: + - uses: actions/checkout@v2 + + - name: Setup elixir + uses: erlef/setup-elixir@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Get deps cache + uses: actions/cache@v2 + with: + path: deps/ + key: deps-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} + + - name: Get build cache + uses: actions/cache@v2 + with: + path: _build/test/ + key: build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} + + - name: Install Dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + mix compile + - name: Run linters + run: | + mix format --check-formatted + mix credo --strict + - name: Run Tests + run: mix coveralls.github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Retrieve PLT Cache + uses: actions/cache@v2 + id: plt-cache + with: + path: priv/plts + key: plts-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} + + - name: Create PLTs + if: steps.plt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer --plt + - name: Run dialyzer + run: mix dialyzer --no-check diff --git a/.gitignore b/.gitignore index 92a2eb5..392211e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /tmp erl_crash.dump *.ez +/priv/plts #### osx #### *.DS_Store diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 94a0951..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: elixir - -sudo: false - -elixir: - - 1.6 - - 1.7 - - 1.8 - - 1.9 - -otp_release: - - 20.0 - - 21.0 - -env: MIX_ENV=test - -script: - - mix format --check-formatted - - mix credo --strict - - mix coveralls.travis - -notifications: - email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index f302ea3..6810c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## v3.0.0 - 2021-09-12 + +### Features + +- Now support `elixir>=1.10` +- Updates `ecto` to `3.7` +- Updates bunch of other deps to newer versions + +### Misc + +- Moves from Travis to GitHub Actions +- Adds `mix format` support + + ## v2.0.1 - 2019-10-16 ### Bugfixes diff --git a/README.md b/README.md index 5170114..56aeeb4 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,15 @@ # EctoAutoslugField -[![Build Status](https://travis-ci.org/sobolevn/ecto_autoslug_field.svg?branch=master)](https://travis-ci.org/sobolevn/ecto_autoslug_field) +[![Build Status](https://github.com/sobolevn/ecto_autoslug_field/workflows/test/badge.svg?branch=master&event=push)](https://github.com/sobolevn/ecto_autoslug_field/actions?query=workflow%3Atest) [![Coverage Status](https://coveralls.io/repos/github/sobolevn/ecto_autoslug_field/badge.svg?branch=master)](https://coveralls.io/github/sobolevn/ecto_autoslug_field?branch=master) [![Module Version](https://img.shields.io/hexpm/v/ecto_autoslug_field.svg)](https://hex.pm/packages/ecto_autoslug_field) [![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ecto_autoslug_field/) -[![Total Download](https://img.shields.io/hexpm/dt/ecto_autoslug_field.svg)](https://hex.pm/packages/ecto_autoslug_field) [![License](https://img.shields.io/hexpm/l/ecto_autoslug_field.svg)](https://github.com/sobolevn/ecto_autoslug_field/blob/master/LICENSE) -[![Last Updated](https://img.shields.io/github/last-commit/sobolevn/ecto_autoslug_field.svg)](https://github.com/sobolevn/ecto_autoslug_field/commits/master) `ecto_autoslug_field` is a reusable [`Ecto`](https://github.com/elixir-ecto/ecto) library which can automatically create slugs from other fields. We use [`slugger`](https://github.com/h4cc/slugger) as a default slug-engine. We only depend on the `ecto` package (we do not deal with `ecto_sql` at all). -We support `ecto >= 2.1 and ecto < 4`! +We support `ecto >= 3.7 and ecto < 4`! See [this blog post](https://sobolevn.me/2017/07/creating-slugs-for-ecto-schemas) for more information. @@ -22,7 +20,7 @@ for more information. ```elixir def deps do [ - {:ecto_autoslug_field, "~> 2.0"} + {:ecto_autoslug_field, "~> 3.0"} ] end ``` @@ -73,13 +71,13 @@ defmodule EctoSlugs.Blog.Article do timestamps() end - def changeset(%Article{} = article, attrs) do - article - |> cast(attrs, [:title, :content, :breaking]) + def changeset(model, params \\ :invalid) do + model + |> cast(params, [:title, :content, :breaking]) |> validate_required([:title, :content]) |> unique_constraint(:title) - |> TitleSlug.maybe_generate_slug - |> TitleSlug.unique_constraint + |> TitleSlug.maybe_generate_slug() + |> TitleSlug.unique_constraint() end end ``` diff --git a/lib/ecto_autoslug_field/slug.ex b/lib/ecto_autoslug_field/slug.ex index c7211f4..38e9e22 100644 --- a/lib/ecto_autoslug_field/slug.ex +++ b/lib/ecto_autoslug_field/slug.ex @@ -48,10 +48,12 @@ defmodule EctoAutoslugField.SlugBase do 1. `atom`-key is supposed to identify the model field 2. `binary`-key is treated as a data itself, it won't be changed """ - @spec get_sources(Changeset.t(), Keyword.t()) :: - list(atom() | binary()) | none + @spec get_sources(Changeset.t(), Keyword.t()) :: list(atom() | binary()) def get_sources(_changeset, [from: from] = _opts) do + # This code is only used in macros, so it is not tracked by `coveralls`. + # coveralls-ignore-start [from] + # coveralls-ignore-stop end @doc """ diff --git a/lib/ecto_autoslug_field/slug_generator.ex b/lib/ecto_autoslug_field/slug_generator.ex index 1301d95..16ec5c1 100644 --- a/lib/ecto_autoslug_field/slug_generator.ex +++ b/lib/ecto_autoslug_field/slug_generator.ex @@ -5,6 +5,8 @@ defmodule EctoAutoslugField.SlugGenerator do It is suited for inner use. """ + alias Ecto.Changeset + import Ecto.Changeset, only: [ put_change: 3, @@ -17,9 +19,7 @@ defmodule EctoAutoslugField.SlugGenerator do Default slug builder. """ @spec build_slug(Keyword.t(), Changeset.t()) :: String.t() - def build_slug(sources, _changeset) do - do_build_slug(sources) - end + def build_slug(sources, _changeset), do: do_build_slug(sources) @doc """ This function conditionally generates slug. @@ -96,10 +96,6 @@ defmodule EctoAutoslugField.SlugGenerator do defp get_field_data(_, source, _) when is_binary(source), do: source defp has_value?(nil), do: false - - defp has_value?(string) when is_binary(string) do - String.trim(string) != "" - end - + defp has_value?(string) when is_binary(string), do: String.trim(string) != "" defp has_value?(_), do: true end diff --git a/mix.exs b/mix.exs index d7d4f49..4da4552 100644 --- a/mix.exs +++ b/mix.exs @@ -2,13 +2,13 @@ defmodule EctoAutoslugField.Mixfile do use Mix.Project @source_url "https://github.com/sobolevn/ecto_autoslug_field" - @version "2.0.1" + @version "3.0.0" def project do [ app: :ecto_autoslug_field, version: @version, - elixir: "~> 1.6", + elixir: "~> 1.10", deps: deps(), build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, @@ -27,7 +27,10 @@ defmodule EctoAutoslugField.Mixfile do ], # Dialyzer: - dialyzer: [plt_add_deps: :apps_direct, plt_add_apps: [:ecto]] + dialyzer: [ + plt_add_deps: :apps_direct, + plt_add_apps: [:ecto] + ] ] end @@ -37,15 +40,15 @@ defmodule EctoAutoslugField.Mixfile do defp deps do [ - {:ecto, ">= 2.1.0"}, + {:ecto, ">= 3.7.0"}, # Slugs: - {:slugger, ">= 0.2.0"}, + {:slugger, ">= 0.3.0"}, # Testing: - {:excoveralls, "~> 0.5", only: :test}, - {:credo, "~> 1.0", only: [:dev, :test], runtime: false}, - {:dialyxir, "~> 1.0", only: :dev, runtime: false}, + {:excoveralls, "~> 0.14", only: :test}, + {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, # Documentation: {:ex_doc, ">= 0.23.0", only: :dev, runtime: false} diff --git a/mix.lock b/mix.lock index 46ec547..6fd3466 100644 --- a/mix.lock +++ b/mix.lock @@ -5,7 +5,7 @@ "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"}, - "ecto": {:hex, :ecto, "3.6.2", "efdf52acfc4ce29249bab5417415bd50abd62db7b0603b8bab0d7b996548c2bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "efad6dfb04e6f986b8a3047822b0f826d9affe8e4ebdd2aeedbfcb14fd48884e"}, + "ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"}, "excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"}, @@ -22,6 +22,6 @@ "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm", "20d0ded0e712605d1eae6c5b4889581c3460d92623a930ddda91e0e609b5afba"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, - "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, + "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, }