From 7dfc63ce51c03b19de81155ba403436415af8065 Mon Sep 17 00:00:00 2001 From: c4710n Date: Mon, 8 Jul 2024 23:15:28 +0800 Subject: [PATCH] chore: prepare for publishing --- .github/workflows/ci.yml | 49 ++++++++++++++++++++++++++++++++++++++++ README.md | 23 ++++++++++++------- lib/jxon.ex | 7 +++++- mix.exs | 47 ++++++++++++++++++++++++++++++++++---- mix.lock | 18 +++++++++++++++ test/jxon_test.exs | 4 +--- 6 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 mix.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..21f3fe8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + mix_check: + name: Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }} + runs-on: ubuntu-20.04 + strategy: + # Following matrix is maintained by following https://hexdocs.pm/elixir/compatibility-and-deprecations.html + # And, only the most recent 3 versions of Elixir are involved. + matrix: + include: + # Elixir v1.17 + - { elixir: '1.17.x', otp: '27.x' } + - { elixir: '1.17.x', otp: '26.x' } + - { elixir: '1.17.x', otp: '25.x' } + # Elixir v1.16 + - { elixir: '1.16.x', otp: '26.x' } + - { elixir: '1.16.x', otp: '25.x' } + - { elixir: '1.16.x', otp: '24.x' } + # Elixir v1.15 + - { elixir: '1.15.x', otp: '26.x' } + - { elixir: '1.15.x', otp: '25.x' } + - { elixir: '1.15.x', otp: '24.x' } + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + - name: Restore dependencies cache + uses: actions/cache@v4 + with: + path: deps + key: ${{ runner.os }}-elixir_${{ matrix.elixir }}-otp_${{ matrix.otp }}-mix_${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-elixir_${{ matrix.elixir }}-otp_${{ matrix.otp }}-mix + - name: Install dependencies + run: mix deps.get + - name: Run mix check + run: mix check diff --git a/README.md b/README.md index 81fd928..6a071ae 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,28 @@ # JXON -**TODO: Add description** +[![CI](https://github.com/cozy-elixir/jxon/actions/workflows/ci.yml/badge.svg)](https://github.com/cozy-elixir/jxon/actions/workflows/ci.yml) +[![Hex.pm](https://img.shields.io/hexpm/v/jxon.svg)](https://hex.pm/packages/jxon) -## Installation +A wrapper for various JSON implementations. -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `jxon` to your list of dependencies in `mix.exs`: +Add `:jxon` to the list of dependencies in `mix.exs`: ```elixir def deps do [ - {:jxon, "~> 0.1.0"} + {:jxon, } ] end ``` -Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) -and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at . +## Usage +For more information, see the [documentation](https://hexdocs.pm/jxon). + +## Thanks + +Inspired by the `json_module` of [jose](https://github.com/potatosalad/erlang-jose). + +## License + +[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) diff --git a/lib/jxon.ex b/lib/jxon.ex index 6bbb49b..7969b93 100644 --- a/lib/jxon.ex +++ b/lib/jxon.ex @@ -1,6 +1,11 @@ defmodule JXON do @moduledoc """ A wrapper for various JSON implementations. + + ## Why? + + It helps to create JSON-implementation-agnostic packages, leaving the choice + of JSON implementation to the user. """ @spec encode(term()) :: {:ok, String.t()} | :error @@ -23,7 +28,7 @@ defmodule JXON do end defp __decode__(binary) do - case Jason.decode(term) do + case Jason.decode(binary) do {:ok, string} -> {:ok, string} _ -> :error end diff --git a/mix.exs b/mix.exs index eac9d6f..5d08ac0 100644 --- a/mix.exs +++ b/mix.exs @@ -1,13 +1,23 @@ defmodule JXON.MixProject do use Mix.Project + @version "0.1.0" + @description "A wrapper for various JSON implementations." + @source_url "https://github.com/cozy-elixir/jxon" + def project do [ app: :jxon, - version: "0.1.0", + version: @version, elixir: "~> 1.15", start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + description: @description, + source_url: @source_url, + homepage_url: @source_url, + docs: docs(), + package: package(), + aliases: aliases() ] end @@ -21,8 +31,37 @@ defmodule JXON.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + {:jason, ">= 0.0.0", only: [:dev]}, + {:ex_check, ">= 0.0.0", only: [:dev], runtime: false}, + {:credo, ">= 0.0.0", only: [:dev], runtime: false}, + {:dialyxir, ">= 0.0.0", only: [:dev], runtime: false}, + {:ex_doc, ">= 0.0.0", only: [:dev], runtime: false}, + {:mix_audit, ">= 0.0.0", only: [:dev], runtime: false} ] end + + defp docs do + [ + extras: ["README.md"], + source_url: @source_url, + source_ref: "v#{@version}" + ] + end + + defp package do + [ + licenses: ["Apache-2.0"], + links: %{GitHub: @source_url} + ] + end + + defp aliases do + [publish: ["hex.publish", "tag"], tag: &tag_release/1] + end + + defp tag_release(_) do + Mix.shell().info("Tagging release as v#{@version}") + System.cmd("git", ["tag", "v#{@version}"]) + System.cmd("git", ["push", "--tags"]) + end end diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..f489402 --- /dev/null +++ b/mix.lock @@ -0,0 +1,18 @@ +%{ + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"}, + "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.40", "f3534689f6b58f48aa3a9ac850d4f05832654fe257bf0549c08cc290035f70d5", [:mix], [], "hexpm", "cdb34f35892a45325bad21735fadb88033bcb7c4c296a999bde769783f53e46a"}, + "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, + "ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"}, + "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, + "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, + "jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"}, + "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, + "mix_audit": {:hex, :mix_audit, "2.1.3", "c70983d5cab5dca923f9a6efe559abfb4ec3f8e87762f02bab00fa4106d17eda", [:make, :mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.9", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "8c3987100b23099aea2f2df0af4d296701efd031affb08d0746b2be9e35988ec"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"}, + "yaml_elixir": {:hex, :yaml_elixir, "2.11.0", "9e9ccd134e861c66b84825a3542a1c22ba33f338d82c07282f4f1f52d847bd50", [:mix], [{:yamerl, "~> 0.10", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "53cc28357ee7eb952344995787f4bb8cc3cecbf189652236e9b163e8ce1bc242"}, +} diff --git a/test/jxon_test.exs b/test/jxon_test.exs index 12777ea..74faa8c 100644 --- a/test/jxon_test.exs +++ b/test/jxon_test.exs @@ -2,7 +2,5 @@ defmodule JXONTest do use ExUnit.Case doctest JXON - test "greets the world" do - assert JXON.hello() == :world - end + # The implementation is simple, so no test for now. end