Split upm and packman packaging

This commit is contained in:
Andreia Gaita 2019-08-13 15:08:27 +02:00
Родитель e15d94a93f
Коммит 8e7c62cff8
18 изменённых файлов: 186 добавлений и 96 удалений

4
.gitignore поставляемый
Просмотреть файл

@ -307,4 +307,6 @@ sysinfo.txt
/embedded-git.json
lib/deps.zip
nbgv.exe
.store
.store
.Editor
PackageSources/

Просмотреть файл

@ -19,7 +19,10 @@ commands:
Pop-Location
Write-Output "Packaging version $($version.AssemblyInformationalVersion)"
scripts\Create-Packages.ps1 $($version.AssemblyInformationalVersion) -Verbose
scripts\Create-Packages.ps1 $($version.AssemblyInformationalVersion) "PackageSources" -SkipUnity -SkipPackman
New-Item -itemtype Directory -Path "upm-ci~\packages" -Force
Copy-Item "artifacts\*.tgz" "upm-ci~\packages\"
Copy-Item "artifacts\packages.json" "upm-ci~\packages\"
triggers:
branches:
@ -28,4 +31,7 @@ triggers:
artifacts:
packages:
paths:
- "artifacts/*.tgz"
- "upm-ci~/packages/**/*"
sources:
paths:
- "PackageSources/**/*"

Просмотреть файл

@ -1,8 +1,4 @@
packages:
- name: com.unity.git.api
path: artifacts/package/com.unity.git.api
- name: com.unity.git.ui
path: artifacts/package/com.unity.git.ui
{% metadata_file .yamato_config/configuration.yml %}
---
name: Pack
agent:
@ -16,7 +12,7 @@ dependencies:
commands:
# - npm install
# - npm install upm-ci-utils@stable -g --registry https://api.bintray.com/npm/unity/unity-npm
- dir artifacts /s
- dir PackageSources /s
{% for package in packages %}
# - upm-ci package pack --packages-path {{ package.path }}
{% endfor %}

Просмотреть файл

@ -4,9 +4,9 @@
<PublishTo Condition="'$(PublishTo)' == '' ">$(SolutionDir)\build\packages</PublishTo>
</PropertyGroup>
<Target Name="EnumeratePackageFiles" Returns="$(PackageName);@(FilesToCopy);@(ExtraFiles)">
<Target Name="EnumeratePackageFiles" Returns="$(PackageName);@(FilesToCopy)">
<CreateItem Include="$(PackageSourceDir)\**\*.*;$(IntermediateOutputPath)\$(AssemblyName).Version.cs" Exclude="$(PackageSourceDir)\**\*.csproj*;$(PackageSourceDir)\**\*.ncrunch*;$(PackageSourceDir)\**\obj\**">
<CreateItem Include="$(PackageSourceDir)\$(PackageName)\**\*.*;$(PackageSourceDir)\extras\$(PackageName)\**\*.*" Exclude="$(PackageSourceDir)\$(PackageName)\**\*.csproj*;$(PackageSourceDir)\$(PackageName)\**\*.ncrunch*;$(PackageSourceDir)\$(PackageName)\**\obj\**">
<Output TaskParameter="Include" ItemName="FilesToCopy" />
</CreateItem>
@ -15,12 +15,14 @@
<Target Name="CopySourcesToPackmanPackage"
DependsOnTargets="EnumeratePackageFiles"
AfterTargets="AfterBuild"
Inputs="@(FilesToCopy)"
Outputs="@(FilesToCopy->'$(PublishTo)\$(PackageName)\%(RecursiveDir)%(Filename)%(Extension)')"
Inputs="@(FilesToCopy);@(VersionFiles)"
Outputs="@(FilesToCopy->'$(PublishTo)\$(PackageName)\%(RecursiveDir)%(Filename)%(Extension)');@(VersionFiles->'$(PublishTo)\$(PackageName)\%(Project)\%(Filename)%(Extension)')"
>
<MakeDir Directories="$(PublishTo)\$(PackageName)" />
<Copy SourceFiles="@(FilesToCopy)" DestinationFiles="@(FilesToCopy->'$(PublishTo)\$(PackageName)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(VersionFiles)" DestinationFiles="@(VersionFiles->'$(PublishTo)\$(PackageName)\%(Project)\%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
</Project>

