Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BuildScripts] Versioning fixes #8238

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions build/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,39 @@ public enum ProjectType

public class BuildContext : FrostingContext
{
public static readonly Version DefaultVersionNumber = new("3.8.1.1");
public static readonly string DefaultRepositoryUrl = "https://github.com/MonoGame/MonoGame";
public static readonly string DefaultBaseVersion = "3.8.1";

public BuildContext(ICakeContext context) : base(context)
{
var repositoryUrl = context.Argument("build-repository", DefaultRepositoryUrl);
var buildConfiguration = context.Argument("build-configuration", "Release");
ArtifactsDirectory = context.Argument("artifacts-directory", "artifacts");
NuGetsDirectory = $"{ArtifactsDirectory}/NuGet/";
BuildOutput = context.Argument("build-output", "artifacts");
Version = context.Argument("build-version", DefaultBaseVersion + ".1-develop");
NuGetsDirectory = $"{BuildOutput}/NuGet/";

string repositoryUrl = "";
if (context.BuildSystem().IsRunningOnGitHubActions)
{
var workflow = context.BuildSystem().GitHubActions.Environment.Workflow;
var version = $"{DefaultVersionNumber.Major}.{DefaultVersionNumber.Minor}.{DefaultVersionNumber.Build}.{workflow.RunNumber}";
repositoryUrl = $"https://github.com/{workflow.Repository}";

if (workflow.Repository == "MonoGame/MonoGame" &&
workflow.RefType == GitHubActionsRefType.Branch &&
workflow.RefName == "refs/heads/master")
if (workflow.Repository != "MonoGame/MonoGame")
{
Version = $"{version}-develop";
Version = $"{DefaultBaseVersion}.{workflow.RunNumber}-{workflow.RepositoryOwner}";
}
else
{
Version = $"{version}-{workflow.RepositoryOwner}";
}

repositoryUrl = $"https://github.com/{workflow.Repository}";
}
else
{
var buildNumber = context.EnvironmentVariable("BUILD_NUMBER", DefaultVersionNumber.ToString());
var version = context.Argument("build-version", buildNumber);
var branchName = context.EnvironmentVariable("BRANCH_NAME", string.Empty);

if (!branchName.Contains("master"))
else if (workflow.RefType == GitHubActionsRefType.Branch && workflow.RefName != "refs/heads/master")
{
Version = $"{version}-develop";
Version = $"{DefaultBaseVersion}.{workflow.RunNumber}-develop";
}
else
{
Version = version;
Version = $"{DefaultBaseVersion}.{workflow.RunNumber}";
}

repositoryUrl = context.EnvironmentVariable("repository-url", "https://github.com/MonoGame/MonoGame");
}

DotNetMSBuildSettings = new DotNetMSBuildSettings();
DotNetMSBuildSettings.WithProperty(nameof(Version), Version);
DotNetMSBuildSettings.WithProperty(nameof(repositoryUrl), repositoryUrl);
DotNetMSBuildSettings.WithProperty("Version", Version);
DotNetMSBuildSettings.WithProperty("RepositoryUrl", repositoryUrl);

DotNetPackSettings = new DotNetPackSettings
{
Expand Down Expand Up @@ -102,16 +87,16 @@ public BuildContext(ICakeContext context) : base(context)

if (!context.IsRunningOnWindows())
{
// SET MGFXC_WINE_PATH for building shaders on macOS and Linux
// SET MGFXC_WINE_PATH for building shaders on macOS and Linux
System.Environment.SetEnvironmentVariable("MGFXC_WINE_PATH", context.EnvironmentVariable("HOME") + "/.winemonogame");
}

context.CreateDirectory(ArtifactsDirectory);
context.CreateDirectory(BuildOutput);
}

public string Version { get; }

public string ArtifactsDirectory { get; }
public string BuildOutput { get; }

public DirectoryPath NuGetsDirectory { get; }

Expand Down