Skip to content

Commit

Permalink
add nuget package publish task
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilphillip-stripe committed May 8, 2024
1 parent 1b0773d commit 09009ba
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
64 changes: 57 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1

# Only one instance of this build at a time.
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: build-${{matrix.os}}
Expand All @@ -39,13 +44,58 @@ jobs:
dotnet-version: ${{ matrix.dotnet-version }}
dotnet-quality: 'ga'

# - name: Install dependencies
# run: dotnet restore

- name: Build
run: ./build compile
# dotnet build --no-restore --configuration Release

- name: Test
run: ./build test
# dotnet test --no-restore --configuration Release
# - name: Test
# run: ./build test

package:
name: create-nuget-packages
runs-on: 'ubuntu-latest'
needs: [build]

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

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-quality: 'ga'

- name: Create Packages
run: ./build pack

- name: Upload packages to artifacts
uses: actions/upload-artifact@v4
with:
name: packages
path: |
artifacts/packages/*.nupkg
artifacts/packages/*.snupkg
publish:
name: publish-packages
runs-on: 'ubuntu-latest'
needs: [package]

if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-quality: 'ga'
env:
NUGET_API_KEY: ${{ secrets.GITHUB_TOKEN }}
NUGET_SOURCE: https://nuget.pkg.github.com/cecilphillip-stripe/index.json

- name: Publish Packages
run: |
./build publish
3 changes: 2 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
</configuration>
13 changes: 6 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@

namespace ExtensionsBuild;

class Build : NukeBuild, IPack, ITest
class Build : NukeBuild, IPublish
{
public static int Main() => Execute<Build>(x => x.Print);

// string BaseExProjectName => "Stripe.Extensions";
// string StripeExDepInjectProjectName => $"{BaseExProjectName}.DependencyInjection";
// string StripeExAspNetCoreProjectName => $"{BaseExProjectName}.AspNetCore";

MinVer MinVerInfo { get; set; }
[GitRepository] GitRepository GitRepo { get; }

[Parameter] readonly string MinVerTagPrefix;
[Parameter] readonly string MinVerPreReleaseIdentifiers;
[Parameter] readonly string MinVerMinimumMajorMinor;

[Parameter] readonly string NuGetApiKey;
[Parameter] readonly string NugGetUrl;

AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "tests";
AbsolutePath SamplesDirectory => RootDirectory / "samples";
Expand Down Expand Up @@ -85,7 +84,7 @@ class Build : NukeBuild, IPack, ITest
public Configure<DotNetPackSettings> PackSettings => settings => settings
.SetVersion(MinVerInfo.Version)
.SetRepositoryUrl(GitRepo.HttpsUrl);

protected override void OnBuildInitialized()
{
base.OnBuildInitialized();
Expand All @@ -98,4 +97,4 @@ protected override void OnBuildInitialized()

MinVerInfo = version;
}
}
}

0 comments on commit 09009ba

Please sign in to comment.