Просмотреть файл

@ -6,7 +6,7 @@
<Import Project="$(SolutionDir)\common\nativelibraries.props" />
<!-- copy native libraries to unity package project folder -->
<!-- copy native libraries to output path -->
<Target Name="CopyNativeLibrariesToUnityPackageProject"
AfterTargets="AfterBuild"
Inputs="@(NativeLibraries"

Просмотреть файл

@ -36,6 +36,8 @@ Param(
$SkipUnity,
[switch]
$SkipPackman,
[switch]
$SkipUpm,
[string]
$Tmp,
[switch]
@ -60,6 +62,7 @@ try {
$noPackage = ""
$noUnity = ""
$noPackman = ""
$noUpm = ""
if ($Skip) {
$noPackage = "-k"
@ -71,7 +74,11 @@ try {
$noPackman = "-p"
}
Run-Command -Fatal { & node ..\yarn.js -s start -o $Out -n $Name -v $Version -s $Source -i $Ignore -e $Extra -t $BaseInstall --tmp $Tmp $noPackage $noUnity $noPackman }
if ($SkipUpm) {
$noUpm = "-m"
}
Run-Command -Fatal { & node ..\yarn.js -s start -o $Out -n $Name -v $Version -s $Source -i $Ignore -e $Extra -t $BaseInstall --tmp $Tmp $noPackage $noUnity $noPackman $noUpm }
} finally {
Pop-Location

Просмотреть файл

@ -11,7 +11,9 @@ export interface ParsedOptions {
ignores: Ignores;
doUnityPackage: boolean;
doPackmanPackage: boolean;
doUpmPackage: boolean;
tmpPath: string | undefined;
other: string[];
}
export const optionDefinitions : OptionDefinition[] = [
@ -77,11 +79,18 @@ export const optionDefinitions : OptionDefinition[] = [
description: 'Skip packaging for the asset store (.unitypackage)'
},
{
name: 'skipPackman',
name: 'skipPackage',
alias: 'p',
type: Boolean,
defaultValue: false,
description: 'Skip packaging for packman (.tgz with the sources inside a "package" folder, and a zip with the sources inside a "package name" folder )'
description: 'Skip packaging for package manager (zip with the sources inside a "package name" folder )'
},
{
name: 'skipUpm',
alias: 'm',
type: Boolean,
defaultValue: false,
description: 'Skip packaging for upm (.tgz with the sources inside a "package" folder)'
},
{
name: 'tmp',

Просмотреть файл

@ -10,6 +10,7 @@ import { optionDefinitions, sections, ParsedOptions } from './cmdlineoptions';
import { PackageType, PackageFileList, PackageFile } from './packager';
import { UnityPackager } from './unityPackager';
import { PackmanPackager } from './packmanPackager';
import { UpmPackager } from './upmPackager';
async function validateOptionPath(options: commandLineArgs.CommandLineOptions, argName: string, optional: boolean = false) {
@ -53,8 +54,10 @@ async function parseCommandLine() : Promise<ParsedOptions> {
skipPackaging: options.skip === true,
ignores: [],
doUnityPackage: !options.skipUnity,
doPackmanPackage: !options.skipPackman,
tmpPath: (await validateOptionPath(options, 'tmp', true))
doPackmanPackage: !options.skipPackage,
doUpmPackage: !options.skipUpm,
tmpPath: (await validateOptionPath(options, 'tmp', true)),
other: []
};
if (extras) {
@ -81,82 +84,95 @@ async function parseCommandLine() : Promise<ParsedOptions> {
const parsed = await parseCommandLine();
let tmpBuildDir = parsed.tmpPath || `build/tmp`;
let tmpBuildDir = parsed.tmpPath || p.join(p.dirname(parsed.targetPath), 'obj');
if (!p.isAbsolute(tmpBuildDir)) {
tmpBuildDir = p.resolve(tmpBuildDir);
}
tmpBuildDir = p.join(tmpBuildDir, parsed.packageName);
if (!parsed.tmpPath) {
console.warn(`--tmp arg not specified, reusing ${tmpBuildDir}.`);
}
parsed.tmpPath = tmpBuildDir;
if (!parsed.skipPackaging) {
if (await asyncfile.exists(tmpBuildDir)) {
await asyncfile.delete(tmpBuildDir);
}
}
const tmpPackmanSourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, 'package', parsed.packageName) : tmpBuildDir;
if (!(await asyncfile.exists(tmpPackmanSourceTree))) {
await asyncfile.mkdirp(tmpPackmanSourceTree);
}
const tmpUnitySourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, "unitypackage") : await FileTreeWalker.getTempDir();
console.log(parsed);
const packmanPackager = new PackmanPackager();
const upmPackager = new UpmPackager();
const unityPackager = new UnityPackager();
const packageJson = await packmanPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpPackmanSourceTree);
if (parsed.doUnityPackage) {
await unityPackager.prepareSource(tmpPackmanSourceTree, tmpUnitySourceTree, parsed.baseInstallationPath);
}
let packages: { [key: string] : any, manifest?: PackageFile } = {};
const manifest: string = p.join(parsed.targetPath, `manifest.json`);
if (await asyncfile.exists(manifest)) {
packages = JSON.parse(await asyncfile.readTextFile(manifest));
}
if (parsed.skipPackaging) {
if (parsed.doPackmanPackage)
packages[PackageType.Source].push({ type: PackageType.Source, path: tmpPackmanSourceTree });
if (parsed.doUnityPackage)
packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUnitySourceTree });
} else {
if (parsed.doPackmanPackage || parsed.doUnityPackage) {
const tmpPackmanSourceTree = p.join(parsed.skipPackaging ? parsed.targetPath : tmpBuildDir, 'package', parsed.packageName);
// unity and package use the same source
await packmanPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpPackmanSourceTree);
if (parsed.doUnityPackage) {
const tmpUnitySourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, "unitypackage") : await FileTreeWalker.getTempDir();
await unityPackager.prepareSource(tmpPackmanSourceTree, tmpUnitySourceTree, parsed.baseInstallationPath);
if (parsed.skipPackaging) {
packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUnitySourceTree });
} else {
let files = await unityPackager.package(tmpUnitySourceTree, parsed.targetPath, parsed.packageName, parsed.version);
files.map(x => {
if (!packages[x.type]) packages[x.type] = [];
packages[x.type].push(x);
});
}
}
if (parsed.doPackmanPackage) {
let files = await packmanPackager.package(tmpPackmanSourceTree, parsed.targetPath, parsed.packageName, parsed.version);
let packmanPackageFile: PackageFile = files.find(x => x.type === PackageType.PackmanPackage)!;
if (parsed.skipPackaging) {
packages[PackageType.Source].push({ type: PackageType.Source, path: tmpPackmanSourceTree });
} else {
let files = await packmanPackager.package(tmpPackmanSourceTree, parsed.targetPath, parsed.packageName, parsed.version);
files.map(x => {
if (!packages[x.type]) packages[x.type] = [];
packages[x.type].push(x);
});
}
}
}
if (parsed.doUpmPackage) {
const tmpUpmSourceTree = p.join(parsed.skipPackaging ? parsed.targetPath : tmpBuildDir, parsed.packageName);
// do the upm package first. it always has a -preview suffix
let versionMetadataIndex = parsed.version.indexOf('+');
parsed.version = parsed.version.substring(0, versionMetadataIndex > 0 ? versionMetadataIndex : undefined ) + "-preview";
let packageJson = await upmPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpUpmSourceTree);
if (parsed.skipPackaging) {
packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUpmSourceTree });
} else {
let files = await upmPackager.package(tmpUpmSourceTree, parsed.targetPath, parsed.packageName, parsed.version);
let upmPackageFile: PackageFile = files.find(x => x.type === PackageType.PackmanPackage)!;
files.map(x => {
if (!packages[x.type]) packages[x.type] = [];
packages[x.type].push(x);
});
if (packageJson) {
const packmanPackageManifest: string = p.join(parsed.targetPath, `packages.json`);
const upmManifest: string = p.join(parsed.targetPath, `packages.json`);
let packageManifest: { [key: string]: string } = {};
if (await asyncfile.exists(packmanPackageManifest)) {
packageManifest = JSON.parse(await asyncfile.readTextFile(packmanPackageManifest));
if (await asyncfile.exists(upmManifest)) {
packageManifest = JSON.parse(await asyncfile.readTextFile(upmManifest));
}
packageManifest[p.basename(packmanPackageFile.path)] = JSON.parse(await asyncfile.readTextFile(packageJson));
await asyncfile.writeTextFile(packmanPackageManifest, JSON.stringify(packageManifest));
packages[PackageType.Manifest] = { type: PackageType.Manifest, path: packmanPackageManifest};
}
packageManifest[p.basename(upmPackageFile.path)] = JSON.parse(await asyncfile.readTextFile(packageJson));
await asyncfile.writeTextFile(upmManifest, JSON.stringify(packageManifest));
packages[PackageType.Manifest] = { type: PackageType.Manifest, path: upmManifest};
}
}
if (parsed.doUnityPackage) {
let files = await unityPackager.package(tmpUnitySourceTree, parsed.targetPath, parsed.packageName, parsed.version);
files.map(x => {
if (!packages[x.type]) packages[x.type] = [];
packages[x.type].push(x);
});
}
await asyncfile.writeTextFile(manifest, JSON.stringify(packages));
}
await asyncfile.writeTextFile(manifest, JSON.stringify(packages));
})();

