Skip to content

Commit c72c91b

Browse files
committed
[ECO-4285] Updated github workflow to support nuget packaging
1 parent 98933e3 commit c72c91b

8 files changed

Lines changed: 164 additions & 37 deletions

File tree

.github/workflows/package.yml

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# ============================================================================
2+
# ACTIVE PACKAGING WORKFLOW - Uses Cake Build System
3+
# ============================================================================
4+
# This is the primary workflow for creating NuGet packages and Unity packages.
5+
# It replaces the legacy FAKE build system scripts (package.sh, package-push.sh).
6+
#
7+
# To create a release:
8+
# 1. Go to Actions tab → Package ably workflow
9+
# 2. Click "Run workflow" and enter the version number (e.g., 1.2.3)
10+
# 3. Download artifacts: output-package, output-package-push, output-package-unity
11+
# ============================================================================
12+
113
name: Package ably
214
on:
315
workflow_dispatch:
@@ -8,7 +20,7 @@ on:
820

921
jobs:
1022
package-library:
11-
runs-on: windows-latest
23+
runs-on: windows-2022
1224
steps:
1325
- uses: actions/checkout@v4
1426
with:
@@ -22,8 +34,39 @@ jobs:
2234
6.0.403
2335
7.0.408
2436
37+
- name: Setup Android SDK
38+
uses: android-actions/setup-android@v3
39+
40+
- name: Install Android SDK Platform 30
41+
shell: pwsh
42+
run: |
43+
echo "y" | & "$env:ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager.bat" "platforms;android-30"
44+
echo "y" | & "$env:ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager.bat" "build-tools;30.0.3"
45+
46+
- name: Install legacy Xamarin
47+
shell: pwsh
48+
run: |
49+
# Install Xamarin.Android and Xamarin.iOS components via VS installer
50+
Write-Host "Installing Xamarin workload for VS 2022..."
51+
Write-Host "This may take several minutes..."
52+
53+
& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify `
54+
--installPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" `
55+
--add Microsoft.VisualStudio.Workload.XamarinBuildTools `
56+
--add Component.Xamarin `
57+
--wait
58+
59+
Write-Host "Xamarin installation completed"
60+
61+
# Verify installation
62+
Write-Host "Verifying Xamarin.iOS targets..."
63+
Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.CSharp.targets"
64+
65+
Write-Host "Verifying Xamarin.Android targets..."
66+
Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.CSharp.targets"
67+
2568
- name: Download cake tool
26-
run: dotnet tool restore
69+
run: dotnet tool restore
2770

