This commit is contained in:
Matthew Leibowitz 2019-09-19 00:43:44 +02:00
Родитель 06b22dcc8b
Коммит 6316304f21
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 00A672181E6BF432
8 изменённых файлов: 17 добавлений и 559 удалений

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

@ -1,133 +1,30 @@
trigger:
- master
- refs/tags/*
variables:
MONO_VERSION: 5_18_1
XCODE_VERSION: 10.3
VERBOSITY: diagnostic
DOTNET_CORE_VERSION: 2.2.401
CAKE_VERSION: 0.34.1
API_TOOLS_VERSION: 1.0.2-preview.14
resources:
repositories:
- repository: xamarin-templates
- repository: internal-templates
type: github
name: xamarin/yaml-templates
endpoint: xamarin
- repository: components
type: github
name: xamarin/XamarinComponents
endpoint: xamarin
variables:
BUILD_COMMIT: $(Build.SourceVersion)
BUILD_NUMBER: $(Build.BuildNumber)
jobs:
- job: prepare
displayName: 'Prepare for builds'
variables:
skipComponentGovernanceDetection: true
pool:
name: Hosted Ubuntu 1604
steps:
- checkout: none
- powershell: |
$branch = $env:BUILD_SOURCEBRANCHNAME
if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) {
$branch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
}
Write-Host "Branch: $branch"
if ($branch -eq "master") {
Write-Host "Branch is master, fetching last successful build commit..."
# Must check allow scripts to have oauth token access in devops
$url = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/?definitions=$env:SYSTEM_DEFINITIONID&branchName=refs%2Fheads%2Fmaster&statusFilter=completed&resultFilter=succeeded&api-version=5.0"
Write-Host "URL: $url"
$json = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "$json"
Try {
$lastSuccessfulBuildCommit = $json.value[0].sourceVersion;
}
Catch {
}
}
if ($lastSuccessfulBuildCommit) {
Write-Host "Last Successful Commit: $lastSuccessfulBuildCommit"
} else {
$lastSuccessfulBuildCommit = "origin/master"
Write-Host "No previously successful build found, using this commit: $lastSuccessfulBuildCommit"
}
Write-Host "##vso[task.setvariable variable=GitLastSuccessfulCommit;isOutput=true]$lastSuccessfulBuildCommit"
name: lastSuccessful
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: 'Find last successful commit'
- job: build
displayName: 'Build'
dependsOn: prepare
pool:
name: 'Hosted macOS'
steps:
- bash: sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(MONO_VERSION)
displayName: 'Switch to the latest Xamarin SDK'
- bash: echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_$(XCODE_VERSION).app;sudo xcode-select --switch /Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer
displayName: 'Switch to the latest Xcode'
- bash: echo '##vso[task.setvariable variable=PATH;]'$PATH:$HOME/.dotnet/tools
displayName: 'Add ~/.dotnet/tools to the PATH environment variable'
- task: UseDotNet@2
displayName: 'Use the correct version of the .NET Core SDK'
inputs:
version: $(DOTNET_CORE_VERSION)
- powershell: |
dotnet tool install -g api-tools --version $(API_TOOLS_VERSION)
dotnet tool install -g cake.tool --version $(CAKE_VERSION)
displayName: 'Install .NET Core global tools'
- task: InstallAppleCertificate@2
inputs:
certSecureFile: 'Components iOS Certificate.p12'
keychain: 'temp'
- task: InstallAppleProvisioningProfile@1
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: 'Components iOS Provisioning.mobileprovision'
- bash: |
dotnet-cake --target=build --names=$(SdksNames) --verbosity=$(VERBOSITY)
displayName: 'Run build'
- powershell: |
if (Get-ChildItem artifacts -Filter *.nupkg) {
api-tools nuget-diff artifacts --latest --group-ids --output artifacts/api-diff --cache externals/package_cache
}
displayName: 'API diff'
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
inputs:
PathToPublish: artifacts
ArtifactName: nuget
- template: .ci/build.yml@components
parameters:
timeoutInMinutes: 180
cakeTarget: 'build'
cakeExtraArgs: '--names=$(SdksNames)'
- ${{ if eq(variables['System.TeamProject'], 'devdiv') }}:
- job: signing
displayName: 'Sign NuGets'
variables:
skipComponentGovernanceDetection: true
dependsOn:
- build
pool:
name: VSEng-XamarinCustom
demands:
- corpnet
condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'],'refs/tags/'), eq(variables['CodeSign'], 'true')))
steps:
- checkout: none
- template: sign-artifacts.yml@xamarin-templates
parameters:
targetFolder: '$(Build.ArtifactStagingDirectory)/signed'
- task: PublishBuildArtifacts@1
displayName: 'Publish the nuget-signed artifacts'
inputs:
artifactName: nuget-signed
pathToPublish: '$(Build.ArtifactStagingDirectory)/signed'
- template: sign-artifacts/jobs/v1.yml@internal-templates
parameters:
dependsOn: [ 'build' ]

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

@ -5,7 +5,6 @@
#load "poco.cake"
#load "components.cake"
#load "common.cake"
#load "custom_externals_download.cake"
var TARGET = Argument ("t", Argument ("target", "build"));
var NAMES = Argument ("names", "");

146
build.ps1
Просмотреть файл

@ -1,146 +0,0 @@
<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
and execute your Cake build script with the parameters you provide.
.PARAMETER Script
The build script to execute.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER Experimental
Tells Cake to use the latest Roslyn release.
.PARAMETER WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER Mono
Tells Cake to use the Mono scripting engine.
.LINK
http://cakebuild.net
#>
[CmdletBinding()]
Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
Write-Host "Preparing to run build script..."
$PS_SCRIPT_ROOT = split-path -parent $MyInvocation.MyCommand.Definition;
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
$CAKE_PACKAGES_CONFIG = Join-Path $PSScriptRoot "cake.packages.config"
# Should we use mono?
$UseMono = "";
if($Mono.IsPresent) {
Write-Verbose -Message "Using the Mono based scripting engine."
$UseMono = "-mono"
}
# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
Write-Verbose -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}
# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}
# Make sure tools folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
Write-Verbose -Message "Creating tools directory..."
New-Item -Path $TOOLS_DIR -Type directory | out-null
}
# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
if (!(Test-Path $CAKE_PACKAGES_CONFIG)) {
Write-Verbose -Message "Downloading packages.config..."
try { Invoke-WebRequest -Uri http://cakebuild.net/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
Throw "Could not download packages.config."
}
} else {
Write-Verbose -Message "using local cake.packages.config..."
Copy-Item $CAKE_PACKAGES_CONFIG $PACKAGES_CONFIG
}
}
# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { Test-Path $_ }
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
}
}
# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Downloading NuGet.exe..."
try {
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
} catch {
Throw "Could not download NuGet.exe."
}
}
# Save nuget.exe path to environment to be available to child processed
$ENV:NUGET_EXE = $NUGET_EXE
# Restore tools from NuGet?
if(-Not $SkipToolPackageRestore.IsPresent)
{
# Restore packages from NuGet.
Push-Location
Set-Location $TOOLS_DIR
Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
if ($LASTEXITCODE -ne 0)
{
exit $LASTEXITCODE
}
}
# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
}
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE

122
build.sh
Просмотреть файл

@ -1,122 +0,0 @@
#!/usr/bin/env bash
##########################################################################
# This is the Cake bootstrapper script for Linux and OS X.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
ADDINS_DIR=$TOOLS_DIR/Addins
MODULES_DIR=$TOOLS_DIR/Modules
NUGET_EXE=$TOOLS_DIR/nuget.exe
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
# Define md5sum or md5 depending on Linux/OSX
MD5_EXE=
if [[ "$(uname -s)" == "Darwin" ]]; then
MD5_EXE="md5 -r"
else
MD5_EXE="md5sum"
fi
# Define default arguments.
SCRIPT="build.cake"
CAKE_ARGUMENTS=()
# Parse arguments.
for i in "$@"; do
case $1 in
-s|--script) SCRIPT="$2"; shift ;;
--) shift; CAKE_ARGUMENTS+=("$@"); break ;;
*) CAKE_ARGUMENTS+=("$1") ;;
esac
shift
done
# Make sure the tools folder exist.
if [ ! -d "$TOOLS_DIR" ]; then
mkdir "$TOOLS_DIR"
fi
# Make sure that packages.config exist.
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
if [ ! -f "$SCRIPT_DIR/cake.packages.config" ]; then
echo "Downloading packages.config..."
curl -Lsfo "$TOOLS_DIR/packages.config" http://cakebuild.net/bootstrapper/packages
if [ $? -ne 0 ]; then
echo "An error occured while downloading packages.config."
exit 1
fi
else
echo "using local cake.packages.config..."
cp "$SCRIPT_DIR/cake.packages.config" "$TOOLS_DIR/packages.config"
fi
fi
# Download NuGet if it does not exist.
if [ ! -f "$NUGET_EXE" ]; then
echo "Downloading NuGet..."
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
if [ $? -ne 0 ]; then
echo "An error occurred while downloading nuget.exe."
exit 1
fi
fi
# Restore tools from NuGet.
pushd "$TOOLS_DIR" >/dev/null
if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
fi
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet tools."
exit 1
fi
$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
popd >/dev/null
# Restore addins from NuGet.
if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
pushd "$ADDINS_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet addins."
exit 1
fi
popd >/dev/null
fi
# Restore modules from NuGet.
if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
pushd "$MODULES_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet modules."
exit 1
fi
popd >/dev/null
fi
# Make sure that Cake has been installed.
if [ ! -f "$CAKE_EXE" ]; then
echo "Could not find Cake.exe at '$CAKE_EXE'."
exit 1
fi
# Start Cake
exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"

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

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.34.1" />
</packages>

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

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

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

@ -1,166 +0,0 @@
#tool "XamarinComponent"
#addin "nuget:?package=Cake.Json"
#addin "nuget:?package=Cake.Xamarin"
#addin "nuget:?package=Cake.ExtendedNuGet"
#addin "nuget:?package=NuGet.Core&version=2.8.6"
// NOTE: COOKIE_JAR_PATH Environment variable should contain the .xamarin cookie file
var TARGET = Argument ("target", Argument ("t", "build"));
var NUGET_FORCE_PUSH = Argument ("nuget-force-push", "false").Equals ("true");
var NUGET_MAX_ATTEMPTS = 5;
var COMP_MAX_ATTEMPTS = 3;
var COMP_WAIT_BETWEEN = 2500;
var NUGET_API_KEY = Argument ("nuget-api-key", "");
var NUGET_PUBLISH_SOURCE = Argument ("nuget-publish-source", (string)null);
var NUGET_SEARCH_SOURCE = Argument ("nuget-search-source", "https://www.nuget.org/api/v2/");
var XAM_ACCT_EMAIL = Argument ("xamarin-account-email", "");
var XAM_ACCT_PWD = Argument ("xamarin-account-password", "");
var BUILD_INFO = DeserializeJsonFromFile<BuildInfo> ("./CI/output/buildinfo.json");
Helpers.CakeContext = Context;
// If more than this # of artifacts are found, abort publish
Helpers.ArtifactThresholdSafetyCount = 45;
Helpers.BuildGroups = BUILD_INFO.BuiltGroups;
Helpers.BuildNames = Argument ("names", Argument ("name", Argument ("n", "")))
.Split (new [] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
Task ("nuget").Does (() =>
{
DirectoryPath currentDir = "./";
var packages = Helpers.FilterFilesForBuildNames ("nupkg");
foreach (var nupkg in packages) {
FilePath pkg = nupkg.FullPath.Replace (MakeAbsolute (currentDir).FullPath, "./");
// Check to see if your nuget source already has this package id + version
if (!NUGET_FORCE_PUSH && IsNuGetPublished (nupkg, NUGET_SEARCH_SOURCE)) {
Information ("Already Published: {0}", nupkg);
continue;
}
Information ("nuget push {0} -Source {1} -ApiKey {2}",
pkg.FullPath,
NUGET_PUBLISH_SOURCE,
NUGET_API_KEY);
int attempts = 0;
bool success = false;
while (attempts < NUGET_MAX_ATTEMPTS) {
attempts++;
try {
NuGetPush (pkg, new NuGetPushSettings {
Source = NUGET_PUBLISH_SOURCE,
ApiKey = NUGET_API_KEY
});
success = true;
break;
} catch {
Warning ("Attempt #{0} of {1} Failed", attempts, NUGET_MAX_ATTEMPTS);
}
}
if (!success)
throw new Exception ("Maximum # of attempts to publish package exceeded");
}
});
Task ("component").Does (() =>
{
var xams = Helpers.FilterFilesForBuildNames ("xam");
var xamarinComponentExe = GetFiles ("./tools/**/xamarin-component.exe").FirstOrDefault ();
foreach (var xam in xams) {
Information ("Uploading Component: {0}", xam);
int attempts = 0;
bool success = false;
while (attempts < COMP_MAX_ATTEMPTS) {
attempts++;
try {
UploadComponent (xam, new XamarinComponentUploadSettings {
Email = XAM_ACCT_EMAIL,
Password = XAM_ACCT_PWD,
});
success = true;
break;
} catch {
Warning ("Failed Component Upload Attempt #{0} of {1}", attempts, COMP_MAX_ATTEMPTS);
}
}
if (!success)
throw new Exception ("Maximum # of attempts to publish package exceeded");
Information ("Waiting {0} ms between uploads...", COMP_WAIT_BETWEEN);
System.Threading.Thread.Sleep (COMP_WAIT_BETWEEN);
}
});
public class BuildInfo
{
public List<BuildGroup> BuiltGroups { get; set; }
}
public class BuildGroup
{
public BuildGroup ()
{
Name = string.Empty;
}
public string Name { get; set; }
public FilePath BuildScript { get; set; }
}
public class Helpers {
public static ICakeContext CakeContext { get;set; }
public static string[] BuildNames { get;set; }
public static List<BuildGroup> BuildGroups { get;set; }
public static int ArtifactThresholdSafetyCount { get;set; }
public static List<FilePath> FilterFilesForBuildNames (string fileExtension)
{
var results = new List<FilePath> ();
// If a filter was specified use it
if (BuildNames != null && BuildNames.Any ()) {
var groupsToPublish = BuildGroups.Where (bg => BuildNames.Any (n => n.ToLower () == bg.Name.ToLower ())).ToList ();
foreach (var buildGroup in groupsToPublish) {
FilePath buildScriptFilePath = buildGroup.BuildScript;
var pattern = string.Format ("{0}/output/**/*.{1}",
CakeContext.MakeAbsolute (buildScriptFilePath.GetDirectory ()).FullPath.TrimEnd ('/'),
fileExtension.TrimStart ('.'));
results.AddRange (CakeContext.GetFiles (pattern));
}
} else {
// No name filters specified, so add all the nupkgs we can find
results.AddRange (CakeContext.GetFiles ("./**/output/**/*." + fileExtension.TrimStart ('.')));
}
if (results.Count > ArtifactThresholdSafetyCount) {
CakeContext.Error ("Suspiciously large number ({0}) of artifacts found, not publishing", results.Count);
return new List<FilePath> ();
}
return results;
}
}
RunTarget (TARGET);