Skip to content

GitHub actions #370

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

Merged
merged 46 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c8e7bed
Add credo
joeapearson Sep 27, 2021
126dda7
mix format
joeapearson Sep 27, 2021
e2a3445
Add github actions
joeapearson Sep 27, 2021
79eae87
Really basic contributing.md
joeapearson Sep 27, 2021
836e391
Matricise build
joeapearson Sep 27, 2021
f24988d
Bump latest versions
joeapearson Sep 27, 2021
034658c
Add docker compose
joeapearson Sep 27, 2021
9235332
Docker compose in deamon mode
joeapearson Sep 27, 2021
2f6fb95
Attempt to run tests in CI
joeapearson Sep 28, 2021
bd53bba
Use sudo
joeapearson Sep 28, 2021
39af7ad
Fix tests
joeapearson Sep 29, 2021
0f56b27
Use github provisioned mongo
joeapearson Sep 29, 2021
0c30773
Split jobs
joeapearson Sep 29, 2021
3a4b89c
Specify otp and el ver
joeapearson Sep 29, 2021
7a94cd0
Set otp ver
joeapearson Sep 29, 2021
bac4346
Run mix deps.get
joeapearson Sep 29, 2021
2b4aa04
Continue on formatting and linting errors for now
joeapearson Sep 29, 2021
0fd6d63
Cache build
joeapearson Sep 29, 2021
b7dca43
Cache PLTs
joeapearson Sep 29, 2021
e5e9b25
Use existing bash script
joeapearson Sep 29, 2021
6b8ad88
Install matrix version
joeapearson Sep 29, 2021
89ce90b
Add mongo status output
joeapearson Sep 29, 2021
aad4b0d
Use start mongo script
joeapearson Sep 29, 2021
394b054
Split mongo version
joeapearson Sep 29, 2021
229dad9
Allow downgrades of mongodb
joeapearson Sep 29, 2021
ec48ef2
Only test Mongo 4.4 for now
joeapearson Sep 29, 2021
42bacd8
Cleanup
joeapearson Sep 29, 2021
4991c91
More selective run rules
joeapearson Sep 30, 2021
af32ef5
Merge branch 'master' into github-actions
scottmessinger Mar 22, 2023
2cfa162
Update CI to use mongodb setup used in other drivers
scottmessinger Mar 22, 2023
bebda64
Remove duplicate ci line
scottmessinger Mar 22, 2023
4bd8149
fix steps for ci
scottmessinger Mar 22, 2023
5e7fb2b
Move name
scottmessinger Mar 22, 2023
2f4a94b
fix elixir version
scottmessinger Mar 22, 2023
8415122
set ubuntu
scottmessinger Mar 22, 2023
e87b0f9
Install deps
scottmessinger Mar 22, 2023
e508a63
Try to pass in the mongodb uri
scottmessinger Mar 22, 2023
4462e28
Comment out text
scottmessinger Mar 22, 2023
815add0
Mongo 4.2 isn't available in the setup so removing
scottmessinger Mar 22, 2023
ccbc6e2
Does not yet work on Mongo 5.0 and 6.0
scottmessinger Mar 22, 2023
2ea0a15
Comment unused references to test we commented out
scottmessinger Mar 22, 2023
4c7ec51
Change test threshold to 70
scottmessinger Mar 22, 2023
74cc2f7
Make tests for 5.0 pass
scottmessinger Mar 22, 2023
6f0ba78
Remove tests for putting write concern 0
scottmessinger Mar 22, 2023
a75e09f
Remove call to deprecated function at compile time
scottmessinger Mar 22, 2023
84493f4
Remove call to deprecated function at compile time
scottmessinger Mar 22, 2023
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
11 changes: 0 additions & 11 deletions .ebert.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
on: push

jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
# Just some default versions to run code quality tools with.
# These can be upgraded as and when but probably won't need to change much.
otp-version: "24.0.6"
elixir-version: "1.12.3"
- uses: actions/cache@v2
with:
path: |
deps
_build
priv/plts
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
- run: mix deps.get
- run: mix credo --strict
continue-on-error: true
- run: mix format --check-formatted
continue-on-error: true
- run: mix dialyzer
test:
strategy:
matrix:
os:
- ubuntu-latest
otp-version:
- "24.0.6"
elixir-version:
- "1.12.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably setup an actual matrix and test previous versions of Elixir and OTP as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Any suggestions for that? I was starting simple so at least there is something in place as we go forward.

mongo-version:
- maj: 4
min: 4
patch: 8
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp-version }}
elixir-version: ${{ matrix.elixir-version }}
- uses: actions/cache@v2
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a proper matrix of Elixir and OTP versions, you will want to include the versions in the cache key in order to pull the proper cache version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, more important here. I'll fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
key: ${{ runner.os }}-{{runner.otp-version}}-{{runner.elixir-version}}-mix-${{ hashFiles('**/mix.lock') }}

I think this is what @ankhers is suggesting!

restore-keys: |
${{ runner.os }}-mix-
- name: Install Mongo
run: |
# See https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

# Import MongoDB public key
wget -qO - https://www.mongodb.org/static/pgp/server-${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.asc | sudo apt-key add -

# Create a list file for MongoDB
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.list

# Update package db
sudo apt-get update

