Skip to content

Commit d67b9f1

Browse files
ci: setup repo for csharp v1 generation (#195) [skip-ci]
* ci: setup repo for generation * ci: rp support added, release pipeline added
1 parent eac1906 commit d67b9f1

File tree

9 files changed

+536
-0
lines changed

9 files changed

+536
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
# Build, sign, package and deploy .NET package for Microsoft.Agents.M365Copilot
5+
6+
name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
7+
8+
trigger:
9+
branches:
10+
include:
11+
- main
12+
paths:
13+
include:
14+
- 'dotnet/src/Microsoft.Agents.M365Copilot/Generated/**'
15+
- 'dotnet/src/Microsoft.Agents.M365Copilot/**/*.cs'
16+
- 'dotnet/src/Microsoft.Agents.M365Copilot/Microsoft.Agents.M365Copilot.csproj'
17+
tags:
18+
include: # ex Microsoft.Agents.M365Copilot-v0.1.0-preview.0, must use the hyphen t distinguish from Beta
19+
- 'Microsoft.Agents.M365Copilot-*'
20+
21+
pr: none
22+
23+
variables:
24+
buildConfiguration: 'Release'
25+
buildPlatform: 'Any CPU'
26+
nugetArtifacts: '$(Build.ArtifactStagingDirectory)/Nugets'
27+
28+
resources:
29+
repositories:
30+
- repository: 1ESPipelineTemplates
31+
type: git
32+
name: 1ESPipelineTemplates/1ESPipelineTemplates
33+
ref: refs/tags/release
34+
35+
extends:
36+
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
37+
parameters:
38+
pool:
39+
name: Azure-Pipelines-1ESPT-ExDShared
40+
vmImage: windows-latest
41+
stages:
42+
- stage: build
43+
displayName: 'Build and Sign .NET Package'
44+
# This condition allows the build to run for both tagged builds and manual builds.
45+
condition: or(contains(variables['Build.SourceBranch'], 'Microsoft.Agents.M365Copilot-'), eq(variables['Build.Reason'], 'Manual'))
46+
jobs:
47+
- job: build_and_sign
48+
displayName: 'Build, Test, and Sign V1'
49+
pool:
50+
name: Azure-Pipelines-1ESPT-ExDShared
51+
vmImage: windows-latest
52+
steps:
53+
- task: UseDotNet@2
54+
displayName: 'Use .NET 8'
55+
inputs:
56+
version: 8.x
57+
- task: UseDotNet@2
58+
displayName: 'Use .NET 6 (for code signing tasks)'
59+
inputs:
60+
packageType: sdk
61+
version: 6.x
62+
- task: NuGetToolInstaller@1
63+
displayName: 'Install Nuget dependency manager'
64+
inputs:
65+
versionSpec: '>=6.0.0'
66+
checkLatest: true
67+
68+
# Enable signing for the .NET projects
69+
- pwsh: |
70+
# This allows us to not have to checkin .csproj or Directory.Build.props files with DelaySign and
71+
# SignAssembly set to to true. If the flag is set, then project is not debuggable with SignAssembly set
72+
# to true.
73+
$buildPropsPath = "$(Build.SourcesDirectory)/dotnet/Directory.Build.props"
74+
if (Test-Path $buildPropsPath) {
75+
$doc = New-Object System.Xml.XmlDocument
76+
$doc.Load($buildPropsPath)
77+
# Set the DelaySign element to 'true' so that delay signing is set.
78+
$delaySign = $doc.SelectSingleNode("//DelaySign");
79+
$delaySign.'#text'= "true"
80+
# Set the SignAssembly element to 'true' so that we can sign the assemblies.
81+
$signAssembly = $doc.SelectSingleNode("//SignAssembly");
82+
$signAssembly.'#text'= "true"
83+
$doc.Save($buildPropsPath);
84+
Write-Host "Updated the Directory.Build.props file so that we can sign the built assemblies."
85+
} else {
86+
Write-Host ""##vso[task.complete result=Failed;]Directory.Build.props file not found."
87+
}
88+
89+
displayName: 'Set project build properties ready to sign'
90+
91+
# Build v1
92+
- task: DotNetCoreCLI@2
93+
displayName: 'Build Microsoft.Agents.M365Copilot'
94+
# This condition allows the build to run for both tag builds and manual builds.
95+
condition: or(contains(variables['Build.SourceBranch'], 'Microsoft.Agents.M365Copilot-'), eq(variables['Build.Reason'], 'Manual'))
96+
inputs:
97+
projects: '$(Build.SourcesDirectory)/dotnet/src/Microsoft.Agents.M365Copilot/Microsoft.Agents.M365Copilot.csproj'
98+
arguments: '--configuration $(buildConfiguration) --no-incremental'
99+
100+
101+
# Strong name for v1 using ESRP
102+
- template: .azure-pipelines/templates/esrp-strongname.yml@self
103+
parameters:
104+
projectName: Microsoft.Agents.M365Copilot
105+
buildConfiguration: $(buildConfiguration)
106+
107+
# Code signing for v1 using ESRP
108+
- template: .azure-pipelines/templates/esrp-codesign-dll.yml@self
109+
parameters:
110+
projectName: Microsoft.Agents.M365Copilot
111+
buildConfiguration: $(buildConfiguration)
112+
113+
# Pack v1
114+
- pwsh: dotnet pack $(Build.SourcesDirectory)/dotnet/src/Microsoft.Agents.M365Copilot/Microsoft.Agents.M365Copilot.csproj /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg --no-build --output $(nugetArtifacts) --configuration $(buildConfiguration)
115+
# This condition allows the pack command to run for both tag builds and manual builds.
116+
condition: or(contains(variables['Build.SourceBranch'], 'Microsoft.Agents.M365Copilot-'), eq(variables['Build.Reason'], 'Manual'))
117+
displayName: 'Dotnet pack v1'
118+
119+
# Sign v1 NuGet package using ESRP
120+
- template: .azure-pipelines/templates/esrp-codesign-nuget.yml@self
121+
parameters:
122+
projectName: Microsoft.Agents.M365Copilot
123+
artifactStagingDirectory: $(nugetArtifacts)
124+
125+
templateContext:
126+
outputs:
127+
- output: pipelineArtifact
128+
displayName: 'Stage Microsoft.Agents.M365Copilot package artifacts'
129+
artifactName: Nugets
130+
targetPath: $(nugetArtifacts)
131+
132+
- stage: deploy
133+
displayName: 'Deploy v1 NuGet Package'
134+
dependsOn: build
135+
condition: or(and(contains(variables['Build.SourceBranch'], 'Microsoft.Agents.M365Copilot-'), succeeded()), eq(variables['Build.Reason'], 'Manual'))
136+
jobs:
137+
- deployment: publish_nuget_package
138+
displayName: 'Publish v1 NuGet Package'
139+
environment: agents-m365copilot-prod
140+
pool:
141+
name: Azure-Pipelines-1ESPT-ExDShared
142+
vmImage: windows-latest
143+
os: windows
144+
templateContext:
145+
type: releaseJob
146+
isProduction: true
147+
inputs:
148+
- input: pipelineArtifact
149+
artifactName: Nugets
150+
targetPath: $(nugetArtifacts)
151+
strategy:
152+
runOnce:
153+
deploy:
154+
steps:
155+
- task: 1ES.PublishNuget@1
156+
displayName: 'Publish v1 NuGet package via NuGet API Key'
157+
inputs:
158+
useDotNetTask: false
159+
packageParentPath: $(nugetArtifacts)
160+
packagesToPush: '!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg;$(nugetArtifacts)/**/*nupkg'
161+
nuGetFeedType: external # Change to external for external
162+
publishPackageMetadata: true
163+
publishFeedCredentials: 'M365 Copilot NuGet Connection'

.github/workflows/release-please-gha.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# variables and secrets, and then runs the release-please-action to manage versioning and changelogs.
1010

1111
name: Release Please
12+
permissions:
13+
contents: read
14+
pull-requests: write
1215

1316
on:
1417
push:

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"dotnet/src/Microsoft.Agents.M365Copilot": "0.1.0-preview.0",
23
"dotnet/src/Microsoft.Agents.M365Copilot.Beta": "1.0.0-preview.7",
34
"dotnet/src/Microsoft.Agents.M365Copilot.Core": "1.0.0-preview.3",
45
"typescript/packages/agents-m365copilot-beta": "1.0.0-preview.7",

dotnet/Microsoft.Agents.M365Copilot.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Agents.M365Copilot.Sample", "src\Microsoft.Agents.M365Copilot.Sample\Microsoft.Agents.M365Copilot.Sample.csproj", "{FAC87736-1178-45E3-8692-CEE2FE051BBC}"
1919
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Agents.M365Copilot", "src\Microsoft.Agents.M365Copilot\Microsoft.Agents.M365Copilot.csproj", "{DC8281F0-648B-B18D-DC4D-4C503F96E264}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -87,6 +89,18 @@ Global
8789
{FAC87736-1178-45E3-8692-CEE2FE051BBC}.Release|x64.Build.0 = Release|Any CPU
8890
{FAC87736-1178-45E3-8692-CEE2FE051BBC}.Release|x86.ActiveCfg = Release|Any CPU
8991
{FAC87736-1178-45E3-8692-CEE2FE051BBC}.Release|x86.Build.0 = Release|Any CPU
92+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|x64.ActiveCfg = Debug|Any CPU
95+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|x64.Build.0 = Debug|Any CPU
96+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|x86.ActiveCfg = Debug|Any CPU
97+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Debug|x86.Build.0 = Debug|Any CPU
98+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|Any CPU.ActiveCfg = Release|Any CPU
99+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|Any CPU.Build.0 = Release|Any CPU
100+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|x64.ActiveCfg = Release|Any CPU
101+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|x64.Build.0 = Release|Any CPU
102+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|x86.ActiveCfg = Release|Any CPU
103+
{DC8281F0-648B-B18D-DC4D-4C503F96E264}.Release|x86.Build.0 = Release|Any CPU
90104
EndGlobalSection
91105
GlobalSection(SolutionProperties) = preSolution
92106
HideSolutionNode = FALSE
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
namespace Microsoft.Agents.M365Copilot
6+
{
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Net.Http;
11+
using System.Reflection;
12+
using Azure.Core;
13+
using Microsoft.Agents.M365Copilot;
14+
using Microsoft.Agents.M365Copilot.Core.Requests;
15+
using Microsoft.Kiota.Abstractions;
16+
using Microsoft.Kiota.Abstractions.Authentication;
17+
18+
/// <summary>
19+
/// A default client implementation.
20+
/// </summary>
21+
public class AgentsM365CopilotServiceClient : BaseAgentsM365CopilotServiceClient, IBaseClient, IDisposable
22+
{
23+
private static readonly Version assemblyVersion = typeof(AgentsM365CopilotServiceClient).GetTypeInfo().Assembly.GetName().Version;
24+
private static readonly CopilotClientOptions copilotClientOptions = new()
25+
{
26+
ServiceLibraryClientVersion = $"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}",
27+
ServiceTargetVersion = string.Empty,
28+
};
29+
30+
/// <summary>
31+
/// Constructs a new <see cref="AgentsM365CopilotServiceClient"/>.
32+
/// </summary>
33+
/// <param name="requestAdapter">The custom <see cref="IRequestAdapter"/> to be used for making requests</param>
34+
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
35+
public AgentsM365CopilotServiceClient(IRequestAdapter requestAdapter, string baseUrl = null) : base(InitializeRequestAdapterWithBaseUrl(requestAdapter, baseUrl))
36+
{
37+
this.RequestAdapter = requestAdapter;
38+
}
39+
40+
/// <summary>
41+
/// Constructs a new <see cref="AgentsM365CopilotServiceClient"/>.
42+
/// </summary>
43+
/// <param name="tokenCredential">The <see cref="TokenCredential"/> for authenticating request messages.</param>
44+
/// <param name="scopes">List of scopes for the authentication context.</param>
45+
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
46+
public AgentsM365CopilotServiceClient(
47+
TokenCredential tokenCredential,
48+
IEnumerable<string> scopes = null,
49+
string baseUrl = null
50+
) : this(new Agents.M365Copilot.Core.Authentication.AzureIdentityAuthenticationProvider(tokenCredential, null, null, true, scopes?.ToArray() ?? []), baseUrl)
51+
{
52+
}
53+
54+
/// <summary>
55+
/// Constructs a new <see cref="AgentsM365CopilotServiceClient"/>.
56+
/// </summary>
57+
/// <param name="httpClient">The customized <see cref="HttpClient"/> to be used for making requests</param>
58+
/// <param name="tokenCredential">The <see cref="TokenCredential"/> for authenticating request messages.</param>
59+
/// <param name="scopes">List of scopes for the authentication context.</param>
60+
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
61+
public AgentsM365CopilotServiceClient(
62+
HttpClient httpClient,
63+
TokenCredential tokenCredential,
64+
IEnumerable<string> scopes = null,
65+
string baseUrl = null
66+
) : this(httpClient, new Agents.M365Copilot.Core.Authentication.AzureIdentityAuthenticationProvider(tokenCredential, null, null, true, scopes?.ToArray() ?? []), baseUrl)
67+
{
68+
}
69+
70+
/// <summary>
71+
/// Constructs a new <see cref="AgentsM365CopilotServiceClient"/>.
72+
/// </summary>
73+
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.</param>
74+
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
75+
public AgentsM365CopilotServiceClient(
76+
IAuthenticationProvider authenticationProvider,
77+
string baseUrl = null
78+
) : this(CopilotClientFactory.Create(copilotClientOptions, version: "v1.0"), authenticationProvider, baseUrl)
79+
{
80+
}
81+
82+
/// <summary>
83+
/// Constructs a new <see cref="AgentsM365CopilotServiceClient"/>.
84+
/// </summary>
85+
/// <param name="httpClient">The customized <see cref="HttpClient"/> to be used for making requests</param>
86+
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.
87+
/// Defaults to <see cref="AnonymousAuthenticationProvider"/> so that authentication is handled by custom middleware in the httpClient</param>
88+
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
89+
public AgentsM365CopilotServiceClient(
90+
HttpClient httpClient,
91+
IAuthenticationProvider authenticationProvider = null,
92+
string baseUrl = null) : this(new BaseRequestAdapter(authenticationProvider ?? new AnonymousAuthenticationProvider(), copilotClientOptions, httpClient: httpClient), baseUrl)
93+
{
94+
}
95+
96+
/// <summary>
97+
/// Gets the <see cref="IRequestAdapter"/> for sending requests.
98+
/// </summary>
99+
public new IRequestAdapter RequestAdapter
100+
{
101+
get; set;
102+
}
103+
104+
/// <summary>
105+
/// Cleanup anything as needed
106+
/// </summary>
107+
public void Dispose()
108+
{
109+
if (this.RequestAdapter is IDisposable disposable)
110+
{
111+
disposable.Dispose();
112+
}
113+
}
114+
115+
private static IRequestAdapter InitializeRequestAdapterWithBaseUrl(IRequestAdapter requestAdapter, string baseUrl)
116+
{
117+
if (!string.IsNullOrEmpty(baseUrl))
118+
{
119+
requestAdapter.BaseUrl = baseUrl;
120+
}
121+
122+
return requestAdapter;
123+
}
124+
}
125+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+

0 commit comments

Comments
 (0)