Skip to content

Commit

Permalink
add github action to publish nuget package
Browse files Browse the repository at this point in the history
  • Loading branch information
eddami committed Oct 4, 2023
1 parent f37db95 commit 49987e6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
push:
tags:
- '*.*.*'
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup dotnet 6.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Push to NuGet
env:
NUGET_URL: https://api.nuget.org/v3/index.json
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: ./Push.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts/**/*
retention-days: 7
24 changes: 24 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}

$artifacts = ".\artifacts"

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

exec { & dotnet clean -c Release }

exec { & dotnet build -c Release }

exec { & dotnet test -c Release --no-build -l trx --verbosity=normal }

exec { & dotnet pack .\src\XmlTvSharp\XmlTvSharp.csproj -c Release -o $artifacts --no-build }
7 changes: 7 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
14 changes: 14 additions & 0 deletions Push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$scriptName = $MyInvocation.MyCommand.Name
$artifacts = "./artifacts"

if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
} else {
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($scriptName): Pushing $($_.Name)"
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
}
10 changes: 9 additions & 1 deletion src/XmlTvSharp/XmlTvSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
<PackageProjectUrl>https://github.com/eddami/XmlTvSharp</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/eddami/XmlTvSharp/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/eddami/XmlTvSharp</RepositoryUrl>
<PackageTags>xmltv;c-sharp-library</PackageTags>
<PackageTags>xmltv;tv;epg;xml</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>A library designed for parsing TV program data in XMLTV format with a focus on asynchronous processing and high performance.</Description>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

0 comments on commit 49987e6

Please sign in to comment.