# Finally install mongodb
sudo apt-get install -y \
--allow-downgrades \
mongodb-org=${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.${{ matrix.mongo-version.patch }} \
mongodb-org-server=${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.${{ matrix.mongo-version.patch }} \
mongodb-org-shell=${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.${{ matrix.mongo-version.patch }} \
mongodb-org-mongos=${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.${{ matrix.mongo-version.patch }} \
mongodb-org-tools=${{ matrix.mongo-version.maj }}.${{ matrix.mongo-version.min }}.${{ matrix.mongo-version.patch }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of this, you can look at what one of the official mongo drivers uses to start mongo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh excellent find. Agreed.

- name: Start Mongo
run: ./start_mongo.bash
- run: mix test --cover
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing

Thanks for considering making a contribution to `mongodb`!

## Getting started

1. Clone this repository
2. Install mongodb and make sure it's available on `$PATH`
3. Run `start_mongo.bash`
4. Run `mix test`


## What's next?

1. Take a look at our [open issues](https://github.com/elixir-mongo/mongodb/issues)
2. Create a new issue or open a discussion for larger topics.
1 change: 0 additions & 1 deletion lib/mongo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ defmodule Mongo do
with {:ok, query} <- Mongo.Session.add_session(query, opts[:session]),
{:ok, conn, _, _} <- select_server(topology_pid, :write, opts),
{:ok, doc} <- direct_command(conn, query, opts) do

{:ok,
%Mongo.FindAndModifyResult{
value: doc["value"],
Expand Down
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ defmodule Mongodb.Mixfile do

defp deps do
[
{:credo, "~> 1.5.6", only: [:dev, :test], runtime: false},
{:db_connection, "~> 2.4.0"},
{:decimal, "~> 2.0.0"},
{:jason, "~> 1.2.2", only: :test},
{:ex_doc, ">= 0.0.0", only: :dev},
{:dialyxir, "~> 1.1.0", only: :dev, runtime: false},
{:earmark, ">= 0.0.0", only: :dev},
{:dialyxir, "~> 1.1.0", only: :dev, runtime: false}
{:ex_doc, ">= 0.0.0", only: :dev},
{:jason, "~> 1.2.2", only: [:dev, :test]}
]
end

Expand Down
3 changes: 3 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
"credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
"db_connection": {:hex, :db_connection, "2.4.0", "d04b1b73795dae60cead94189f1b8a51cc9e1f911c234cc23074017c43c031e5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad416c21ad9f61b3103d254a71b63696ecadb6a917b36f563921e0de00d7d7c8"},
"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": {:hex, :earmark, "1.4.15", "2c7f924bf495ec1f65bd144b355d0949a05a254d0ec561740308a54946a67888", [:mix], [{:earmark_parser, ">= 1.4.13", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "3b1209b85bc9f3586f370f7c363f6533788fb4e51db23aa79565875e7f9999ee"},
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
"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"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
Expand Down
18 changes: 9 additions & 9 deletions test/mongo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ defmodule Mongo.Test do
assert {:ok, value} =
Mongo.find_one_and_update(c.pid, coll, %{"foo" => 42}, %{"$set" => %{bar: 2}})

assert %{"bar" => 1} = value, "Should return original document by default"
assert %Mongo.FindAndModifyResult{ value: %{"bar" => 1}} = value, "Should return original document by default"

# should raise if we don't have atomic operators
assert_raise ArgumentError, fn ->
Expand All @@ -325,7 +325,7 @@ defmodule Mongo.Test do
return_document: :after
)

assert %{"bar" => 3} = value, "Should return modified doc"
assert %Mongo.FindAndModifyResult{ value: %{"bar" => 3}} = value, "Should return modified doc"

# projection
assert {:ok, value} =
Expand All @@ -344,7 +344,7 @@ defmodule Mongo.Test do
return_document: :after
)

assert %{"bar" => 10, "baz" => 1} = value, "Should respect the sort"
assert %Mongo.FindAndModifyResult{value: %{"bar" => 10, "baz" => 1}} = value, "Should respect the sort"

# upsert
assert {:ok, value} =
Expand All @@ -353,15 +353,15 @@ defmodule Mongo.Test do
return_document: :after
)

assert %{"foo" => 43, "baz" => 1} = value, "Should upsert"
assert %Mongo.FindAndModifyResult{ value: %{"foo" => 43, "baz" => 1}} = value, "Should upsert"

# don't find return {:ok, nil}
assert {:ok, nil} ==
assert {:ok, %Mongo.FindAndModifyResult{value: nil, matched_count: 0, updated_existing: false}} ==
Mongo.find_one_and_update(c.pid, coll, %{"number" => 666}, %{
"$set" => %{title: "the number of the beast"}
})

assert {:ok, nil} ==
assert {:ok, %Mongo.FindAndModifyResult{value: nil, matched_count: 0, updated_existing: false}} ==
Mongo.find_one_and_update(c.pid, "coll_that_doesnt_exist", %{"number" => 666}, %{
"$set" => %{title: "the number of the beast"}
})
Expand All @@ -384,7 +384,7 @@ defmodule Mongo.Test do

# defaults
assert {:ok, value} = Mongo.find_one_and_replace(c.pid, coll, %{"foo" => 42}, %{bar: 2})
assert %{"foo" => 42, "bar" => 1} = value, "Should return original document by default"
assert %Mongo.FindAndModifyResult{value: %{"foo" => 42, "bar" => 1}} = value, "Should return original document by default"

# return_document = :after
assert {:ok, _} = Mongo.insert_one(c.pid, coll, %{foo: 43, bar: 1})
Expand All @@ -394,7 +394,7 @@ defmodule Mongo.Test do
return_document: :after
)

assert %{"bar" => 3} = value, "Should return modified doc"
assert %Mongo.FindAndModifyResult{ value: %{"bar" => 3}} = value, "Should return modified doc"
assert match?(%{"foo" => 43}, value) == false, "Should replace document"

# projection
Expand Down Expand Up @@ -435,7 +435,7 @@ defmodule Mongo.Test do
return_document: :after
)

assert %{"upsertedDocument" => true} = value, "Should upsert"
assert %Mongo.FindAndModifyResult{ value: %{"upsertedDocument" => true}} = value, "Should upsert"

assert [%{"upsertedDocument" => true}] =
c.pid |> Mongo.find(coll, %{upsertedDocument: true}) |> Enum.to_list()
Expand Down