Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 844b253

Browse files
authored
Publish release and NuGet package (#11)
1 parent ac2e2ea commit 844b253

18 files changed

+425
-18
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Build And Test Action"
2+
description: "Builds and Tests bindle-dotnet"
3+
inputs:
4+
configuration:
5+
description: 'The Configration to build and test'
6+
required: true
7+
default: 'release'
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Restore dependencies
12+
run: dotnet restore
13+
shell: bash
14+
- name: Set MINVERBUILDMETADATA
15+
run: echo MINVERBUILDMETADATA=$(git rev-parse --short ${GITHUB_SHA}) >> $GITHUB_ENV
16+
shell: bash
17+
- name: Build
18+
run: dotnet build -c ${{ inputs.configuration }}
19+
shell: bash
20+
- name: Build Bindle
21+
run: make build
22+
working-directory: bindleserver
23+
shell: bash
24+
- name: Test
25+
env:
26+
BINDLE_SERVER_PATH: ../../../../bindleserver/target/debug
27+
run: dotnet test
28+
shell: bash
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: dotnet
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+'
7+
- '[0-9]+.[0-9]+.[0-9]+-preview'
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
if: ${{ github.event_name == 'pull_request' }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
build: [linux-debug, linux-release, macos-debug, macos-release, windows-debug, windows-release]
20+
include:
21+
- build: linux-debug
22+
os: ubuntu-latest
23+
config: debug
24+
- build: linux-release
25+
os: ubuntu-latest
26+
config: release
27+
- build: macos-debug
28+
os: macos-latest
29+
config: debug
30+
- build: macos-release
31+
os: macos-latest
32+
config: release
33+
- build: windows-debug
34+
os: windows-latest
35+
config: debug
36+
- build: windows-release
37+
os: windows-latest
38+
config: release
39+
40+
steps:
41+
- name: Fetch Source
42+
uses: actions/checkout@v2
43+
with:
44+
fetch-depth: 0
45+
- name: Get Bindle source for testing
46+
uses: actions/checkout@v2
47+
with:
48+
repository: deislabs/bindle
49+
path: bindleserver
50+
ref: main
51+
- name: Setup dotnet
52+
uses: actions/setup-dotnet@v1
53+
with:
54+
dotnet-version: 5.0.x
55+
- uses: ./.github/workflows/build-and-test
56+
with:
57+
configuration: ${{ matrix.config }}
58+
publish:
59+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Fetch Source
63+
uses: actions/checkout@v2
64+
with:
65+
fetch-depth: 0
66+
- name: Get Bindle source for testing
67+
uses: actions/checkout@v2
68+
with:
69+
repository: deislabs/bindle
70+
path: bindleserver
71+
ref: main
72+
- name: Setup dotnet
73+
uses: actions/setup-dotnet@v1
74+
with:
75+
dotnet-version: 5.0.x
76+
- uses: ./.github/workflows/build-and-test
77+
with:
78+
configuration: Release
79+
- name: Publish Github Packages
80+
run: |
81+
for nupkg in $(find . -name *.nupkg)
82+
do
83+
echo Pushing $nupkg
84+
dotnet nuget push $nupkg --api-key ${{ secrets.GHPACKAGES_PAT }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
85+
done
86+
shell: bash
87+
release:
88+
if: startsWith(github.ref, 'refs/tags/')
89+
runs-on: ubuntu-latest
90+
steps:
91+
- name: Fetch Source
92+
uses: actions/checkout@v2
93+
with:
94+
fetch-depth: 0
95+
- name: Get Bindle source for testing
96+
uses: actions/checkout@v2
97+
with:
98+
repository: deislabs/bindle
99+
path: bindleserver
100+
ref: main
101+
- name: Setup dotnet
102+
uses: actions/setup-dotnet@v1
103+
with:
104+
dotnet-version: 5.0.x
105+
- uses: ./.github/workflows/build-and-test
106+
with:
107+
configuration: Release
108+
- name: "Build Changelog"
109+
id: github_release
110+
uses: mikepenz/release-changelog-builder-action@main
111+
with:
112+
configuration: ".github/workflows/configuration.json"
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
- name: Create Release
116+
uses: actions/create-release@v1
117+
with:
118+
tag_name: ${{ github.ref }}
119+
release_name: ${{ github.ref }}
120+
body: ${{ steps.github_release.outputs.changelog }}
121+
prerelease: ${{ contains(github.ref, '-preview') }}
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
- name: Publish Github Packages
125+
run: |
126+
for nupkg in $(find . -name *.nupkg)
127+
do
128+
echo Pushing $nupkg
129+
dotnet nuget push $nupkg --api-key ${{ secrets.GHPACKAGES_PAT }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
130+
done
131+
shell: bash
132+
- name: Publish Nuget Packages
133+
run: |
134+
for nupkg in $(find . -name *.nupkg)
135+
do
136+
echo Pushing $nupkg
137+
dotnet nuget push $nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
138+
done
139+
shell: bash
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"categories": [
3+
{
4+
"title": "## 🚀 Features",
5+
"labels": [
6+
"feature",
7+
"enhancement"
8+
]
9+
},
10+
{
11+
"title": "## 🐛 Fixes",
12+
"labels": [
13+
"fix",
14+
"bug"
15+
]
16+
},
17+
{
18+
"title": "## 🧪 Tests",
19+
"labels": [
20+
"test"
21+
]
22+
},
23+
{
24+
"title": "## 📦 Dependencies",
25+
"labels": [
26+
"dependencies"
27+
]
28+
},
29+
{
30+
"title": "## 🏷️ Uncategorized",
31+
"labels": []
32+
}
33+
]
34+
}

Bindle.Tests/Bindle.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
1111
<PackageReference Include="xunit" Version="2.4.1" />
1212
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
16-
<PackageReference Include="coverlet.collector" Version="1.3.0">
16+
<PackageReference Include="coverlet.collector" Version="3.0.3">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>

Bindle.Tests/Integration.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Threading.Tasks;
43
using Xunit;
4+
using static Deislabs.Bindle.GetInvoiceOptions;
55

6-
using static Bindle.GetInvoiceOptions;
7-
8-
namespace Bindle.Tests
6+
namespace Deislabs.Bindle.Tests
97
{
108
// To run this against the data assumed in the integration tests, run the Bindle server
119
// to serve files on port 14044 from the test/data directory. If you have Rust installed you can
1210
// do by cloning the Bindle repo and running:
1311
//
1412
// RUST_LOG=info cargo run --bin bindle-server --features="cli" -- -i 127.0.0.1:14044 -d <this_repo>/Bindle.Tests/data
1513

16-
public class Integration
14+
// 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
15+
// 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"
16+
17+
[TestCaseOrderer("Deislabs.Bindle.Tests.TestPriorityOrderer", "Bindle.Tests")]
18+
public class Integration : IClassFixture<IntegrationFixture>
1719
{
1820
const string DEMO_SERVER_URL = "http://localhost:14044/v1";
1921

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

104+
// Make sure CanYankInvoice runs after CanCreateInvoice
104105
[Fact]
106+
[TestPriority(10)]
105107
public async Task CanYankInvoice()
106108
{
107109
var client = new BindleClient(DEMO_SERVER_URL);
108-
await client.YankInvoice("your/fancy/bindle/0.3.0"); // TODO: use one that doesn't conflict with CanFetchInvoice (because Xunit parallelisation)
109-
await Assert.ThrowsAsync<BindleYankedException>(async () => {
110+
await client.YankInvoice("your/fancy/bindle/0.3.0");
111+
await Assert.ThrowsAsync<BindleYankedException>(async () =>
112+
{
110113
await client.GetInvoice("your/fancy/bindle/0.3.0");
111114
});
112115
var invoice = await client.GetInvoice("your/fancy/bindle/0.3.0", IncludeYanked);

Bindle.Tests/IntegrationFixture.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Threading;
5+
using Xunit;
6+
7+
namespace Deislabs.Bindle.Tests
8+
{
9+
public class IntegrationFixture : IDisposable
10+
{
11+
private readonly Process process;
12+
private readonly string dataPath;
13+
private readonly string testDataCopy;
14+
15+
// private readonly string[] testDirs;
16+
public IntegrationFixture()
17+
{
18+
var bindlePath = Environment.GetEnvironmentVariable("BINDLE_SERVER_PATH");
19+
if (!string.IsNullOrEmpty(bindlePath))
20+
{
21+
var fullPath = Path.GetFullPath(Path.Join(bindlePath, "bindle-server"));
22+
dataPath = Path.GetFullPath(Path.Join("../../../data"));
23+
Console.WriteLine($"Using Bindle Server Path: {fullPath}");
24+
Console.WriteLine($"Using Test Data Path: {dataPath}");
25+
26+
// Take a copy of the test data to be used by the tests
27+
testDataCopy = $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}/test-data-copy";
28+
Console.WriteLine($"Copying Test Data to: {testDataCopy}");
29+
CopyDirectory(dataPath, testDataCopy);
30+
31+
var psi = new ProcessStartInfo
32+
{
33+
FileName = fullPath,
34+
Arguments = $"-i 127.0.0.1:14044 -d {dataPath}",
35+
UseShellExecute = false,
36+
CreateNoWindow = true,
37+
RedirectStandardError = true,
38+
RedirectStandardOutput = true
39+
};
40+
psi.Environment["RUST_LOG"] = "info";
41+
process = new Process
42+
{
43+
StartInfo = psi
44+
};
45+
process.OutputDataReceived += (sender, e) =>
46+
{
47+
if (!String.IsNullOrEmpty(e.Data))
48+
{
49+
Console.WriteLine(e.Data);
50+
}
51+
};
52+
process.ErrorDataReceived += (sender, e) =>
53+
{
54+
if (!String.IsNullOrEmpty(e.Data))
55+
{
56+
Console.WriteLine(e.Data);
57+
}
58+
};
59+
process.Start();
60+
process.BeginErrorReadLine();
61+
process.BeginOutputReadLine();
62+
// TODO: something a bit less crappy that this to wait for server to start:
63+
Thread.Sleep(5000);
64+
Assert.False(process.HasExited);
65+
}
66+
}
67+
68+
public void Dispose()
69+
{
70+
// Stop the bindle server
71+
try
72+
{
73+
process?.Kill();
74+
}
75+
catch (Exception ex)
76+
{
77+
Console.WriteLine($"Failed to stop bindle process:{ex}");
78+
}
79+
80+
// Revert the modifications to test data
81+
82+
var testOutput = $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}/test-output";
83+
Console.WriteLine($"Copying Test Output to: {testOutput}");
84+
85+
// Copy the output of the test to the temp directory and then delete it and replace with the original, then delete the copies
86+
87+
CopyDirectory(dataPath, testOutput);
88+
Directory.Delete(dataPath, true);
89+
CopyDirectory(testDataCopy, dataPath);
90+
Directory.Delete(testDataCopy, true);
91+
Directory.Delete(testOutput, true);
92+
}
93+
94+
private void CopyDirectory(string source, string dest)
95+
{
96+
Directory.CreateDirectory(dest);
97+
foreach (var file in Directory.GetFiles(source))
98+
{
99+
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), true);
100+
}
101+
102+
foreach (var dir in Directory.GetDirectories(source))
103+
{
104+
CopyDirectory(dir, Path.Combine(dest, Path.GetFileName(dir)));
105+
}
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)