Skip to content

Commit

Permalink
Add NuGet GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Aug 12, 2024
1 parent cfac43e commit f145504
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 11 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# Based on Gerald Barre's blog post: https://www.meziantou.net/publishing-a-nuget-package-following-best-practices-using-github.htm

name: publish
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
release:
types:
- published # Run the workflow when a new GitHub release is published

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget

defaults:
run:
shell: pwsh

jobs:
create_nuget:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4

# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }} /p:ContinuousIntegrationBuild=true

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg

validate_nuget:
runs-on: ubuntu-latest
needs: [ create_nuget ]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Install nuget validator
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global

# Validate metadata and content of the NuGet package
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")

run_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Run tests
run: dotnet test --configuration Release

deploy:
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [ validate_nuget, run_test ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
uses: actions/setup-dotnet@v4

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
10 changes: 5 additions & 5 deletions DBCD.IO/Common/OrderedHashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ bool ICollection<T>.IsReadOnly
}

/// <summary>
/// Add item to this hashset. This is the explicit implementation of the ICollection<T>
/// Add item to this hashset. This is the explicit implementation of the ICollection{T}
/// interface. The other Add method returns bool indicating whether item was added.
/// </summary>
/// <param name="item">item to add</param>
Expand Down Expand Up @@ -454,10 +454,10 @@ private int InternalIndexOf(T item)
}

/// <summary>
/// Returns the zero-based index of the first occurrence of a value in the <see cref="OrderedHashSet<T>"/> or in a portion of it.
/// Returns the zero-based index of the first occurrence of a value in the <see cref="OrderedHashSet{T}"/> or in a portion of it.
/// </summary>
/// <param name="item">The object to locate in the <see cref="OrderedHashSet<T>"/> .</param>
/// <returns>The zero-based index of the first occurrence of item within the range of elements in the <see cref="OrderedHashSet<T>"/> that extends from index to the last element, if found; otherwise, -1.</returns>
/// <param name="item">The object to locate in the <see cref="OrderedHashSet{T}"/> .</param>
/// <returns>The zero-based index of the first occurrence of item within the range of elements in the <see cref="OrderedHashSet{T}"/> that extends from index to the last element, if found; otherwise, -1.</returns>
public int IndexOf(T item) => InternalIndexOf(item);

/// <summary>
Expand Down Expand Up @@ -972,7 +972,7 @@ private void IncreaseCapacity()
/// Add item to this HashSet. Returns bool indicating whether item was added (won't be
/// added if already present)
/// </summary>
/// <param name="item"></param>
/// <param name="value"></param>
/// <returns>true if added, false if already present</returns>
public bool Add(T value)
{
Expand Down
2 changes: 0 additions & 2 deletions DBCD.IO/DBCD.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Version>2.0.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
5 changes: 3 additions & 2 deletions DBCD.IO/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ public static T Read<T>(this BinaryReader reader) where T : struct
/// <summary>
/// Reads a NUL-separated string table from the current stream
/// </summary>
/// <param name="StringTableSize">Size of the string table</param>
/// <param name="reader">BinaryReader instance</param>
/// <param name="stringTableSize">Size of the string table</param>
/// <param name="usePos">Use WDC2-style position-base table key numbering</param>
/// <param name="BaseOffset">Base offset to use for the string table keys</param>
/// <param name="baseOffset">Base offset to use for the string table keys</param>
public static Dictionary<long, string> ReadStringTable(this BinaryReader reader, int stringTableSize, int baseOffset = 0, bool usePos = false)
{
var StringTable = new Dictionary<long, string>(stringTableSize / 0x20);
Expand Down
2 changes: 0 additions & 2 deletions DBCD/DBCD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Version>2.0.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
32 changes: 32 additions & 0 deletions Directory.build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project>
<PropertyGroup>
<DebugType>portable</DebugType>
<LangVersion>latest</LangVersion>
<Version>2.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<Authors>WoWDev</Authors>
<Description>Library for reading/writing World of Warcraft's DBC/DB2 files</Description>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/wowdev/DBCD.git</RepositoryUrl>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>library,DBC,DB2,World of Warcraft</PackageTags>
<PackageProjectUrl>https://github.com/wowdev/DBCD</PackageProjectUrl>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Directory.build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>

<!-- Workaround to ensure deterministic builds https://github.com/dotnet/sourcelink/issues/572 -->
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
<ItemGroup>
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)"/>
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ C# library for reading and writing [DBC](https://wowdev.wiki/DBC)/[DB2](https://
- Experimental writing (`WDC3` works, the others likely will too but are largely untested with actual WoW clients).
- Applying of hotfixes (DBCache.bin).

## Projects
### DBCD
Contains the glue between DBCD.IO, DBDefsLib and the providers.

### DBCD.IO
Contains the actual reading and writing of DBC/DB2 files.

## Limitations
- _(Reading/Writing)_ Relies on [WoWDBDefs](https://github.com/wowdev/WoWDBDefs) (DBDs) for table structures, can not load tables without DBDs (yet).
- _(Writing)_ Does not support writing out DB2s with multiple sections.
Expand Down

0 comments on commit f145504

Please sign in to comment.