Skip to content

Commit

Permalink
Push to NuGet (#303)
Browse files Browse the repository at this point in the history
* Push to NuGet

* Add build step

* Fix imports
  • Loading branch information
erri120 authored May 8, 2023
1 parent f4f4e97 commit 1957a8e
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/clean_environment_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ jobs:

# - name: Clean
# run: dotnet clean


- name: Build
run: dotnet build

- name: Tests
run: dotnet test --filter "RequiresNetworking!=True" --collect:"XPlat Code Coverage;Format=opencover"
run: dotnet test --no-build --filter "RequiresNetworking!=True" --collect:"XPlat Code Coverage;Format=opencover"

- uses: codecov/codecov-action@v3
with:
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/publish-nuget-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish NuGet Packages

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Get Version
id: get-version
shell: pwsh
run: |
$version = [System.Version]::Parse("${{ github.ref_name }}".Replace('v', '')).ToString()
echo "version=$version" >> $env:GITHUB_OUTPUT
echo $version
- name: Print Debug Info
run: dotnet --info

- name: Pack
run: dotnet --pack -p:Version="${{ steps.get-version.outputs.version }}" -p:RepositoryCommit="${{ github.sha }}"

- name: Validate
shell: pwsh
run: ./scripts/validate-nupkgs.ps1

- name: Push to NuGet
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<!-- https://github.com/dotnet/sourcelink/tree/main/docs#continuousintegrationbuild -->
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
Expand Down
5 changes: 5 additions & 0 deletions NuGet.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Project>
<PropertyGroup>
<!-- Overwrites IsPackable from global Directory.Build.props -->
<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup>
<Authors>Nexus Mods</Authors>

Expand Down
56 changes: 56 additions & 0 deletions scripts/validate-nupkgs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This script extracts all "*.nupkg" files and parses the ".nuspec" file.
# It looks at the dependencies of that package and alerts if some dependencies
# of this organization are not available.

$Organization = "NexusMods"

$nupkgs = Get-ChildItem -Path "*" -Recurse -Include "*.nupkg"

$allPackages = [System.Collections.Generic.HashSet[string]]::new()
$allDependencies = [System.Collections.Generic.HashSet[string]]::new()

foreach ($item in $nupkgs)
{
$packageName = [System.IO.Path]::GetFileName(
[System.IO.Path]::GetDirectoryName(
[System.IO.Path]::GetDirectoryName(
[System.IO.Path]::GetDirectoryName($item))))

$allPackages.Add($packageName)
$extractedPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($item.FullName), "extracted")

Expand-Archive -Path $item.FullName -DestinationPath $extractedPath -Force

$nuspecFilePath = [System.IO.Path]::Combine($extractedPath, $packageName + ".nuspec")

if (![System.IO.File]::Exists($nuspecFilePath)) {
echo "File $nuspecFilePath does not exist!"
exit 1
}

# Select-Xml doesn't want to work for whatever reason
#$dependencies = Select-Xml -Path $nuspecFilePath -XPath "//dependency"

$xml = ([xml](Get-Content -Path $nuspecFilePath))
$dependencies = $xml.ChildNodes[1].ChildNodes.dependencies.group.dependency.id

foreach ($dep in $dependencies) {
if (!$dep.StartsWith($Organization)) {
continue
}

$allDependencies.Add($dep)
}
}

$allDependencies.ExceptWith($allPackages)

foreach ($missing in $allDependencies) {
echo "The following package wasn't packed: $missing"
}

if ($allDependencies.Count -ne 0) {
exit 1
} else {
echo "All packages are correct"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('NuGet.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.29.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Mutagen.Bethesda.Skyrim;

namespace NexusMods.App.UI.RightContent.LoadoutGrid.Columns;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using NexusMods.DataModel.Abstractions;
using NexusMods.DataModel.Loadouts;
using NexusMods.DataModel.Loadouts.Cursors;
using Noggog;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

Expand Down
1 change: 1 addition & 0 deletions src/NexusMods.App/NexusMods.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Games\NexusMods.Games.BethesdaGameStudios\NexusMods.Games.BethesdaGameStudios.csproj" />
<ProjectReference Include="..\Games\NexusMods.Games.DarkestDungeon\NexusMods.Games.DarkestDungeon.csproj" />
<ProjectReference Include="..\Games\NexusMods.Games.StardewValley\NexusMods.Games.StardewValley.csproj" />
<ProjectReference Include="..\Games\NexusMods.Games.FOMOD\NexusMods.Games.FOMOD.csproj" />
Expand Down
4 changes: 3 additions & 1 deletion src/NexusMods.CLI/NexusMods.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- NuGet Package Shared Details -->
<Import Project="$([MSBuild]::GetPathOfFileAbove('NuGet.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchiveManagement\NexusMods.FileExtractor\NexusMods.FileExtractor.csproj" />
<ProjectReference Include="..\Games\NexusMods.Games.BethesdaGameStudios\NexusMods.Games.BethesdaGameStudios.csproj" />
<ProjectReference Include="..\NexusMods.DataModel\NexusMods.DataModel.csproj" />
<ProjectReference Include="..\NexusMods.Paths\NexusMods.Paths.csproj" />
<ProjectReference Include="..\NexusMods.StandardGameLocators\NexusMods.StandardGameLocators.csproj" />
Expand Down

0 comments on commit 1957a8e

Please sign in to comment.