Skip to content

Commit

Permalink
Publish release and NuGet package (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
simongdavies authored Jul 20, 2021
1 parent ac2e2ea commit 844b253
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 18 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-and-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Build And Test Action"
description: "Builds and Tests bindle-dotnet"
inputs:
configuration:
description: 'The Configration to build and test'
required: true
default: 'release'
runs:
using: "composite"
steps:
- name: Restore dependencies
run: dotnet restore
shell: bash
- name: Set MINVERBUILDMETADATA
run: echo MINVERBUILDMETADATA=$(git rev-parse --short ${GITHUB_SHA}) >> $GITHUB_ENV
shell: bash
- name: Build
run: dotnet build -c ${{ inputs.configuration }}
shell: bash
- name: Build Bindle
run: make build
working-directory: bindleserver
shell: bash
- name: Test
env:
BINDLE_SERVER_PATH: ../../../../bindleserver/target/debug
run: dotnet test
shell: bash
139 changes: 139 additions & 0 deletions .github/workflows/build-publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: dotnet

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-preview'
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [linux-debug, linux-release, macos-debug, macos-release, windows-debug, windows-release]
include:
- build: linux-debug
os: ubuntu-latest
config: debug
- build: linux-release
os: ubuntu-latest
config: release
- build: macos-debug
os: macos-latest
config: debug
- build: macos-release
os: macos-latest
config: release
- build: windows-debug
os: windows-latest
config: debug
- build: windows-release
os: windows-latest
config: release

steps:
- name: Fetch Source
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Bindle source for testing
uses: actions/checkout@v2
with:
repository: deislabs/bindle
path: bindleserver
ref: main
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- uses: ./.github/workflows/build-and-test
with:
configuration: ${{ matrix.config }}
publish:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- name: Fetch Source
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Bindle source for testing
uses: actions/checkout@v2
with:
repository: deislabs/bindle
path: bindleserver
ref: main
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- uses: ./.github/workflows/build-and-test
with:
configuration: Release
- name: Publish Github Packages
run: |
for nupkg in $(find . -name *.nupkg)
do
echo Pushing $nupkg
dotnet nuget push $nupkg --api-key ${{ secrets.GHPACKAGES_PAT }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
done
shell: bash
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Fetch Source
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Bindle source for testing
uses: actions/checkout@v2
with:
repository: deislabs/bindle
path: bindleserver
ref: main
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- uses: ./.github/workflows/build-and-test
with:
configuration: Release
- name: "Build Changelog"
id: github_release
uses: mikepenz/release-changelog-builder-action@main
with:
configuration: ".github/workflows/configuration.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{ steps.github_release.outputs.changelog }}
prerelease: ${{ contains(github.ref, '-preview') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Github Packages
run: |
for nupkg in $(find . -name *.nupkg)
do
echo Pushing $nupkg
dotnet nuget push $nupkg --api-key ${{ secrets.GHPACKAGES_PAT }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
done
shell: bash
- name: Publish Nuget Packages
run: |
for nupkg in $(find . -name *.nupkg)
do
echo Pushing $nupkg
dotnet nuget push $nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
done
shell: bash
34 changes: 34 additions & 0 deletions .github/workflows/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": [
"feature",
"enhancement"
]
},
{
"title": "## 🐛 Fixes",
"labels": [
"fix",
"bug"
]
},
{
"title": "## 🧪 Tests",
"labels": [
"test"
]
},
{
"title": "## 📦 Dependencies",
"labels": [
"dependencies"
]
},
{
"title": "## 🏷️ Uncategorized",
"labels": []
}
]
}
4 changes: 2 additions & 2 deletions Bindle.Tests/Bindle.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
21 changes: 12 additions & 9 deletions Bindle.Tests/Integration.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using static Deislabs.Bindle.GetInvoiceOptions;

using static Bindle.GetInvoiceOptions;

namespace Bindle.Tests
namespace Deislabs.Bindle.Tests
{
// To run this against the data assumed in the integration tests, run the Bindle server
// to serve files on port 14044 from the test/data directory. If you have Rust installed you can
// do by cloning the Bindle repo and running:
//
// RUST_LOG=info cargo run --bin bindle-server --features="cli" -- -i 127.0.0.1:14044 -d <this_repo>/Bindle.Tests/data

public class Integration
// Alternatively if you set the variable BINDLE_SERVER_PATH to the relative path of bindle-server then the test will start and stop the server automatically
// e.g. if bindle is in a peer directory to bindle-dotnet and the debug build is being used then set the variable to "../../../../../bindle/target/debug"

[TestCaseOrderer("Deislabs.Bindle.Tests.TestPriorityOrderer", "Bindle.Tests")]
public class Integration : IClassFixture<IntegrationFixture>
{
const string DEMO_SERVER_URL = "http://localhost:14044/v1";

Expand Down Expand Up @@ -44,8 +46,6 @@ public async Task CanFetchYankedInvoices()
[Fact]
public async Task CanCreateInvoices()
{
// TODO: this results in creating the invoice, so it can't be run twice!
// For now you need to delete test/data/invoices/8fb420... and restart the Bindle server
var client = new BindleClient(DEMO_SERVER_URL);
var invoice = new Invoice(
bindleVersion: "1.0.0",
Expand Down Expand Up @@ -101,12 +101,15 @@ public async Task CanCreateInvoices()
Assert.Equal(invoice.Groups.Count, fetched.Groups.Count);
}

// Make sure CanYankInvoice runs after CanCreateInvoice
[Fact]
[TestPriority(10)]
public async Task CanYankInvoice()
{
var client = new BindleClient(DEMO_SERVER_URL);
await client.YankInvoice("your/fancy/bindle/0.3.0"); // TODO: use one that doesn't conflict with CanFetchInvoice (because Xunit parallelisation)
await Assert.ThrowsAsync<BindleYankedException>(async () => {
await client.YankInvoice("your/fancy/bindle/0.3.0");
await Assert.ThrowsAsync<BindleYankedException>(async () =>
{
await client.GetInvoice("your/fancy/bindle/0.3.0");
});
var invoice = await client.GetInvoice("your/fancy/bindle/0.3.0", IncludeYanked);
Expand Down
108 changes: 108 additions & 0 deletions Bindle.Tests/IntegrationFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Xunit;

namespace Deislabs.Bindle.Tests
{
public class IntegrationFixture : IDisposable
{
private readonly Process process;
private readonly string dataPath;
private readonly string testDataCopy;

// private readonly string[] testDirs;
public IntegrationFixture()
{
var bindlePath = Environment.GetEnvironmentVariable("BINDLE_SERVER_PATH");
if (!string.IsNullOrEmpty(bindlePath))
{
var fullPath = Path.GetFullPath(Path.Join(bindlePath, "bindle-server"));
dataPath = Path.GetFullPath(Path.Join("../../../data"));
Console.WriteLine($"Using Bindle Server Path: {fullPath}");
Console.WriteLine($"Using Test Data Path: {dataPath}");

// Take a copy of the test data to be used by the tests
testDataCopy = $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}/test-data-copy";
Console.WriteLine($"Copying Test Data to: {testDataCopy}");
CopyDirectory(dataPath, testDataCopy);

var psi = new ProcessStartInfo
{
FileName = fullPath,
Arguments = $"-i 127.0.0.1:14044 -d {dataPath}",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
psi.Environment["RUST_LOG"] = "info";
process = new Process
{
StartInfo = psi
};
process.OutputDataReceived += (sender, e) =>
{
if (!String.IsNullOrEmpty(e.Data))
{
Console.WriteLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (!String.IsNullOrEmpty(e.Data))
{
Console.WriteLine(e.Data);
}
};
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
// TODO: something a bit less crappy that this to wait for server to start:
Thread.Sleep(5000);
Assert.False(process.HasExited);
}
}

public void Dispose()
{
// Stop the bindle server
try
{
process?.Kill();
}
catch (Exception ex)
{
Console.WriteLine($"Failed to stop bindle process:{ex}");
}

// Revert the modifications to test data

var testOutput = $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}/test-output";
Console.WriteLine($"Copying Test Output to: {testOutput}");

// Copy the output of the test to the temp directory and then delete it and replace with the original, then delete the copies

CopyDirectory(dataPath, testOutput);
Directory.Delete(dataPath, true);
CopyDirectory(testDataCopy, dataPath);
Directory.Delete(testDataCopy, true);
Directory.Delete(testOutput, true);
}

private void CopyDirectory(string source, string dest)
{
Directory.CreateDirectory(dest);
foreach (var file in Directory.GetFiles(source))
{
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), true);
}

foreach (var dir in Directory.GetDirectories(source))
{
CopyDirectory(dir, Path.Combine(dest, Path.GetFileName(dir)));
}
}
}
}
Loading

0 comments on commit 844b253

Please sign in to comment.