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

Use docker directly on Linux instead of relying on third party action #18

Merged
merged 54 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9a8bdd6
Update action.yml
danielmarbach Mar 5, 2024
f721c48
Update action.yml
danielmarbach Mar 5, 2024
077bb11
Update ci.yml
danielmarbach Mar 5, 2024
698bb93
Update action.yml
danielmarbach Mar 5, 2024
e032d95
Update action.yml
danielmarbach Mar 5, 2024
49b53d4
Update ci.yml
danielmarbach Mar 5, 2024
eae1480
Update action.yml
danielmarbach Mar 5, 2024
58e08e9
Update action.yml
danielmarbach Mar 5, 2024
2084afe
Move quiet
danielmarbach Mar 5, 2024
0dca53c
Real quiet
danielmarbach Mar 5, 2024
4fd3f61
Make it chatty for now
danielmarbach Mar 5, 2024
6d05bed
Formatting
danielmarbach Mar 6, 2024
eda8ee3
Try quiet again
danielmarbach Mar 6, 2024
3112824
Try bash
danielmarbach Mar 6, 2024
aa8ced4
Update action.yml
danielmarbach Mar 6, 2024
0c7eaa8
Try to fix things
danielmarbach Mar 6, 2024
00de3d7
More output
danielmarbach Mar 6, 2024
ae77a9e
Less output
danielmarbach Mar 6, 2024
2de1391
Test connection refused
danielmarbach Mar 6, 2024
63f3ac8
Bring back quiet
danielmarbach Mar 6, 2024
b3cdc46
Grouping
danielmarbach Mar 6, 2024
72af9ff
Formatting
andreasohlund Mar 13, 2024
4ea3de4
Add test project
andreasohlund Mar 13, 2024
94d30e5
Fix test name
andreasohlund Mar 13, 2024
22860fc
Fix test
andreasohlund Mar 13, 2024
5f05fb7
Create folder to make test runner happy
andreasohlund Mar 13, 2024
e16f29f
Use latest client
andreasohlund Mar 13, 2024
5f58d5d
Print cluster details
andreasohlund Mar 13, 2024
35d9dce
Fix serialization
andreasohlund Mar 14, 2024
357619b
Logging
andreasohlund Mar 14, 2024
bbdeaed
Better logging
andreasohlund Mar 14, 2024
498b824
Try fake call
andreasohlund Mar 14, 2024
7694ad6
Check replica set name
andreasohlund Mar 14, 2024
c0d1dc5
Adding the standard dependabot config
danielmarbach Mar 14, 2024
ed6fbda
Adding reposync to make sure dependabot config is synced
danielmarbach Mar 14, 2024
6a1ea09
Set replicaset in connstring
andreasohlund Mar 14, 2024
1eefd23
Merge branch 'replicaset' of https://github.com/Particular/setup-mong…
andreasohlund Mar 14, 2024
7a78325
Add assert and fix syntax
andreasohlund Mar 14, 2024
0cdb8be
Log conn string
andreasohlund Mar 14, 2024
6bf5746
rename
andreasohlund Mar 14, 2024
4b8e3fc
Echo
andreasohlund Mar 14, 2024
c4eebaa
Test connection with replicaset
danielmarbach Mar 14, 2024
2b91c6d
Write output
danielmarbach Mar 14, 2024
930de36
Check more conditions
danielmarbach Mar 14, 2024
0eb008a
Testing connections everywhere
danielmarbach Mar 14, 2024
43712ac
Proper replica setup
danielmarbach Mar 14, 2024
12a8984
T
danielmarbach Mar 14, 2024
bc47e83
Hardcode
danielmarbach Mar 14, 2024
303cb6b
Try something else
danielmarbach Mar 14, 2024
96b8961
Different quoting
danielmarbach Mar 14, 2024
7c5c68d
Proper
danielmarbach Mar 14, 2024
091b60c
Try
danielmarbach Mar 14, 2024
58f7219
Windows same
danielmarbach Mar 14, 2024
d58bd7e
Align windows
danielmarbach Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/dependabot.yml
@@ -1,5 +1,29 @@
version: 2
updates:
- package-ecosystem: nuget
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 1000
groups:
AWSSDK:
patterns:
- "AWSSDK.*"
NServiceBusCore:
patterns:
- "NServiceBus"
- "NServiceBus.AcceptanceTesting"
- "NServiceBus.AcceptanceTests.Sources"
- "NServiceBus.PersistenceTests.Sources"
- "NServiceBus.TransportTests.Sources"
ignore:
# Particular.Analyzers updates are distributed via RepoStandards
- dependency-name: "Particular.Analyzers"
# Changing these 3 dependencies affects the .NET SDK and Visual Studio versions we support
# These types of updates should be more intentional than an automated update
- dependency-name: "Microsoft.Build.Utilities.Core"
- dependency-name: "Microsoft.CodeAnalysis.CSharp"
- dependency-name: "Microsoft.CodeAnalysis.CSharp.Workspaces"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -16,9 +16,9 @@ jobs:
matrix:
include:
- name: Windows
os: windows-2019
os: windows-2022
- name: Linux
os: ubuntu-20.04
os: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -29,10 +29,19 @@ jobs:
mongodb-port: 27018
mongodb-replica-set: "tr0"
- name: Check result
if: runner.os == 'Windows'
shell: pwsh
run: |
$connstr = $Env:MongoDBConnectionString
Write-Host "Connection String: $connstr"

