Skip to content

Initial commit for packageWorks in 6000.2 #400

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

Open
wants to merge 6 commits into
base: release/6000.2/publish
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions .Wrench/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using TilemapExtras.Cookbook.Settings;
using RecipeEngine;
using RecipeEngine.Modules.Wrench.Helpers;


// ReSharper disable once CheckNamespace
public static class Program
{
public static int Main(string[] args)
{
var settings = new TilemapExtrasSettings();

// ReSharper disable once UnusedVariable
var engine = EngineFactory
.Create()
.ScanAll()
.WithWrenchModule(settings.Wrench)
.GenerateAsync().Result;
return engine;
}
}
61 changes: 61 additions & 0 deletions .Wrench/Settings/TilemapExtrasSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using RecipeEngine.Api.Settings;
using RecipeEngine.Api.Commands;
using RecipeEngine.Modules.Wrench.Models;
using RecipeEngine.Modules.Wrench.Settings;

namespace TilemapExtras.Cookbook.Settings;

public class TilemapExtrasSettings : AnnotatedSettingsBase
{
// Path from the root of the repository where packages are located.
readonly string[] PackagesRootPaths = {".", ".tests/Packages/com.unity.2d.tilemap.extras.tests"};

// update this to list all packages in this repo that you want to release.
Dictionary<string, PackageOptions> PackageOptions = new()
{
{
"com.unity.2d.tilemap.extras",
new PackageOptions()
{
PackJobOptions = new PackJobOptions()
{
PrePackCommands = new List<Command>()
{
new Command("git clone $UNITY_2D_REPO_GIT --no-checkout .tests"),
new Command("cd .tests && git fetch origin $GIT_BRANCH"),
new Command("cd .tests && rm -f .git/index.lock"),
new Command("cd .tests && git checkout -f --detach FETCH_HEAD"),
},
},
ReleaseOptions = new ReleaseOptions() { IsReleasing = true }
}
},
{
"com.unity.2d.tilemap.extras.tests",
new PackageOptions()
{
PackJobOptions = new PackJobOptions()
{
PrePackCommands = new List<Command>()
{
new Command("git clone $UNITY_2D_REPO_GIT --no-checkout .tests"),
new Command("cd .tests && git fetch origin $GIT_BRANCH"),
new Command("cd .tests && rm -f .git/index.lock"),
new Command("cd .tests && git checkout -f --detach FETCH_HEAD"),
},
},
ReleaseOptions = new ReleaseOptions() { IsReleasing = false, NeverPublish = true }
}
},
};

public TilemapExtrasSettings()
{
Wrench = new WrenchSettings(
PackagesRootPaths,
PackageOptions
);
}

public WrenchSettings Wrench { get; private set; }
}
16 changes: 16 additions & 0 deletions .Wrench/TilemapExtras-recipes.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TilemapExtras.Cookbook", "TilemapExtras.Cookbook.csproj", "{A5A71435-C891-4C78-989C-2713DAA7B3B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5A71435-C891-4C78-989C-2713DAA7B3B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5A71435-C891-4C78-989C-2713DAA7B3B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5A71435-C891-4C78-989C-2713DAA7B3B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5A71435-C891-4C78-989C-2713DAA7B3B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions .Wrench/TilemapExtras.Cookbook.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RecipeEngine.Modules.Wrench" Version="0.10.42" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions .Wrench/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}
6 changes: 6 additions & 0 deletions .Wrench/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Artifactory Prd" value="https://artifactory.prd.it.unity3d.com/artifactory/api/nuget/v3/nuget"/>
</packageSources>
</configuration>
149 changes: 149 additions & 0 deletions .Wrench/onboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Description: This script is used to onboard a project onto Wrench
import argparse
import json
import os
import shutil
import subprocess

TEMPLATE_CSPROJ = "TEMPLATE.Cookbook.csproj"
TEMPLATE_SLN = "TEMPLATE-recipes.sln"


def get_args():
parser = argparse.ArgumentParser(description="Onboard a project onto Wrench")
parser.add_argument("--settings-name", required=True, help="The name of the settings file",
dest="settings_name")
return parser.parse_args()


def delete_git_folder():
print("Deleting .git folder")
if os.path.isfile(".gitignore"):
os.remove(".gitignore")
if os.path.exists(".git"):
shutil.rmtree(".git", ignore_errors=True)


def get_git_root_dir():
git_dir = subprocess.run(["git", "rev-parse", "--show-toplevel"], stdout=subprocess.PIPE).stdout
return git_dir.decode("utf-8").strip()


def find_package_json_files(root_dir, initial=True):
#walk the directory recursively and find all package.json files
rtn_list = set()
for root, dirs, files in os.walk(root_dir):
for file in files:
if file == "package.json":
if initial:
file_location = file
else:
file_location = os.path.join(root, file)
# validate the package.json file
with open(os.path.join(root, file_location), "r") as f:
data = json.loads(f.read())
if "unity" in data and "name" in data:
rtn_list.add(data["name"])
for directory in dirs:
rtn_list.update(find_package_json_files(os.path.join(root, directory), False))

return rtn_list


def create_package_option(name, first):
initial_char=""
initial_tab = ""
if not first:
initial_char = ",\n"
initial_tab = " "
return f"{initial_char}{initial_tab}{{\n \"{name}\",\n new PackageOptions() {{ ReleaseOptions = new ReleaseOptions() {{ IsReleasing = true }} }}\n }}"


def update_template_variables(packages):
template_var = "TEMPLATESettings"
settings = get_args()
settings_content = open(os.path.join("Settings", template_var+".cs")).read()
# replace the template settings with the actual settings
settings_content = settings_content.replace("TEMPLATESettings", f"{settings.settings_name}Settings")
settings_content = settings_content.replace('PACKAGES_ROOTS', '.')

package_replace_string = str()
first = True
for package in packages:
package_replace_string += create_package_option(package, first)
first = False
settings_content = settings_content.replace('//"PACKAGES_TO_RELEASE"', package_replace_string)
settings_content = settings_content.replace('TEMPLATE.Cookbook.Settings', settings.settings_name+".Cookbook.Settings")

# Write the updated settings file
with open(os.path.join("Settings", settings.settings_name+"Settings.cs"), "w") as f:
f.write(settings_content)
# Update the Program.cs file
program_content = open("Program.cs").read()
with open("Program.cs", "w") as f:
program_content = program_content.replace('using TEMPLATE.Cookbook.Settings;', f"using {settings.settings_name}.Cookbook.Settings;")
program_content = program_content.replace("TEMPLATE.Cookbook", settings.settings_name)
program_content = program_content.replace('PACKAGES_ROOT', '.')
program_content = program_content.replace('TEMPLATESettings', settings.settings_name+"Settings")
f.write(program_content)
# delete the template file
os.remove(os.path.join("Settings", template_var+".cs"))
# update csproj file
csproj_content = open(TEMPLATE_CSPROJ).read()
with open(TEMPLATE_CSPROJ.replace("TEMPLATE", settings.settings_name), "w") as f:
f.write(csproj_content)
os.remove(TEMPLATE_CSPROJ)
# update sln file
sln_content = open(TEMPLATE_SLN).read()
with open(TEMPLATE_SLN.replace("TEMPLATE", settings.settings_name), "w") as f:
sln_content = sln_content.replace("TEMPLATE", settings.settings_name)
f.write(sln_content)
os.remove(TEMPLATE_SLN)


def update_shell_scripts(root_dir):
split_root=os.path.normpath(root_dir).split(os.sep)
split_cwd=os.getcwd().split(os.sep)

relative_path = os.path.relpath(os.getcwd(), root_dir)
csproj_path = os.path.join(relative_path, f"{get_args().settings_name}.Cookbook.csproj")

path_diff = len(split_cwd) - len(split_root)
cd_string = str()
for i in range(path_diff):
cd_string += "../"

bash_content = open("regenerate.bat").read()
bash_content = bash_content.replace("STEPS_TO_ROOT", cd_string)
bash_content = bash_content.replace("PATH_TO_CSPROJ", csproj_path)
with open("regenerate.bat", "w") as f:
f.write(bash_content)

shell_content = open("regenerate.sh").read()
shell_content = shell_content.replace("STEPS_TO_ROOT", cd_string)
shell_content = shell_content.replace("PATH_TO_CSPROJ", csproj_path)
with open("regenerate.sh", "w") as f:
f.write(shell_content)


def main():
print("Starting process of onboarding")
# delete git folder
delete_git_folder()
# get root folder
root_dir = get_git_root_dir()
# find all appropriate package.json files
package_files = find_package_json_files(root_dir)
packages = set()
# process out any testing packages
for package in package_files:
if ".tests" in package:
continue
packages.add(package)
# Replace Template naming with actual naming
update_template_variables(packages)
update_shell_scripts(root_dir)


if "__main__" in __name__:
main()
2 changes: 2 additions & 0 deletions .Wrench/regenerate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd %~dp0../
dotnet run --project .Wrench/TilemapExtras.Cookbook.csproj
2 changes: 2 additions & 0 deletions .Wrench/regenerate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd $(dirname "$0")/../
dotnet run --project .Wrench/TilemapExtras.Cookbook.csproj
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
Assets/AssetStoreTools*
**/.idea/

# Visual Studio cache directory
.vs/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.csproj.meta
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.opendb
*.dwlt

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage
Projects/PublishAll/Logs
Projects/AllPackages/Logs
**/Logs

EntityCache
EntityCache.meta
Projects/Hybrid/UserSettings
StreamingAssets.meta
SceneDependencyCache.meta
SceneDependencyCache/

**/Packages/packages-lock.json
**/ProjectSettings/VersionControlSettings.asset
**/ProjectSettings/PackageManagerSettings.asset
**/UserSettings/QuickSearch.settings
**/UserSettings/QuickSearch.index

!Documentation~
!Samples~/
!Packages/com.unity.2d.psdimporter.tests/EditorTests/TypeAssets~/
.DS_Store
.multitool

.Wrench/bin
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build/**
.npmrc
.npmignore
.gitignore
.Wrench
.tests
CONTRIBUTING.md
CONTRIBUTING.md.meta
QAReport.md
Expand Down
Loading