Skip to content

Commit 5a63ec9

Browse files
webwarrior-wsknocte
authored andcommitted
GithubCI: build nuget packages
* Generate & upload stable release package for tags. * Upload pre-release versions for main branch commits, using nugetPreRelease.fsx to get a version number that includes the date and commit hash inside it. These packages will only be valid for the GTK platform so when building against nonLinux platforms the consumers of Lima will need to switch to restore and link to MAUI nuget packages (instead of LIMA) at compile time.
1 parent 0685340 commit 5a63ec9

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

.github/workflows/build-gtk.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,31 @@ jobs:
2929
chmod 764 $WORKLOAD_MANIFEST_DIR/*
3030
dotnet workload search
3131
dotnet workload install gtk --skip-manifest-update
32+
- name: Generate pre-release version suffix
33+
run: dotnet fsi nugetPreRelease.fsx "" > PreReleaseVersionSuffix.txt
3234
- name: Build MAUI
3335
run: |
3436
sed -i 's/_IncludeAndroid>true/_IncludeAndroid>/g' Directory.Build.Override.props
3537
dotnet build Microsoft.Maui.BuildTasks.slnf
36-
dotnet build Microsoft.Maui.Gtk.slnf
37-
- name: Build ZXing.Net.Maui
38+
dotnet build -c Release Lima.slnf
39+
- name: Pack MAUI
40+
run: dotnet pack Lima.slnf
41+
- name: Compare nuget package versions with GitInfo.txt version (sanity check)
3842
run: |
39-
dotnet build ./src/ZXing.Net.Maui/ZXing.Net.MAUI/ZXing.Net.MAUI.csproj --framework=net8.0-gtk
40-
dotnet build ./src/ZXing.Net.Maui/ZXing.Net.MAUI.Controls/ZXing.Net.MAUI.Controls.csproj --framework=net8.0-gtk
43+
version_prefix=$(cat GitInfo.txt | tr -d '\n' | cut -d'-' -f1)
44+
# fail if at least one of *.nupkg files' names' version portion doesn't start with version string stored in GitInfo.txt
45+
# ( and ) have to be escaped when used in find command regex
46+
count=$(find . -type f -name "*.nupkg" ! -regex "\(.*\/\)*\([a-zA-Z]+\.\)+${version_prefix}.*" | wc -l)
47+
if [ "$count" -gt 0 ]; then
48+
echo "Packages have versions that are inconsistent with version stored in GitInfo.txt. Aborting."
49+
exit 1
50+
fi
51+
- name: Upload binaries to nuget (if tag or main branch, and nugetKey is present)
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
NUGET_KEY: ${{ secrets.NUGET_KEY }}
55+
if: ${{ env.NUGET_KEY != '' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
56+
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
4157

4258
dotnet-format:
4359
needs: build_and_test

Lima.slnf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"solution": {
3+
"path": "Microsoft.Maui.sln",
4+
"projects": [
5+
"src\\BlazorWebView\\src\\Maui\\Microsoft.AspNetCore.Components.WebView.Maui.csproj",
6+
"src\\Essentials\\src\\Essentials.csproj",
7+
"src\\Controls\\src\\Core\\Controls.Core.csproj",
8+
"src\\Controls\\src\\Xaml\\Controls.Xaml.csproj",
9+
"src\\Core\\src\\Core.csproj",
10+
"src\\Compatibility\\Core\\src\\Compatibility.csproj",
11+
"src\\Controls\\Foldable\\src\\Controls.Foldable.csproj",
12+
"src\\Graphics\\src\\Graphics\\Graphics.csproj",
13+
"src\\Graphics\\src\\Graphics.Gtk\\Graphics.Gtk.csproj"
14+
]
15+
}
16+
}

eng/Versions.targets

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</Target>
4949
<Target Name="SetVersions" BeforeTargets="$(SetVersionsBefore)" DependsOnTargets="$(SetVersionsDependsOn)" Returns="$(Version)">
5050
<PropertyGroup>
51+
<GitTag Condition="$(GITHUB_REF_TYPE) == 'tag'">$(GITHUB_REF_NAME)</GitTag>
5152
<SemVerLabel>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(RegexTag)))</SemVerLabel>
5253
<GitDefaultBranch>main</GitDefaultBranch>
5354
<GitIgnoreBranchVersion>true</GitIgnoreBranchVersion>
@@ -64,13 +65,17 @@
6465

6566
<VersionMetadata Condition="'$(GitCommit)' != ''" Include="sha.$(GitCommit)"/>
6667

67-
<VersionMetadata Condition="$(CI)"
68+
<VersionMetadata Condition="$(CI) and '$(BUILD_BUILDID)' != ''"
6869
Include="azdo.$(BUILD_BUILDID)"/>
6970
</ItemGroup>
7071

72+
<Error Text="Git tag ($(GitTag)) != version extracted from GitInfo.txt ($(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch))"
73+
Condition="'$(GitTag)' != '' and '$(GitTag)' != '$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)'">
74+
</Error>
75+
7176
<PropertyGroup>
7277
<VersionMetadataLabel>@(VersionMetadata -> '%(Identity)', '-')</VersionMetadataLabel>
73-
<VersionMetadataPlusLabel Condition="'$(VersionMetadataLabel)' != ''">+$(VersionMetadataLabel)</VersionMetadataPlusLabel>
78+
<VersionMetadataPlusLabel Condition="'$(VersionMetadataLabel)' != ''">0+$(VersionMetadataLabel)</VersionMetadataPlusLabel>
7479
<Version>$(GitBaseVersionMajor).$(GitBaseVersionMinor).$(GitBaseVersionPatch)</Version>
7580
<PackageReferenceVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageReferenceVersion>
7681
<PackageReferenceVersion Condition="$(CI) and '$(GitSemVerDashLabel)' != ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitBaseVersionPatch)$(GitSemVerDashLabel).$(BUILDVERSION)</PackageReferenceVersion>
@@ -79,6 +84,11 @@
7984
<VSComponentVersion Condition="$(CI) and '$(GitSemVerDashLabel)' != ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitBaseVersionPatch).$(BUILDVERSION)</VSComponentVersion>
8085
<VSComponentVersion Condition="$(CI) and '$(GitSemVerDashLabel)' == ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch).0</VSComponentVersion>
8186
<PackageVersion>$(PackageReferenceVersion)$(VersionMetadataPlusLabel)</PackageVersion>
87+
<!-- Generate stable release package for tags -->
88+
<PackageVersion Condition=" '$(GitTag)' != '' ">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</PackageVersion>
89+
<!-- Pre-release version for other cases -->
90+
<PreReleaseVersionSuffix>$([System.IO.File]::ReadAllText($(MSBuildThisFileDirectory)../PreReleaseVersionSuffix.txt))</PreReleaseVersionSuffix>
91+
<PackageVersion Condition="$(CI) and '$(GitTag)' == '' ">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(PreReleaseVersionSuffix)</PackageVersion>
8292
</PropertyGroup>
8393

8494
<PropertyGroup>

nugetPreRelease.fsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#r "nuget: Fsdk, Version=0.6.0--date20231213-0703.git-d7a5962"
2+
3+
let args = fsi.CommandLineArgs
4+
5+
Fsdk.Network.GetNugetPrereleaseVersionFromBaseVersion args.[1]
6+
|> System.Console.WriteLine

src/Graphics/src/Graphics.Gtk/Graphics.Gtk.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.1;netstandard2.0;$(_MauiDotNetTfm)-gtk</TargetFrameworks>
55
<RootNamespace>Microsoft.Maui.Graphics.Gtk</RootNamespace>
6+
<PackageId>Lima.Graphics.Gtk</PackageId>
67
</PropertyGroup>
78
<PropertyGroup>
89
<Nullable>enable</Nullable>

0 commit comments

Comments
 (0)