Skip to content
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
25 changes: 24 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
contents: write
packages: write

steps:
Expand Down Expand Up @@ -45,6 +45,7 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
Expand All @@ -59,3 +60,25 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64

- name: Create release image reference
if: github.event_name == 'release'
shell: bash
run: |
set -euo pipefail
{
echo "CodeMedic container image"
echo "Release: ${{ github.event.release.tag_name }}"
echo "Repository: ${{ github.repository }}"
echo "Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
echo "Digest: ${{ steps.build.outputs.digest }}"
echo ""
echo "Tags:"
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ - /'
} > codemedic-container-image.txt

- name: Attach image reference to release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
files: codemedic-container-image.txt
126 changes: 126 additions & 0 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release Binaries (NativeAOT)

on:
release:
types: [published]
workflow_dispatch:

env:
DOTNET_NOLOGO: true

jobs:
publish-aot:
name: Publish NativeAOT (${{ matrix.rid }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
rid: win-x64
ext: .exe
- os: windows-latest
rid: win-arm64
ext: .exe
- os: ubuntu-latest
rid: linux-x64
ext: ""
- os: ubuntu-latest
rid: linux-arm64
ext: ""
needsCross: true
- os: macos-13
rid: osx-x64
ext: ""
- os: macos-latest
rid: osx-arm64
ext: ""

permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x

- name: Install NativeAOT prerequisites (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y clang zlib1g-dev

- name: Install cross toolchain (linux-arm64)
if: runner.os == 'Linux' && matrix.needsCross
shell: bash
run: |
set -euo pipefail
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu

- name: Restore
run: dotnet restore src/CodeMedic.sln

- name: Publish (NativeAOT)
run: >-
dotnet publish src/CodeMedic/CodeMedic.csproj
-c Release
-r ${{ matrix.rid }}
/p:PublishAot=true

- name: Prepare artifact
shell: bash
run: |
set -euo pipefail
VERSION="${{ github.event.release.tag_name }}"
if [ -z "$VERSION" ]; then VERSION="manual"; fi

OUTDIR="src/CodeMedic/bin/Release/net10.0/${{ matrix.rid }}/publish"
BIN="$OUTDIR/CodeMedic${{ matrix.ext }}"

if [ ! -f "$BIN" ]; then
echo "Expected binary not found at $BIN"
echo "Publish directory contents:"
ls -la "$OUTDIR" || true
exit 1
fi

mkdir -p artifacts
DEST="artifacts/CodeMedic-${VERSION}-${{ matrix.rid }}${{ matrix.ext }}"
cp "$BIN" "$DEST"

- name: Generate checksums (SHA-256)
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'

$files = Get-ChildItem -LiteralPath 'artifacts' -File | Where-Object { $_.Name -notmatch '\.sha256$' }
if (-not $files -or $files.Count -eq 0) {
throw 'No artifacts found to checksum.'
}

foreach ($file in $files) {
$hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $file.FullName).Hash.ToLowerInvariant()
$line = "$hash $($file.Name)"
$checksumPath = "$($file.FullName).sha256"
$line | Out-File -FilePath $checksumPath -Encoding ascii
}

- name: Upload workflow artifact
uses: actions/upload-artifact@v4
with:
name: CodeMedic-${{ matrix.rid }}
path: artifacts/*

- name: Attach binaries to GitHub Release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
files: artifacts/*
16 changes: 16 additions & 0 deletions src/CodeMedic/CodeMedic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>

<!-- Allow publishing per-platform single-file executables. -->
<RuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>

<!-- Default Release publish settings: self-contained single file (per RID). -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>

<!-- Keep Release artifacts minimal: single executable only. -->
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/CodeMedic/InternalsVisibleTo.Test.CodeMedic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Test.CodeMedic")]
27 changes: 24 additions & 3 deletions src/CodeMedic/Output/ConsoleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,39 @@ private void RenderTable(ReportTable reportTable)
{
var table = new Table
{
Border = TableBorder.Rounded
Border = TableBorder.Rounded,
Expand = true
};

if (!string.IsNullOrWhiteSpace(reportTable.Title))
{
table.Title = new TableTitle($"[bold]{reportTable.Title}[/]");
}

// Add columns
// Add columns (wrap long-text columns; keep short columns compact)
var noWrapHeaders = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Version",
"Latest",
"Type",
"License",
"Source",
"Comm",
"Severity",
"Score",
"Count",
"Status"
};

foreach (var header in reportTable.Headers)
{
table.AddColumn(header);
var column = new TableColumn(header);
if (noWrapHeaders.Contains(header))
{
column.NoWrap();
}

table.AddColumn(column);
}

// Add rows
Expand Down
46 changes: 31 additions & 15 deletions src/CodeMedic/Plugins/BomAnalysis/BomAnalysisPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ private async Task<Dictionary<string, PackageInfo>> AddNuGetPackagesSectionAsync
latestVersionDisplay = "Current";
}

// Truncate package names if too long to improve table formatting
var displayName = package.Name.Length > 25 ? package.Name.Substring(0, 22) + "..." : package.Name;
// Keep full package names/licenses for report accuracy.
var displayName = package.Name;

// Shorten source type and commercial status for better formatting
var sourceType = package.SourceType == "Open Source" ? "Open" :
Expand All @@ -320,8 +320,7 @@ private async Task<Dictionary<string, PackageInfo>> AddNuGetPackagesSectionAsync
var commercial = package.Commercial == "Unknown" ? "?" :
package.Commercial == "Yes" ? "Y" : "N";

// Truncate license if too long
var license = package.License?.Length > 12 ? package.License.Substring(0, 9) + "..." : package.License ?? "Unknown";
var license = package.License ?? "Unknown";

packagesTable.AddRow(
displayName,
Expand Down Expand Up @@ -527,19 +526,36 @@ private async Task FetchLatestVersionForPackageAsync(PackageInfo package)
var apiUrl = $"https://api.nuget.org/v3-flatcontainer/{package.Name.ToLowerInvariant()}/index.json";

var response = await httpClient.GetStringAsync(apiUrl);
var versionData = JsonSerializer.Deserialize<NuGetVersionResponse>(response, new JsonSerializerOptions

using var doc = JsonDocument.Parse(response);
if (doc.RootElement.ValueKind != JsonValueKind.Object)
{
PropertyNameCaseInsensitive = true
});

if (versionData?.Versions?.Length > 0)
return;
}

if (!doc.RootElement.TryGetProperty("versions", out var versionsElement) ||
versionsElement.ValueKind != JsonValueKind.Array)
{
return;
}

var versions = new List<string>();
foreach (var element in versionsElement.EnumerateArray())
{
if (element.ValueKind == JsonValueKind.String)
{
var value = element.GetString();
if (!string.IsNullOrWhiteSpace(value))
{
versions.Add(value);
}
}
}

if (versions.Count > 0)
{
// Get the latest stable version (not pre-release)
var latestVersion = versionData.Versions
.Where(v => !IsPreReleaseVersion(v))
.LastOrDefault() ?? versionData.Versions.Last();

package.LatestVersion = latestVersion;
var latestStable = versions.Where(v => !IsPreReleaseVersion(v)).LastOrDefault();
package.LatestVersion = latestStable ?? versions.Last();
}
}
catch (HttpRequestException ex)
Expand Down
Loading