Skip to content
Draft
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
75 changes: 75 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Publish NuGet Package to GitHub Packages

on:
push:
branches:
- main
tags:
- "v*.*.*"

jobs:
build-and-publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"

# Derive a version from the git tag (e.g. v1.2.3 → 1.2.3).
# Falls back to 1.0.0 for plain branch pushes.
- name: Determine package version
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="1.0.0"
fi
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"

- name: Restore dependencies
run: dotnet restore src/mdz-core/mdz-core.csproj

- name: Build (Release)
run: dotnet build src/mdz-core/mdz-core.csproj --configuration Release --no-restore

# Run tests only when a test project is present
- name: Run tests
run: |
if find tests -name '*.csproj' -print -quit 2>/dev/null | grep -q .; then
dotnet test tests --configuration Release --verbosity normal
else
echo "No test projects found – skipping test step."
fi

- name: Pack
run: >
dotnet pack src/mdz-core/mdz-core.csproj
--configuration Release
--no-build
-p:Version=${{ steps.version.outputs.VERSION }}
-o out

- name: Add GitHub Packages source
run: >
dotnet nuget add source
https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
--name github
--username ${{ github.actor }}
--password ${{ secrets.GITHUB_TOKEN }}
--store-password-in-clear-text

- name: Publish to GitHub Packages
run: >
dotnet nuget push out/*.nupkg
--source github
--api-key ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ CodeCoverage/
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
nunit-*.xml

# Pack output (dotnet pack -o out)
out/
24 changes: 24 additions & 0 deletions src/mdz-core/mdz-core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

<!-- NuGet package metadata -->
<PackageId>mdz-core</PackageId>
<Version>1.0.0</Version>
<Authors><!-- TODO: your name or org --></Authors>
<Company><!-- TODO: your company --></Company>
<Description>Core library assembly for the .mdz format.</Description>
<RepositoryUrl>https://github.com/kylemwhite/mdz-core</RepositoryUrl>
<RepositoryType>git</RepositoryType>

<!-- Pack manually via `dotnet pack`; do not pack on every build -->
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

<!-- Publish to GitHub Packages (private) -->
<IsPackable>true</IsPackable>
</PropertyGroup>

</Project>