-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from microsoft/getpackagesoperation
Add new GetPackages operation
- Loading branch information
Showing
18 changed files
with
356 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
trigger: none | ||
|
||
parameters: | ||
- name: Version | ||
default: '1.0.0' | ||
|
||
pool: | ||
vmImage: windows-latest | ||
|
||
variables: | ||
- name: projectName | ||
value: "PackageUploader" | ||
- name: buildConfiguration | ||
value: "release" | ||
- name: esrpConnectedServiceName | ||
value: "ESRP CodeSigning External" | ||
- name: version | ||
value: ${{ parameters.Version }} | ||
|
||
stages: | ||
- stage: Build | ||
displayName: | ||
|
||
jobs: | ||
- job: BuildWindows | ||
displayName: Build win-x64 | ||
|
||
variables: | ||
- name: buildRuntime | ||
value: "win-x64" | ||
|
||
steps: | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'dotnet publish' | ||
inputs: | ||
command: 'publish' | ||
publishWebProjects: false | ||
projects: './src/PackageUploader.Application/PackageUploader.Application.csproj' | ||
arguments: '--self-contained -o $(Build.BinariesDirectory) -p:Version=$(version) -r $(buildRuntime) -c $(buildConfiguration)' | ||
zipAfterPublish: false | ||
modifyOutputPath: false | ||
|
||
- task: EsrpCodeSigning@3 | ||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) | ||
displayName: 'Code sign binary files' | ||
inputs: | ||
ConnectedServiceName: $(esrpConnectedServiceName) | ||
FolderPath: '$(Build.BinariesDirectory)' | ||
Pattern: '*.exe' | ||
signConfigType: 'inlineSignParams' | ||
inlineOperation: | | ||
[ | ||
{ | ||
"KeyCode": "CP-230012", | ||
"OperationCode": "SigntoolSign", | ||
"ToolName": "sign", | ||
"ToolVersion": "1.0", | ||
"Parameters": { | ||
"OpusName": "Microsoft", | ||
"OpusInfo": "https://www.microsoft.com", | ||
"FileDigest": "/fd SHA256", | ||
"PageHash": "/NPH", | ||
"TimeStamp": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" | ||
} | ||
}, | ||
{ | ||
"KeyCode": "CP-230012", | ||
"OperationCode": "SigntoolVerify", | ||
"ToolName": "sign", | ||
"ToolVersion": "1.0", | ||
"Parameters": {} | ||
} | ||
] | ||
SessionTimeout: '60' | ||
MaxConcurrency: '50' | ||
MaxRetryAttempts: '5' | ||
|
||
- task: PowerShell@2 | ||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) | ||
displayName: 'Remove signing result file' | ||
inputs: | ||
targetType: 'inline' | ||
script: 'Remove-Item * -Include *.md' | ||
workingDirectory: '$(Build.BinariesDirectory)' | ||
|
||
- task: ArchiveFiles@2 | ||
displayName: 'Zip files to Staging directory' | ||
inputs: | ||
rootFolderOrFile: '$(Build.BinariesDirectory)' | ||
includeRootFolder: false | ||
archiveType: 'zip' | ||
archiveFile: '$(Build.ArtifactStagingDirectory)/$(projectName).$(version).$(buildRuntime).zip' | ||
replaceExistingArchive: true | ||
|
||
- task: PublishPipelineArtifact@1 | ||
displayName: 'publish artifact to pipeline' | ||
inputs: | ||
targetPath: '$(Build.ArtifactStagingDirectory)' | ||
artifact: '$(projectName).$(buildRuntime)' | ||
publishLocation: 'pipeline' | ||
|
||
- job: BuildLinux | ||
displayName: Build linux-x64 | ||
|
||
variables: | ||
- name: buildRuntime | ||
value: "linux-x64" | ||
|
||
steps: | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'dotnet publish' | ||
inputs: | ||
command: 'publish' | ||
publishWebProjects: false | ||
projects: './src/PackageUploader.Application/PackageUploader.Application.csproj' | ||
arguments: '--self-contained -o $(Build.BinariesDirectory) -p:Version=$(version) -r $(buildRuntime) -c $(buildConfiguration)' | ||
zipAfterPublish: false | ||
modifyOutputPath: false | ||
|
||
- task: ArchiveFiles@2 | ||
displayName: 'Zip files to Staging directory' | ||
inputs: | ||
rootFolderOrFile: '$(Build.BinariesDirectory)' | ||
includeRootFolder: false | ||
archiveType: 'zip' | ||
archiveFile: '$(Build.ArtifactStagingDirectory)/$(projectName).$(version).$(buildRuntime).zip' | ||
replaceExistingArchive: true | ||
|
||
- task: PublishPipelineArtifact@1 | ||
displayName: 'publish artifact to pipeline' | ||
inputs: | ||
targetPath: '$(Build.ArtifactStagingDirectory)' | ||
artifact: '$(projectName).$(buildRuntime)' | ||
publishLocation: 'pipeline' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/PackageUploader.Application/Config/GetPackagesOperationConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace PackageUploader.Application.Config; | ||
|
||
internal class GetPackagesOperationConfig : PackageBranchOperationConfig | ||
{ | ||
internal override string GetOperationName() => "GetPackages"; | ||
|
||
public string MarketGroupName { get; set; } = "default"; | ||
|
||
protected override void Validate(IList<ValidationResult> validationResults) | ||
{ | ||
if (string.IsNullOrWhiteSpace(MarketGroupName)) | ||
{ | ||
MarketGroupName = "default"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using PackageUploader.ClientApi.Client.Ingestion.Models; | ||
|
||
namespace PackageUploader.Application.Models; | ||
|
||
public class Package | ||
{ | ||
/// <summary> | ||
/// If the package is certified | ||
/// </summary> | ||
public bool? IsCertified { get; set; } | ||
|
||
/// <summary> | ||
/// File name of the package | ||
/// </summary> | ||
public string FileName { get; set; } | ||
|
||
/// <summary> | ||
/// File size of the package | ||
/// </summary> | ||
public long? FileSize { get; set; } | ||
|
||
public Package(GamePackage gamePackage) | ||
{ | ||
IsCertified = gamePackage.IsCertified; | ||
FileName = gamePackage.FileName; | ||
FileSize = gamePackage.FileSize; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/PackageUploader.Application/Operations/GetPackagesOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using PackageUploader.Application.Config; | ||
using PackageUploader.Application.Extensions; | ||
using PackageUploader.Application.Models; | ||
using PackageUploader.ClientApi; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace PackageUploader.Application.Operations; | ||
|
||
internal class GetPackagesOperation : Operation | ||
{ | ||
private readonly IPackageUploaderService _storeBrokerService; | ||
private readonly ILogger<GetPackagesOperation> _logger; | ||
private readonly GetPackagesOperationConfig _config; | ||
|
||
public GetPackagesOperation(IPackageUploaderService storeBrokerService, ILogger<GetPackagesOperation> logger, IOptions<GetPackagesOperationConfig> config) : base(logger) | ||
{ | ||
_storeBrokerService = storeBrokerService ?? throw new ArgumentNullException(nameof(storeBrokerService)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_config = config?.Value ?? throw new ArgumentNullException(nameof(config)); | ||
} | ||
|
||
protected override async Task ProcessAsync(CancellationToken ct) | ||
{ | ||
_logger.LogInformation("Starting {operationName} operation.", _config.GetOperationName()); | ||
|
||
var product = await _storeBrokerService.GetProductAsync(_config, ct).ConfigureAwait(false); | ||
var packageBranch = await _storeBrokerService.GetGamePackageBranch(product, _config, ct).ConfigureAwait(false); | ||
var packages = await _storeBrokerService.GetGamePackagesAsync(product, packageBranch, _config.MarketGroupName, ct) | ||
.Select(gamePackage => new Package(gamePackage)) | ||
.ToListAsync(ct).ConfigureAwait(false); | ||
|
||
var packagesJson = PackagesToJson(packages); | ||
_logger.LogInformation("Packages:"); | ||
Console.WriteLine(packagesJson); | ||
} | ||
|
||
private static readonly JsonSerializerOptions DefaultJsonSerializerOptions = new() | ||
{ | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
}; | ||
|
||
public static string PackagesToJson(IEnumerable<Package> packages) | ||
{ | ||
try | ||
{ | ||
var serializedObject = JsonSerializer.Serialize(packages, DefaultJsonSerializerOptions); | ||
return serializedObject; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return $"Could not serialize packages to json - {ex.Message}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.