Skip to content

Commit

Permalink
User/masudars/microsoft winget create azure pipelines migration to 1 …
Browse files Browse the repository at this point in the history
…es (#468)
  • Loading branch information
Madhusudhan-MSFT committed Oct 31, 2023
1 parent d7e716c commit 23535d2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 113 deletions.
246 changes: 135 additions & 111 deletions pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ variables:
# Appx Package Directory
appxPackageDir: '$(Build.ArtifactStagingDirectory)\AppxPackages'

# Agent VM image name
vmImageName: "windows-latest"
# WingetCreate Msix Bundle Directory
wingetCreatePackageDir: '$(appxPackageDir)\WingetCreateMsixBundle'

# Working Directory
workingDirectory: "src"
Expand All @@ -36,113 +36,137 @@ variables:
# Target framework
targetFramework: "net6.0-windows10.0.22000.0"

jobs:
- job: GetVersion
variables:
runCodesignValidationInjection: ${{ false }}
skipComponentGovernanceDetection: ${{ true }}
steps:
- powershell: |
[xml]$project = get-content "$(workingDirectory)/WingetCreateCLI/WingetCreateCLI.csproj"
$version = $project.Project.PropertyGroup.Version
echo "##vso[task.setvariable variable=majorMinorVersion;isOutput=true]$version"
name: GetVersionStep
displayName: Get version from CLI project
- job: Build
displayName: Build
dependsOn: GetVersion
variables:
majorMinorVersion: $[dependencies.GetVersion.outputs['GetVersionStep.majorMinorVersion']]
# Only update counter for non-PR builds, otherwise just use 0 for the revision
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
buildVersion: 0
${{ if not(eq(variables['Build.Reason'], 'PullRequest')) }}:
buildVersion: $[counter(variables['majorMinorVersion'], 1)]

version: "$(majorMinorVersion).$(buildVersion).0"
appxBundlePath: '$(appxPackageDir)\Microsoft.WindowsPackageManagerManifestCreator_$(version)_8wekyb3d8bbwe.msixbundle'
resources:
repositories:
- repository: 1ESPipelineTemplates
type: git
name: 1ESPipelineTemplates/1ESPipelineTemplates
ref: refs/tags/release

extends:
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
parameters:
pool:
vmImage: $(vmImageName)

steps:
- checkout: self
lfs: "true"

- powershell: |
echo $(version)
echo $(appxBundlePath)
displayName: Display version and bundle path for diagnosing
- powershell: |
[xml]$manifest = get-content "$(workingDirectory)/WingetCreatePackage/Package.appxmanifest"
$manifest.Package.Identity.Version = "$(version)"
$manifest.save("$(workingDirectory)/WingetCreatePackage/Package.appxmanifest")
displayName: "Update package manifest version"
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: "restore"
feedsToUse: "config"
nugetConfigPath: "NuGet.config"
projects: $(workingDirectory)/**/*.csproj

- task: MSBuild@1
displayName: Build Solution
inputs:
platform: "$(buildPlatform)"
solution: "$(solution)"
configuration: "$(buildConfiguration)"
msbuildArguments: '/p:AppxBundleOutput="$(appxBundlePath)"
/p:AppxBundle=Always
/p:UapAppxPackageBuildMode=SideloadOnly
/p:AppxPackageSigningEnabled=false'

- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
displayName: 'Generate SBOM'
inputs:
BuildDropPath: '$(appxPackageDir)'

- publish: $(appxBundlePath)
artifact: msixbundle
displayName: Publish msix bundle

- task: ComponentGovernanceComponentDetection@0
displayName: Component Governance
inputs:
scanType: "Register"
verbosity: "Verbose"
alertWarningLevel: "High"

- task: notice@0
displayName: "NOTICE File Generator"
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
inputs:
outputfile: "$(System.DefaultWorkingDirectory)/temp/NOTICE.txt"
outputformat: "text"

- bash: |
echo "Diffing existing NOTICE.txt with generated version"
diff -w NOTICE.txt temp/NOTICE.txt
if [[ $? -ne 0 ]];
then
echo "Notice file modified"
echo "*******************************************************************************************************"
echo "Download the updated NOTICE.txt from the build artifacts and update the file in your PR, then re-submit"
echo "*******************************************************************************************************"
exit 1
else
echo "Notice file not modified."
fi
displayName: "Trigger build warning if NOTICE.txt file needs to be modified."
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
continueOnError: "true"
- task: VSTest@2
displayName: Run Tests
inputs:
testSelector: "testAssemblies"
testAssemblyVer2: 'src\WingetCreateTests\WingetCreateTests\bin\$(buildPlatform)\$(buildConfiguration)\$(targetFramework)\WingetCreateTests.dll'
runSettingsFile: 'src\WingetCreateTests\WingetCreateTests\Test.runsettings'
overrideTestrunParameters: '-WingetPkgsTestRepoOwner microsoft -WingetPkgsTestRepo winget-pkgs-submission-test -GitHubAppPrivateKey "$(GitHubApp_PrivateKey)"'
name: Azure-Pipelines-1ESPT-ExDShared
image: windows-2022
os: windows
customBuildTags:
- ES365AIMigrationTooling

stages:
- stage: GetVersion_Build

jobs:
- job: GetVersion
variables:
runCodesignValidationInjection: ${{ false }}
skipComponentGovernanceDetection: ${{ true }}
steps:
- task: PowerShell@2
name: GetVersionStep
displayName: Get version from CLI project
inputs:
targetType: "inline"
script: |
[xml]$project = get-content "$(workingDirectory)/WingetCreateCLI/WingetCreateCLI.csproj"
$version = $project.Project.PropertyGroup.Version
echo "##vso[task.setvariable variable=majorMinorVersion;isOutput=true]$version"
- job: Build
displayName: Build
dependsOn: GetVersion
variables:
majorMinorVersion: $[dependencies.GetVersion.outputs['GetVersionStep.majorMinorVersion']]
# Only update counter for non-PR builds, otherwise just use 0 for the revision
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
buildVersion: 0
${{ if not(eq(variables['Build.Reason'], 'PullRequest')) }}:
buildVersion: $[counter(variables['majorMinorVersion'], 1)]

version: "$(majorMinorVersion).$(buildVersion).0"
appxBundlePath: '$(wingetCreatePackageDir)\Microsoft.WindowsPackageManagerManifestCreator_$(version)_8wekyb3d8bbwe.msixbundle'

steps:
- checkout: self
lfs: "true"

- task: PowerShell@2
displayName: Display version and bundle path for diagnosing
inputs:
targetType: inline
script: |
echo $(version)
echo $(appxBundlePath)
- task: PowerShell@2
displayName: "Update package manifest version"
inputs:
targetType: inline
script: |
[xml]$manifest = get-content "$(workingDirectory)/WingetCreatePackage/Package.appxmanifest"
$manifest.Package.Identity.Version = "$(version)"
$manifest.save("$(workingDirectory)/WingetCreatePackage/Package.appxmanifest")
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: "restore"
feedsToUse: "config"
nugetConfigPath: "NuGet.config"
projects: $(workingDirectory)/**/*.csproj

- task: MSBuild@1
displayName: Build Solution
inputs:
platform: "$(buildPlatform)"
solution: "$(solution)"
configuration: "$(buildConfiguration)"
msbuildArguments: '/p:AppxBundleOutput="$(appxBundlePath)"
/p:AppxBundle=Always
/p:UapAppxPackageBuildMode=SideloadOnly
/p:AppxPackageSigningEnabled=false'

- task: 1ES.PublishPipelineArtifact@1
inputs:
targetPath: $(wingetCreatePackageDir)
artifactName: wingetcreate_msixbundle
displayName: Publish WingetCreate msix bundle

- task: ComponentGovernanceComponentDetection@0
displayName: Component Governance
inputs:
scanType: "Register"
verbosity: "Verbose"
alertWarningLevel: "High"

- task: notice@0
displayName: "NOTICE File Generator"
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
inputs:
outputfile: "$(System.DefaultWorkingDirectory)/temp/NOTICE.txt"
outputformat: "text"

- bash: |
echo "Diffing existing NOTICE.txt with generated version"
diff -w NOTICE.txt temp/NOTICE.txt
if [[ $? -ne 0 ]];
then
echo "Notice file modified"
echo "*******************************************************************************************************"
echo "Download the updated NOTICE.txt from the build artifacts and update the file in your PR, then re-submit"
echo "*******************************************************************************************************"
exit 1
else
echo "Notice file not modified."
fi
displayName: "Trigger build warning if NOTICE.txt file needs to be modified."
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
continueOnError: "true"
- task: VSTest@2
displayName: Run Tests
inputs:
testSelector: "testAssemblies"
testAssemblyVer2: 'src\WingetCreateTests\WingetCreateTests\bin\$(buildPlatform)\$(buildConfiguration)\$(targetFramework)\WingetCreateTests.dll'
runSettingsFile: 'src\WingetCreateTests\WingetCreateTests\Test.runsettings'
overrideTestrunParameters: '-WingetPkgsTestRepoOwner microsoft -WingetPkgsTestRepo winget-pkgs-submission-test -GitHubAppPrivateKey "$(GitHubApp_PrivateKey)"'
2 changes: 1 addition & 1 deletion src/WingetCreateCore/WingetCreateCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
<PackageReference Include="Microsoft.Msix.Utils" Version="2.1.1" />
<!--https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#generatepathproperty-->
<PackageReference Include="Microsoft.WindowsPackageManager.Utils" Version="1.5.2" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.WindowsPackageManager.Utils" Version="1.7.1" GeneratePathProperty="true" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="NLog" Version="4.7.9" />
<PackageReference Include="NSwag.MSBuild" Version="13.11.1">
Expand Down
14 changes: 13 additions & 1 deletion src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Microsoft.WingetCreateE2ETests
{
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WingetCreateCLI.Commands;
Expand All @@ -11,6 +12,8 @@ namespace Microsoft.WingetCreateE2ETests
using Microsoft.WingetCreateTests;
using Microsoft.WingetCreateUnitTests;
using NUnit.Framework;
using Octokit;
using Polly;

/// <summary>
/// This class tests the entire end-to-end flow of the tool, from submitting a PR, retrieving the package from the repo
Expand Down Expand Up @@ -68,7 +71,16 @@ private async Task RunSubmitAndUpdateFlow(string packageId, string manifestPath,
};
Assert.IsTrue(await submitCommand.Execute(), "Command should have succeeded");

await this.gitHub.MergePullRequest(submitCommand.PullRequestNumber);
var mergeRetryPolicy = Policy
.Handle<PullRequestNotMergeableException>()
.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(i));

await mergeRetryPolicy.ExecuteAsync(async () =>
{
// Attempting to merge immediately after creating the PR can throw an exception if the branch
// has not completed verification if it can be merged. Wait and retry.
await this.gitHub.MergePullRequest(submitCommand.PullRequestNumber);
});

TestUtils.SetMockHttpResponseContent(installerName);
UpdateCommand updateCommand = new UpdateCommand
Expand Down

0 comments on commit 23535d2

Please sign in to comment.