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

Add CodeQL workflow for GitHub code scanning #167

Merged
merged 9 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: "59 14 * * 2"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ csharp ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
33 changes: 10 additions & 23 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,24 @@ env:
jobs:
build:

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.x
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Add MSFT code signing key
run: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- name: Add MSFT package repo
run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
- name: MySQL
dotnet-version: 6.x
- name: Install MS SQL Server and Postgresql, start existing MySQL
run: |
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --port=3306 --skip-grant-tables &
- name: Install Sql Server
run: sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server
- name: Configure Sql Server
run: sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula
- name: Install dependencies
run: dotnet restore
sudo wget -qO/etc/apt/trusted.gpg.d/microsoft.asc https://packages.microsoft.com/keys/microsoft.asc
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
sed -i -e 's/Pwd=;/Pwd=root;AllowPublicKeyRetrieval=True;/' DicomTypeTranslation.Tests/TestDatabases.xml
sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server
sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula
sudo service mysql start
- name: Build
run: dotnet build --configuration Release --no-restore
run: dotnet build --configuration Release
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Pack and push
Expand Down
5 changes: 5 additions & 0 deletions .lgtm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extraction:
csharp:
index:
dotnet:
version: 6.0.103
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .travisignore

This file was deleted.

4 changes: 2 additions & 2 deletions DicomTypeTranslation.Tests/DatabaseExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void WorkedExampleTest(FAnsi.DatabaseType dbType)
tbl.AddColumn("FileLocation", new DatabaseTypeRequest(typeof(string), 500), true, 500);

//Create a DataTable in memory for the data we read from disk
DataTable dt = new DataTable();
using var dt = new DataTable();
dt.Columns.Add("SOPInstanceUID");
dt.Columns.Add("Modality");
dt.Columns.Add("PatientID");
Expand Down Expand Up @@ -101,7 +101,7 @@ public void TestGetDataTable()
new DicomDate(DicomTag.PatientBirthDate,new DateTime(2001,1,1))
});

var dt = new DataTable();
using var dt = new DataTable();
var row = ds.ToRow(dt);

Assert.AreEqual("Frank", row["PatientName"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<AssemblyTitle>DicomTypeTranslation.Tests</AssemblyTitle>
<Product>DicomTypeTranslation.Tests</Product>
Expand Down
46 changes: 23 additions & 23 deletions DicomTypeTranslation/Helpers/DicomDatasetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,40 @@ public static bool ValueEquals(DicomItem a, DicomItem b)
private static bool ValueEquals(IByteBuffer a, IByteBuffer b)
{
if (a == null || b == null)
return a == b;
return ReferenceEquals(a,b);

if (a == b)
if (ReferenceEquals(a, b))
return true;

if (a.IsMemory)
return b.IsMemory && a.Data.SequenceEqual(b.Data);

if (a is IBulkDataUriByteBuffer abuff)
switch (a)
{
if (!(b is IBulkDataUriByteBuffer bbuff))
return false;

return abuff.BulkDataUri == bbuff.BulkDataUri;
}

if (a is EmptyBuffer && b is EmptyBuffer)
return true;
case IBulkDataUriByteBuffer abuff:
{
if (b is not IBulkDataUriByteBuffer bbuff)
return false;

if (a is StreamByteBuffer && b is StreamByteBuffer)
{
var asbb = (StreamByteBuffer)a;
var bsbb = (StreamByteBuffer)b;
return abuff.BulkDataUri == bbuff.BulkDataUri;
}
case EmptyBuffer when b is EmptyBuffer:
return true;
case StreamByteBuffer buffer when b is StreamByteBuffer:
{
var asbb = buffer;
var bsbb = (StreamByteBuffer)b;

if (asbb.Stream == null || bsbb.Stream == null)
return asbb.Stream == bsbb.Stream;
if (asbb.Stream == null || bsbb.Stream == null)
return asbb.Stream == bsbb.Stream;

return asbb.Position == bsbb.Position && asbb.Size == bsbb.Size && asbb.Stream.Equals(bsbb.Stream);
return asbb.Position == bsbb.Position && asbb.Size == bsbb.Size && asbb.Stream.Equals(bsbb.Stream);
}
case CompositeByteBuffer buffer when b is CompositeByteBuffer:
return buffer.Buffers.Zip(((CompositeByteBuffer)b).Buffers, ValueEquals).All(x => x);
default:
return a.Equals(b);
}

if (a is CompositeByteBuffer && b is CompositeByteBuffer)
return ((CompositeByteBuffer)a).Buffers.Zip(((CompositeByteBuffer)b).Buffers, ValueEquals).All(x => x);

return a.Equals(b);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion DicomTypeTranslation/Helpers/DictionaryHelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static bool DictionaryEquals(IDictionary dict1, IDictionary dict2)
{
//if either is null
if (dict1 == null || dict2 == null)
return dict1 == dict2; //they are only equal if they are both null
return Object.ReferenceEquals(dict1,dict2); //they are only equal if they are both null

var keys1 = new HashSet<object>();

Expand Down
6 changes: 3 additions & 3 deletions DicomTypeTranslation/Helpers/FlexibleEquality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class FlexibleEquality
public static bool FlexibleEquals(object a, object b)
{
if (a == null || b == null)
return a == b;
return ReferenceEquals(a,b);

//types are different so most likely we are not equipped to deal with this problem let a decide if it is equal or not
if (a.GetType() != b.GetType())
Expand All @@ -31,8 +31,8 @@ public static bool FlexibleEquals(object a, object b)
return DictionaryHelperMethods.DictionaryEquals((IDictionary)a, (IDictionary)b);

//if they are both arrays
if (a is Array)
return ArrayHelperMethods.ArrayEquals((Array)a, (Array)b);
if (a is Array array)
return ArrayHelperMethods.ArrayEquals(array, (Array)b);

//they are not dictionaries or arrays
return Equals(a, b);
Expand Down
11 changes: 0 additions & 11 deletions rakeconfig.rb

This file was deleted.

80 changes: 0 additions & 80 deletions rakefile.rb

This file was deleted.