$result = mongosh "$connstr"
echo $result
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build src --configuration Release
- name: Run tests
uses: Particular/run-tests-action@v1.7.0
102 changes: 102 additions & 0 deletions .gitignore
@@ -0,0 +1,102 @@
/assets
/binaries
/deploy
/nugets
build32
*.vshost.*
.nu
_UpgradeReport.*
*.cache
Thumbs.db
*~
*.swp
results
CommonAssemblyInfo.cs
lib/sqlite/System.Data.SQLite.dll
*.orig
*.zip
Samples/DataBus/storage
packages
PrecompiledWeb
tempstorage
.learningtransport
core-only
Release
Artifacts
LogFiles
csx
*.ncrunchproject
*.ncrunchsolution
_NCrunch_NServiceBus/*
logs
run-git.cmd
src/Chocolatey/Build/*

installer/[F|f]iles
installer/[C|c]ustom[A|a]ctions
installer/ServiceControl-cache

# Created by https://www.gitignore.io

### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.json.lock
*.nuget.targets
*.lock.json
*.userosscache
*.sln.docstates
.vs/
local.settings.json

# mac temp file ignore
.DS_Store

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Roslyn cache directories
*.ide/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

#NUNIT
*.VisualState.xml
TestResult.xml

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings
*.DotSettings.user

src/scaffolding.config

# Approval tests temp file
*.received.*

# JetBrains Rider
.idea/
*.sln.iml

# Visual Studio Code
.vscode
Empty file added .reposync.yml
Empty file.
109 changes: 99 additions & 10 deletions action.yml
Expand Up @@ -10,11 +10,11 @@ inputs:
description: "MongoDB replica set name (no replica set by default)"
required: false
default: ""

mongodb-version:
description: "MongoDB version (default 7.0.6)"
required: false
default: "7.0.6"
default: "7.0.6"

mongodb-port:
description: "MongoDB port to use (default 27017)"
Expand All @@ -37,7 +37,7 @@ runs:
mkdir $databaseRootDirectory > $null
mkdir $databaseDataDirectory > $null
mkdir $databaseLogsDirectory > $null

$version = [Version]::new("${{ inputs.mongodb-version }}")
$databaseBinDirectory = "C:\Program Files\MongoDB\Server\$($version.Major).$($version.Minor)\bin"

Expand Down Expand Up @@ -71,19 +71,108 @@ runs:

echo "::endgroup::"

Write-Output "::group::Testing connection"
$startDate = Get-Date
do {
try {
$output = & mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "db.serverStatus()" --quiet
if(!$output.Contains('ECONNREFUSED')) {
Write-Output "Connection to MongoDB successful"
break
}
}
catch {
if ($startDate.AddSeconds(20) -lt (Get-Date)) {
throw "MongoDB did not initialize within 20 seconds. Exiting."
}
Start-Sleep -Seconds 1
Write-Output "Connection to MongoDB unsuccessful. Trying again"
}
} While ($True)

Write-Output "::endgroup::"

if($replicaSet) {
& mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "rs.initiate()"
Write-Output "::group::Setting up the replica set"

$rsInitialize =
"rs.initiate(
{
_id: '${{ inputs.mongodb-replica-set }}',
members: [ { _id: 0, host: '127.0.0.1:${{ inputs.mongodb-port }}' } ]
}
);"

& mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "$rsInitialize" --quiet
& mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "rs.status()" --quiet

echo "::endgroup::"
}

- name: Start MongoDB Server (Linux)
if: runner.os == 'Linux'
uses: supercharge/mongodb-github-action@v1.10.0
with:
mongodb-replica-set: ${{ inputs.mongodb-replica-set }}
mongodb-port: ${{ inputs.mongodb-port }}
mongodb-version: ${{ inputs.mongodb-version }}
shell: pwsh
run: |
$databaseServiceName = "MongoDB$(Get-Random)"
Write-Output "::group:: Starting MongoDB $databaseServiceName on port ${{ inputs.mongodb-port }}"
$replicaSet = "${{ inputs.mongodb-replica-set }}"

if($replicaSet) {
Write-Output "Starting MongoD with replica"
docker run --name $databaseServiceName --publish ${{ inputs.mongodb-port }}:${{ inputs.mongodb-port }} --detach mongo:${{ inputs.mongodb-version }} --replSet $replicaSet --port ${{ inputs.mongodb-port }}
}
else {
Write-Output "Starting MongoD without replica"
docker run --name $databaseServiceName --publish ${{ inputs.mongodb-port }}:${{ inputs.mongodb-port }} --detach mongo:${{ inputs.mongodb-version }} --port ${{ inputs.mongodb-port }}
}

Write-Output "::group::Testing connection"
$startDate = Get-Date
do {
try {
$output = & docker exec --tty $databaseServiceName mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "db.serverStatus()" --quiet
if(!$output.Contains('ECONNREFUSED')) {
Write-Output "Connection to MongoDB successful"
break
}
}
catch {
if ($startDate.AddSeconds(20) -lt (Get-Date)) {
throw "MongoDB did not initialize within 20 seconds. Exiting."
}
Start-Sleep -Seconds 1
Write-Output "Connection to MongoDB unsuccessful. Trying again"
}
} While ($True)

Write-Output "::endgroup::"

if($replicaSet) {
Write-Output "::group::Setting up the replica set"

$rsInitialize =
"rs.initiate(
{
_id: '${{ inputs.mongodb-replica-set }}',
members: [ { _id: 0, host: '127.0.0.1:${{ inputs.mongodb-port }}' } ]
}
);"

docker exec --tty $databaseServiceName mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "$rsInitialize" --quiet
docker exec --tty $databaseServiceName mongosh "mongodb://127.0.0.1:${{ inputs.mongodb-port }}" --eval "rs.status()" --quiet

Write-Output "::endgroup::"
}
- name: Setup Connection string
shell: pwsh
run: |
echo "Setting environment variable ${{ inputs.connection-string-name }} to MongoDB connection string..."
echo "${{ inputs.connection-string-name }}=mongodb://127.0.0.1:${{ inputs.mongodb-port }}" >> $Env:GITHUB_ENV

$connectionString = "${{ inputs.connection-string-name }}=mongodb://127.0.0.1:${{ inputs.mongodb-port }}"
$replicaSet = "${{ inputs.mongodb-replica-set }}"

if($replicaSet) {
$connectionString = $connectionString + "/?replicaSet=" + $replicaSet
}

echo $connectionString >> $Env:GITHUB_ENV
31 changes: 31 additions & 0 deletions src/setup-mongodb-action.sln
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34601.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{04C163B1-1840-450F-B837-8FFECDBCB8A7}"
ProjectSection(SolutionItems) = preProject
..\action.yml = ..\action.yml
..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "tests\Tests.csproj", "{E8FD91D3-D32B-4C92-9849-ECD6AEE39439}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E8FD91D3-D32B-4C92-9849-ECD6AEE39439}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8FD91D3-D32B-4C92-9849-ECD6AEE39439}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8FD91D3-D32B-4C92-9849-ECD6AEE39439}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8FD91D3-D32B-4C92-9849-ECD6AEE39439}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A5FE4431-5BCC-4407-B770-79B27F730761}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions src/tests/DriverCompatibilityTests.cs
@@ -0,0 +1,27 @@
using System;
using MongoDB.Driver;
using MongoDB.Driver.Core.Clusters;
using NUnit.Framework;

[TestFixture]
class DriverCompatibilityTests
{
[Test]
public void Should_report_correct_cluster_type()
{
var connectionString = Environment.GetEnvironmentVariable("MongoDBConnectionString");
TestContext.WriteLine("ConnectionString: " + connectionString);

var client = new MongoClient(connectionString);

//do a fake call to make sure that cluster details is fetched
client.ListDatabases();

TestContext.WriteLine("State: " + client.Cluster.Description.State);
TestContext.WriteLine("Type: " + client.Cluster.Description.Type);
TestContext.WriteLine("ReplicaSetName: " + client.Cluster.Settings.ReplicaSetName);

Assert.AreEqual(ClusterType.ReplicaSet, client.Cluster.Description.Type);
Assert.AreEqual("tr0", client.Cluster.Settings.ReplicaSetName);
}
}
15 changes: 15 additions & 0 deletions src/tests/Tests.csproj
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

</Project>