2871
- name: Package
2972
run: ./package-cake.cmd ${{ github.event.inputs.version }}
@@ -36,7 +79,7 @@ jobs:
3679
${{ github.workspace }}/*.nupkg
3780
3881
package-push:
39-
runs-on: macos-latest
82+
runs-on: macos-13
4083
env:
4184
DOTNET_NOLOGO: true
4285

@@ -45,6 +88,19 @@ jobs:
4588
with:
4689
submodules: 'recursive'
4790

91+
- name: Setup Xcode
92+
uses: maxim-lobanov/setup-xcode@v1
93+
with:
94+
xcode-version: '14.3'
95+
96+
- name: Setup Android SDK
97+
uses: android-actions/setup-android@v3
98+
99+
- name: Install Android SDK Platform 30
100+
run: |
101+
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platforms;android-30"
102+
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "build-tools;30.0.3"
103+
48104
- name: Download dotnet framework
49105
uses: actions/setup-dotnet@v3
50106
with:
@@ -53,13 +109,27 @@ jobs:
53109
6.0.403
54110
7.0.408
55111
112+
- name: Install Xamarin (legacy)
113+
run: |
114+
# macOS 13 runners should have Xamarin pre-installed
115+
# Verify Xamarin.iOS and Xamarin.Android are available
116+
ls -la "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/" || true
117+
ls -la "/Library/Frameworks/Xamarin.iOS.framework/" || true
118+
119+
# If not found, install via brew
120+
if [ ! -d "/Library/Frameworks/Xamarin.iOS.framework/" ]; then
121+
echo "Installing Xamarin via brew..."
122+
brew install --cask xamarin-ios || true
123+
brew install --cask xamarin-android || true
124+
fi
125+
56126
- name: Download cake tool
57-
run: dotnet tool restore
127+
run: dotnet tool restore
58128

59-
- name: Package
129+
- name: Package Push (iOS & Android)
60130
run: ./package-push-cake.sh ${{ github.event.inputs.version }}
61131

62-
- name: Archive package
132+
- name: Archive push packages
63133
uses: actions/upload-artifact@v4
64134
with:
65135
name: output-package
@@ -86,7 +156,7 @@ jobs:
86156
- name: Package Unity
87157
run: ./package-unity-cake.sh ${{ github.event.inputs.version }}
88158

89-
- name: Archive package
159+
- name: Archive Unity package
90160
uses: actions/upload-artifact@v4
91161
with:
92162
name: output-package

cake-build/helpers/paths.cake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class BuildPaths
1111
public DirectoryPath Package { get; }
1212
public DirectoryPath Lib { get; }
1313

14+
public FilePath MainSolution { get; }
1415
public FilePath NetStandardSolution { get; }
1516
public FilePath NetFrameworkSolution { get; }
1617
public FilePath XamarinSolution { get; }
@@ -20,8 +21,12 @@ public class BuildPaths
2021

2122
public BuildPaths(ICakeContext context)
2223
{
23-
// Get the actual repository root (parent of cake-build directory)
24-
Root = context.MakeAbsolute(context.Directory("../"));
24+
// Get the actual repository root
25+
var buildScriptDir = context.MakeAbsolute(context.Environment.WorkingDirectory);
26+
// Cake sets its working directory to where the build script is located (cake-build/)
27+
// So we need to go up one directory to get to the repository root
28+
Root = buildScriptDir.Combine("../").Collapse();
29+
2530
Src = Root.Combine("src");
2631
Lib = Root.Combine("lib");
2732

@@ -30,6 +35,7 @@ public class BuildPaths
3035
TestResults = BuildOutput.Combine("tests");
3136
Package = BuildOutput.Combine("package");
3237

38+
MainSolution = Src.CombineWithFilePath("IO.Ably.sln");
3339
NetStandardSolution = Src.CombineWithFilePath("IO.Ably.NetStandard.sln");
3440
NetFrameworkSolution = Src.CombineWithFilePath("IO.Ably.NetFramework.sln");
3541
XamarinSolution = Src.CombineWithFilePath("IO.Ably.Xamarin.sln");

cake-build/tasks/build.cake

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,63 @@ Task("Clean")
1212
EnsureDirectoryExists(paths.Package);
1313
});
1414

15-
Task("Restore")
16-
.Does(() =>
15+
// Helper method to restore a solution, try both nuget restore and dotnet restore
16+
void RestoreSolution(FilePath solutionPath)
1717
{
18-
Information("Restoring NuGet packages...");
19-
20-
// FAKE restores the main IO.Ably.sln solution, not IO.Ably.NetStandard.sln
21-
var mainSolution = paths.Src.CombineWithFilePath("IO.Ably.sln");
22-
23-
// Use NuGet CLI for .NET Framework projects (packages.config)
24-
// This is critical for both Windows and macOS/Linux with Mono
18+
Information($"Restoring NuGet packages for {solutionPath.GetFilename()}...");
19+
20+
// This is needed to restore deprecated Xamarin projects on Windows and macOS/Linux.
21+
// Needed for projects using old packages.config format for maintaining dependencies.
22+
// This will not be needed once deprecated projects are removed.
2523
Information("Running NuGet restore...");
2624
try
2725
{
2826
if (IsRunningOnWindows())
2927
{
30-
NuGetRestore(mainSolution.FullPath);
28+
Information("Windows system detected, running direct NuGetRestore command");
29+
NuGetRestore(solutionPath.FullPath);
3130
}
3231
else
3332
{
33+
Information("macOS/Linux system detected, running nuget restore from CLI");
3434
// On macOS/Linux, use nuget command (installed via mono)
3535
StartProcess("nuget", new ProcessSettings
3636
{
37-
Arguments = $"restore {mainSolution.FullPath}"
37+
Arguments = $"restore {solutionPath.FullPath}"
3838
});
3939
}
4040
}
4141
catch (Exception ex)
4242
{
4343
Warning($"NuGet restore failed: {ex.Message}");
44-
// Continue anyway as dotnet restore might handle it
4544
}
46-
47-
Information("Running dotnet restore...");
48-
// Suppress NU1903 vulnerability warning for Newtonsoft.Json 9.0.1 (known issue, accepted risk)
49-
var restoreSettings = new DotNetRestoreSettings
45+
46+
// dotnet restore (all platforms, for SDK-style projects)
47+
try
5048
{
51-
MSBuildSettings = new DotNetMSBuildSettings()
52-
.WithProperty("WarningsNotAsErrors", "NU1903")
53-
.WithProperty("NoWarn", "NU1903")
54-
};
55-
DotNetRestore(mainSolution.FullPath, restoreSettings);
49+
Information("Running dotnet restore...");
50+
// Suppress NU1903 vulnerability warning for Newtonsoft.Json 9.0.1 (known issue, accepted risk)
51+
// Also supress restore warning as errors NU1503 for xamarin/old style projects
52+
var restoreSettings = new DotNetRestoreSettings
53+
{
54+
MSBuildSettings = new DotNetMSBuildSettings()
55+
.WithProperty("WarningsNotAsErrors", "NU1903;NU1503")
56+
.WithProperty("NoWarn", "NU1903;NU1503")
57+
};
58+
DotNetRestore(solutionPath.FullPath, restoreSettings);
59+
Information($"✓ dotnet restore completed");
60+
}
61+
catch (Exception e)
62+
{
63+
Warning($"dotnet restore failed: {e.Message}");
64+
}
65+
}
66+
67+
Task("Restore")
68+
.Does(() =>
69+
{
70+
// FAKE restores the main IO.Ably.sln solution, not IO.Ably.NetStandard.sln
71+
RestoreSolution(paths.MainSolution);
5672
});
5773

5874
Task("Version")
@@ -132,7 +148,16 @@ Task("Restore-Xamarin")
132148
try
133149
{
134150
Information($"Running NuGet restore for {paths.XamarinSolution.FullPath}...");
135-
NuGetRestore(paths.XamarinSolution.FullPath);
151+
var nugetSettings = new NuGetRestoreSettings();
152+
153+
// Use local nuget.exe if available
154+
var nugetPath = paths.Root.CombineWithFilePath("tools/nuget.exe");
155+
if (FileExists(nugetPath))
156+
{
157+
nugetSettings.ToolPath = nugetPath;
158+
}
159+
160+
NuGetRestore(paths.XamarinSolution.FullPath, nugetSettings);
136161
}
137162
catch (Exception ex)
138163
{

cake-build/tasks/package.cake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
///////////////////////////////////////////////////////////////////////////////
44

55
Task("Package-Build-All")
6-
.IsDependentOn("Prepare")
6+
.IsDependentOn("Clean")
77
.IsDependentOn("Version")
88
.Does(() =>
99
{
@@ -15,6 +15,9 @@ Task("Package-Build-All")
1515
return;
1616
}
1717

18+
// Restore the package solution (not the main solution)
19+
RestoreSolution(paths.PackageSolution);
20+
1821
var settings = buildConfig.ApplyStandardSettings(
1922
new MSBuildSettings(),
2023
"Release"
@@ -107,7 +110,7 @@ Task("Package-Create-NuGet")
107110
});
108111

109112
Task("PushPackage-Build-All")
110-
.IsDependentOn("Prepare")
113+
.IsDependentOn("Clean")
111114
.IsDependentOn("Version")
112115
.Does(() =>
113116
{
@@ -119,6 +122,9 @@ Task("PushPackage-Build-All")
119122
return;
120123
}
121124

125+
// Restore the push package solution (not the main solution)
126+
RestoreSolution(paths.PushPackageSolution);
127+
122128
var settings = buildConfig.ApplyStandardSettings(
123129
new MSBuildSettings(),
124130
"Package"

src/IO.Ably.Android/IO.Ably.Android.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'package|AnyCPU'">
4949
<OutputPath>bin\package\</OutputPath>
5050
</PropertyGroup>
51+
<!-- Fix for DeterministicSourcePaths in CI environments -->
52+
<!-- See: https://github.com/dotnet/sourcelink/issues/572 -->
53+
<ItemGroup>
54+
<SourceRoot Include="$(MSBuildThisFileDirectory)..\..\"/>
55+
</ItemGroup>
5156
<ItemGroup>
5257
<Reference Include="Microsoft.CSharp" />
5358
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -119,4 +124,4 @@
119124
<Target Name="AfterBuild">
120125
</Target>
121126
-->
122-
</Project>
127+
</Project>

src/IO.Ably.Push.Android/IO.Ably.Push.Android.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
<PropertyGroup>
4848
<AssemblyOriginatorKeyFile>IO.Ably.snk</AssemblyOriginatorKeyFile>
4949
</PropertyGroup>
50+
<!-- Fix for DeterministicSourcePaths in CI environments -->
51+
<!-- See: https://github.com/dotnet/sourcelink/issues/572 -->
52+
<ItemGroup>
53+
<SourceRoot Include="$(MSBuildThisFileDirectory)..\..\"/>
54+
</ItemGroup>
5055
<ItemGroup>
5156
<Reference Include="Java.Interop" />
5257
<Reference Include="Mono.Android" />
@@ -497,4 +502,4 @@
497502
<Target Name="AfterBuild">
498503
</Target>
499504
-->
500-
</Project>
505+
</Project>

src/IO.Ably.Push.iOS/IO.Ably.Push.iOS.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<PropertyGroup>
4343
<AssemblyOriginatorKeyFile>IO.Ably.snk</AssemblyOriginatorKeyFile>
4444
</PropertyGroup>
45+
<!-- Fix for DeterministicSourcePaths in CI environments -->
46+
<!-- See: https://github.com/dotnet/sourcelink/issues/572 -->
47+
<ItemGroup>
48+
<SourceRoot Include="$(MSBuildThisFileDirectory)..\..\"/>
49+
</ItemGroup>
4550
<ItemGroup>
4651
<Reference Include="OpenTK-1.0" />
4752
<Reference Include="System" />
@@ -90,4 +95,4 @@
9095
</PropertyGroup>
9196
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props'))" />
9297
</Target>
93-
</Project>
98+
</Project>

src/IO.Ably.iOS/IO.Ably.iOS.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'package|AnyCPU'">
5353
<OutputPath>bin\package\</OutputPath>
5454
</PropertyGroup>
55+
<!-- Fix for DeterministicSourcePaths in CI environments -->
56+
<!-- See: https://github.com/dotnet/sourcelink/issues/572 -->
57+
<ItemGroup>
58+
<SourceRoot Include="$(MSBuildThisFileDirectory)..\..\"/>
59+
</ItemGroup>
5560
<ItemGroup>
5661
<Reference Include="Microsoft.CSharp" />
5762
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -112,4 +117,4 @@
112117
<Import Project="..\IO.Ably.Shared.MsgPack\IO.Ably.Shared.MsgPack.projitems" Label="Shared" Condition="$(DefineConstants.Contains(MSGPACK))" />
113118
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets')" />
114119
<Import Project="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.CSharp.targets" Condition="Exists('C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.CSharp.targets')" />
115-
</Project>
120+
</Project>

0 commit comments

Comments
 (0)