Skip to content

Commit 931039c

Browse files
greg-rychlewskiGreg Rychlewski
andauthored
Automate SQLite Version Testing (#210)
Co-authored-by: Greg Rychlewski <[email protected]>
1 parent 784e20f commit 931039c

5 files changed

Lines changed: 45 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches:
66
- "*"
77
pull_request:
8-
types:
9-
- opened
108
branches:
119
- "*"
1210

@@ -37,6 +35,7 @@ jobs:
3735
- run: mix format --check-formatted
3836
- run: mix deps.unlock --check-unused
3937
- run: mix credo --all
38+
- run: mix test_sqlite_version
4039

4140
test:
4241
runs-on: ${{ matrix.os }}

bin/download_sqlite.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ set -e
77
# https://www.sqlite.org/src/timeline?r=version-3.36.0
88
# VERSION consists of 7 digits, like:3350000 for "3.35.5" or 3360000 for "3.36.0"
99

10-
VERSION=3390200
11-
1210
mkdir -p tmp
1311
pushd tmp
1412

lib/mix/tasks/download_sqlite.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule Mix.Tasks.DownloadSqlite do
2+
@moduledoc false
3+
4+
use Mix.Task
5+
6+
@shortdoc "Downloads the SQLite amalgamation version specified in mix.exs"
7+
def run(_args) do
8+
version = Exqlite.MixProject.sqlite_version() |> tarball_version()
9+
System.cmd("sh", ["-c", "VERSION=#{version} bin/download_sqlite.sh"])
10+
end
11+
12+
defp tarball_version(semantic_version) do
13+
[major, minor, patch] = String.split(semantic_version, ".")
14+
minor = String.pad_leading(minor, 2, "0")
15+
patch = String.pad_leading(patch, 2, "0")
16+
17+
major <> minor <> patch <> "00"
18+
end
19+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule Mix.Tasks.TestSqliteVersion do
2+
@moduledoc false
3+
4+
use Mix.Task
5+
6+
@shortdoc "Tests that the SQLite amalgation version matches the SQLite version in mix.exs"
7+
def run(_args) do
8+
# Get mix SQLite version
9+
mix_version = Exqlite.MixProject.sqlite_version()
10+
11+
# Get installed SQLite version
12+
{:ok, conn} = Exqlite.Sqlite3.open(":memory:")
13+
{:ok, stmt} = Exqlite.Sqlite3.prepare(conn, "select sqlite_version()")
14+
{_, [amalgamation_version]} = Exqlite.Sqlite3.step(conn, stmt)
15+
16+
if mix_version != amalgamation_version do
17+
("mix test_sqlite_version failed: the mix.exs version (#{mix_version}) " <>
18+
"does not match the amalgation version (#{amalgamation_version})")
19+
|> Mix.raise()
20+
end
21+
end
22+
end

mix.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule Exqlite.MixProject do
22
use Mix.Project
33

44
@version "0.11.3"
5+
@sqlite_version "3.39.2"
56

67
def project do
78
[
@@ -35,6 +36,8 @@ defmodule Exqlite.MixProject do
3536
]
3637
end
3738

39+
def sqlite_version, do: @sqlite_version
40+
3841
# Run "mix help deps" to learn about dependencies.
3942
defp deps do
4043
[

0 commit comments

Comments
 (0)