Просмотреть файл

@ -1,9 +1,7 @@
import * as asyncfile from 'async-file';
import * as p from 'path';
import { Ignores } from './RecursiveReaddir';
import md5 = require('md5');
import { FileTreeWalker } from './TreeWalker';
import { Packager, PackageType, createTar, createZip, PackageFile } from './packager';
import { Packager, PackageType, createZip, PackageFile } from './packager';
export class PackmanPackager extends Packager {
@ -13,9 +11,6 @@ export class PackmanPackager extends Packager {
public async package(sourcePath: string, targetPath: string, packageName: string, version: string) : Promise<PackageFile[]>{
const tgzPath: string = p.join(targetPath, `${packageName}-${version}.tgz`);
const tgzMd5Path: string = p.join(targetPath, `${packageName}-${version}.tgz.md5`);
const zipPath: string = p.join(targetPath, `${packageName}-${version}.zip`);
const zipMd5Path: string = p.join(targetPath, `${packageName}-${version}.zip.md5`);
@ -23,13 +18,8 @@ export class PackmanPackager extends Packager {
let ret: PackageFile[] = [];
await createTar(sourcePath, tgzPath, 'package');
let hash = md5(await asyncfile.readFile(tgzPath));
await asyncfile.writeTextFile(tgzMd5Path, hash);
ret.push({ type: PackageType.PackmanPackage, path: tgzPath, md5Path: tgzMd5Path, md5Hash: hash });
await createZip(sourcePath, zipPath, p.dirname(sourcePath) === packageName ? packageName : undefined);
hash = md5(await asyncfile.readFile(zipPath));
let hash = md5(await asyncfile.readFile(zipPath));
await asyncfile.writeTextFile(zipMd5Path, hash);
ret.push({ type: PackageType.PackmanSource, path: zipPath, md5Path: zipMd5Path, md5Hash: hash });

Просмотреть файл

@ -0,0 +1,28 @@
import * as asyncfile from 'async-file';
import * as p from 'path';
import md5 = require('md5');
import { Packager, PackageType, createTar, PackageFile } from './packager';
export class UpmPackager extends Packager {
public constructor() {
super();
}
public async package(sourcePath: string, targetPath: string, packageName: string, version: string) : Promise<PackageFile[]>{
const tgzPath: string = p.join(targetPath, `${packageName}-${version}.tgz`);
const tgzMd5Path: string = p.join(targetPath, `${packageName}-${version}.tgz.md5`);
await asyncfile.mkdirp(targetPath);
let ret: PackageFile[] = [];
await createTar(sourcePath, tgzPath, 'package');
let hash = md5(await asyncfile.readFile(tgzPath));
await asyncfile.writeTextFile(tgzMd5Path, hash);
ret.push({ type: PackageType.PackmanPackage, path: tgzPath, md5Path: tgzMd5Path, md5Hash: hash });
return ret;
}
}

Просмотреть файл

@ -10,6 +10,14 @@
Param(
[string]
$Version,
[string]
$TmpDir = '',
[switch]
$SkipUnity = $false,
[switch]
$SkipPackman = $false,
[switch]
$SkipUpm = $false,
[switch]
$Trace = $false
)
@ -32,35 +40,41 @@ if ($Trace) {
Die -1 "You need to pass the -Version parameter"
}
$tmpDir=$TmpDir
if ($tmpDir -eq '') {
$tmpDir="$rootDirectory\obj"
} elseif (![System.IO.Path]::IsPathRooted($tmpDir)) {
$tmpDir="$rootDirectory\$tmpDir"
}
$artifactDir="$rootDirectory\artifacts"
$tmpDir="$rootDirectory\obj"
$packageDir="$rootDirectory\build\packages"
$srcDir="$rootDirectory\src"
$packagingScriptsDir="$rootDirectory\packaging\create-unity-packages"
Write-Output "Cleaning up previous build artifacts..."
Write-Output "Cleaning up previous build artifacts from $tmpDir..."
Remove-Item $tmpDir -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item $artifactDir -Force -Recurse -ErrorAction SilentlyContinue
$pkgName="com.unity.git.api"
$pkgSrcDir="$packageDir\$pkgName"
$extrasDir="$srcDir\extras\$pkgName"
$extrasDir=""
$ignorefile="$srcDir\$pkgName\.npmignore"
$baseInstall="Packages\$pkgName"
$outDir=$artifactDir
Write-Verbose "$packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall"
Write-Output "Packaging $pkgName..."
Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir }
Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir -SkipUnity:$SkipUnity -SkipPackman:$SkipPackman -SkipUpm:$SkipUpm }
$pkgName="com.unity.git.ui"
$pkgSrcDir="$packageDir\$pkgName"
$extrasDir="$srcDir\extras\$pkgName"
$extrasDir=""
$ignorefile="$srcDir\$pkgName\.npmignore"
$baseInstall="Packages\$pkgName"
$outDir=$artifactDir
Write-Verbose "$packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall"
Write-Output "Packaging $pkgName..."
Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir }
Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir -SkipUnity:$SkipUnity -SkipPackman:$SkipPackman -SkipUpm:$SkipUpm }
}

