Skip to content

Commit

Permalink
NUKE fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa committed Sep 5, 2024
1 parent 8578341 commit 7469252
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 45 deletions.
4 changes: 1 addition & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

<PropertyGroup>
<PackageVersion>0.2.0</PackageVersion>
<PackageVersionSuffix Condition="'$(APPVEYOR)' == 'True'">-build.$(APPVEYOR_BUILD_NUMBER)+$(APPVEYOR_REPO_COMMIT.Substring(0, 7))</PackageVersionSuffix>
<PackageVersionSuffix Condition="'$(PackageVersionSuffix)' == '' AND '$(DesignTimeBuild)' != 'True'">-localbuild$([System.DateTime]::Now.ToString("yyyyMMddHHmmss"))</PackageVersionSuffix>
<PackageVersionSuffix Condition="'$(APPVEYOR_REPO_TAG)' == 'True'"></PackageVersionSuffix>
<PackageVersionSuffix Condition="'$(CI)' != 'True' AND '$(PackageVersionSuffix)' == '' AND '$(DesignTimeBuild)' != 'True'">-localbuild$([System.DateTime]::Now.ToString("yyyyMMddHHmmss"))</PackageVersionSuffix>
</PropertyGroup>

<ItemGroup>
Expand Down
104 changes: 62 additions & 42 deletions build/_build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ TagName is not null
IsLocalBuild
? "-local"
: (
TagName is not null
? ""
TagVersion is not null
? $"-{TagVersion.Release}"
: $"-build2.{BuildNumber}+{GitHubActions.Sha[0..7]}"
);

Expand Down Expand Up @@ -133,29 +133,17 @@ TagName is not null
)
);

private Target PushMyGet => _ => _
private Target PushToMyGet => _ => _
.TriggeredBy(Pack)
.OnlyWhenStatic(
() =>
!GitHubActions.IsPullRequest
&& Configuration == Configuration.Debug
)
.Requires(() => MyGetApiKey)
.Executes(
() =>
NupkgArtifactsPath
.GetFiles()
.ForEach(
nupkg => DotNetTasks.DotNetNuGetPush(
x => x
.SetSource(MyGetFeedUrl)
.SetApiKey(MyGetApiKey)
.SetTargetPath(nupkg)
)
)
);
.Executes(() => PushToNuGetFeed(MyGetFeedUrl, MyGetApiKey!));

private Target PushNuGet => _ => _
private Target PushToNuGet => _ => _
.TriggeredBy(Pack)
.OnlyWhenStatic(
() =>
Expand All @@ -164,21 +152,11 @@ TagVersion is not null
)
.Requires(() => NuGetApiKey)
.Executes(
() =>
NupkgArtifactsPath
.GetFiles()
.ForEach(
nupkg => DotNetTasks.DotNetNuGetPush(
x => x
.SetSource(NuGetConstants.V3FeedUrl)
.SetApiKey(NuGetApiKey)
.SetTargetPath(nupkg)
)
)
() => PushToNuGetFeed(NuGetConstants.V3FeedUrl, NuGetApiKey!)
);

private Target ReleaseGitHub => _ => _
.TriggeredBy(Pack, PushNuGet)
private Target ReleaseToGitHub => _ => _
.TriggeredBy(Pack, PushToNuGet)
.OnlyWhenStatic(
() =>
TagVersion is not null
Expand All @@ -197,24 +175,53 @@ TagVersion is not null
)
);

var release = await client
.Repository
.Release
.Create(
repositoryId,
new NewRelease(TagName!)
{
Draft = true,
Name = TagName!,
Prerelease = TagVersion!.IsPrerelease
}
);
Release release;

try
{
release = await client
.Repository
.Release
.Get(repositoryId, TagName!);

if (!release.Draft)
{
return;
}
}
catch (ApiException)
{
release = await client
.Repository
.Release
.Create(
repositoryId,
new NewRelease(TagName!)
{
Draft = true,
Name = TagName!,
Prerelease = TagVersion!.IsPrerelease
}
);
}

// preserve order
foreach (var nupkg in NupkgArtifactsPath.GetFiles())
{
using var ms = new MemoryStream(nupkg.ReadAllBytes());

if (
release.Assets.Any(
x => StringEqualsOrdinalIgnoreCase(
x.Name,
nupkg.Name
)
)
)
{
continue;
}

await client
.Repository
.Release
Expand All @@ -237,6 +244,19 @@ await client.Repository.Release.Edit(
}
);

private void PushToNuGetFeed(string feedUrl, string apiKey) =>
NupkgArtifactsPath
.GetFiles()
.ForEach(
nupkg => DotNetTasks.DotNetNuGetPush(
x => x
.SetApiKey(apiKey)
.SetSkipDuplicate(true)
.SetSource(feedUrl)
.SetTargetPath(nupkg)
)
);

private static bool StringEqualsOrdinalIgnoreCase(string? x, string? y) =>
String.Equals(x, y, StringComparison.OrdinalIgnoreCase);
}

0 comments on commit 7469252

Please sign in to comment.