Skip to content

Commit

Permalink
Merge pull request #35 from nblumhardt/create-tool-package
Browse files Browse the repository at this point in the history
Package and publish as a `dotnet tool` package
  • Loading branch information
nblumhardt authored May 22, 2024
2 parents 44c3e7b + ac3de62 commit 50e7f50
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
12 changes: 10 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Write-Output "build: Project .csproj file is located at $project"

Write-Output "build: Getting Version from $project"
$xml = [Xml](Get-Content $project)
$prefix = [Version]$xml.Project.PropertyGroup.VersionPrefix.ToString()
$prefix = [Version]$xml.Project.PropertyGroup[0].VersionPrefix.ToString()
Write-Output "build: Version prefix is $prefix"

Write-Output "build: Calculating `$branch, `$revision, and `$suffix"
Expand All @@ -78,14 +78,22 @@ Write-Output "build: Version is $version"
Write-Output "build: Creating artifacts directory at .\$artifacts"
New-Item -ItemType "directory" -Name $artifacts

Write-Output "build: Packing library into .nupkg"
Write-Output "build: Packing library into Datalust.Piggy.*.nupkg"
if ($suffix) {
& dotnet pack $project -c Release -o $PSScriptRoot/$artifacts /p:OutputType=Library --version-suffix=$suffix
} else {
& dotnet pack $project -c Release -o $PSScriptRoot/$artifacts /p:OutputType=Library
}
if($LASTEXITCODE -ne 0) { exit 11 }

Write-Output "build: Packing executable into dotnet tool Datalust.Piggy.Cli.*.nupkg"
if ($suffix) {
& dotnet pack $project -c Release -o $PSScriptRoot/$artifacts /p:PackAsTool=True --version-suffix=$suffix
} else {
& dotnet pack $project -c Release -o $PSScriptRoot/$artifacts /p:PackAsTool=True
}
if($LASTEXITCODE -ne 0) { exit 11 }

$rids = @("win-x64", "linux-x64", "osx-x64", "osx-arm64")
foreach ($rid in $rids) {
Write-Output "build: Building a $rid build of version $version"
Expand Down
46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,38 @@ Piggy is a simple command-line tool for managing schema and data changes to Post

### Installation

Piggy is available for Windows, macOS and Linux from [the releases page](https://github.com/datalust/piggy/releases). If your platform of choice isn't listed, please [raise an issue here](https://github.com/datalust/piggy/issues) so that we can add it.
Piggy is available as a .NET tool package, as standalone binaries, and as a C♯ library that can be used directly in .NET applications.

#### `dotnet tool`

Piggy is distributed as a [.NET tool package called _Datalust.Piggy.Cli_](https://nuget.org/packages/datalust.piggy.cli), which can be installed using:

```
dotnet tool install --global Datalust.Piggy.Cli
```

The executable is called `piggy`. Test that the installation was successful with:

```
piggy version
```

#### Executable binaries

Pre-built, native, self-contained Piggy binaries are available for Windows, macOS and Linux from [the releases page](https://github.com/datalust/piggy/releases). If your platform of choice isn't listed, please [raise an issue here](https://github.com/datalust/piggy/issues) so that we can add it.

#### C# library

For development and test automation purposes, the core script runner is also packaged as a C♯ API and [published to NuGet as _Datalust.Piggy_](https://nuget.org/packages/datalust.piggy).

```csharp
// dotnet add package Datalust.Piggy
var connectionString = // Npgsql connection string
using (var connection = DatabaseConnector.Connect(connectionString))
{
UpdateSession.ApplyChangeScripts(connection, "./db", new Dictionary<string, string>());
}
```

### Workflow

Expand Down Expand Up @@ -100,16 +131,3 @@ Available commands are:
Type `piggy help <command>` for detailed help
```

### C&sharp; API

For development and test automation purposes, the core script runner is also packaged as a C&sharp; API and published to NuGet as _Datalust.Piggy_.

```csharp
// dotnet add package Datalust.Piggy
var connectionString = // Npgsql connection string
using (var connection = DatabaseConnector.Connect(connectionString))
{
UpdateSession.ApplyChangeScripts(connection, "./db", new Dictionary<string, string>());
}
```
6 changes: 6 additions & 0 deletions src/Datalust.Piggy/Datalust.Piggy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(PackAsTool)' == 'True' ">
<PackageId>Datalust.Piggy.Cli</PackageId>
<ToolCommandName>piggy</ToolCommandName>
<RollForward>Major</RollForward>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\asset\Piggy-Icon-128px.png" Pack="true" Visible="false" PackagePath="" />
Expand Down

0 comments on commit 50e7f50

Please sign in to comment.