Просмотреть файл

@ -7,11 +7,9 @@ Api/version.json
Api/version.json.meta
# some directories we don't want
obj/
obj/**
obj.meta
node_modules/
node_modules/**
node_modules.meta
UnityTests/
UnityTests.meta
Third Party Notices - net35.md
Third Party Notices - net35.md.meta

Просмотреть файл

@ -57,9 +57,17 @@
<!-- copy source files to packman package folder -->
<PropertyGroup>
<PackageSourceDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\'))</PackageSourceDir>
<PackageSourceDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</PackageSourceDir>
<PackageName>com.unity.git.api</PackageName>
</PropertyGroup>
<ItemGroup>
<VersionFiles Include="$(IntermediateOutputPath)\$(AssemblyName).Version.cs">
<Project>Api</Project>
</VersionFiles>
<VersionFiles Include="$(IntermediateOutputPath)\$(RootNamespace).Logging.Version.cs">
<Project>Logging</Project>
</VersionFiles>
</ItemGroup>
<Import Project="$(SolutionDir)\common\packaging.targets" Condition=" '$(TargetFramework)' == 'net471' " />
</Project>

Просмотреть файл

@ -5,11 +5,9 @@ git*.zip*
.npmignore-net35
# some directories we don't want
obj/
obj/**
obj.meta
node_modules/
node_modules/**
node_modules.meta
UnityTests/
UnityTests.meta
Third Party Notices - net35.md
Third Party Notices - net35.md.meta

Просмотреть файл

@ -38,9 +38,14 @@
<!-- copy source files to packman package folder -->
<PropertyGroup>
<PackageSourceDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\'))</PackageSourceDir>
<PackageSourceDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</PackageSourceDir>
<PackageName>com.unity.git.ui</PackageName>
</PropertyGroup>
<ItemGroup>
<VersionFiles Include="$(IntermediateOutputPath)\$(AssemblyName).Version.cs">
<Project>UI</Project>
</VersionFiles>
</ItemGroup>
<Import Project="$(SolutionDir)\common\packaging.targets" Condition=" '$(TargetFramework)' == 'net471' " />

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51b4865f934150f48bb99d4aff015eca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: