Skip to content

Commit ec8a7d6

Browse files
Add version number information in backend, frontend and build process (microsoft#165)
### Motivation and Context We want to make it easier to know which version we are dealing with / debugging ### Description - Add version number information in backend, frontend and build process - Remove unused deployment files ![image](https://github.com/microsoft/chat-copilot/assets/8430998/57112301-16d6-4bd1-ac1d-d67253976f1e) ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [Contribution Guidelines](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Teresa Hoang <[email protected]>
1 parent 2143f05 commit ec8a7d6

13 files changed

Lines changed: 140 additions & 133 deletions

File tree

‎.github/workflows/copilot-build-backend.yml‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,35 @@ jobs:
3434
- uses: actions/checkout@v3
3535
with:
3636
clean: true
37+
fetch-depth: 0
3738

38-
- name: Package Copilot Chat WebAPI
39-
run: |
40-
scripts\deploy\package-webapi.ps1 -Configuration Release -DotnetFramework net6.0 -TargetRuntime win-x64 -OutputDirectory ${{ github.workspace }}\scripts\deploy
39+
- name: Install GitVersion
40+
uses: gittools/actions/gitversion/setup@v0
41+
with:
42+
versionSpec: '5.x'
4143

42-
- name: Check formatting of Copilot Chat WebAPI
43-
run: |
44-
cd webapi/
45-
dotnet format --verify-no-changes --verbosity diagnostic
44+
- name: Determine version
45+
id: gitversion
46+
uses: gittools/actions/gitversion/execute@v0
4647

4748
- name: Set version tag
4849
id: versiontag
4950
run: |
50-
$VERSION_TAG="$(Get-Date -Format "MMddHHmmss")"
51+
$VERSION_TAG = "${{ steps.gitversion.outputs.Major }}."
52+
$VERSION_TAG += "${{ steps.gitversion.outputs.Minor }}."
53+
$VERSION_TAG += "${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
5154
echo $VERSION_TAG
5255
Write-Output "versiontag=$VERSION_TAG" >> $env:GITHUB_OUTPUT
5356
57+
- name: Package Copilot Chat WebAPI
58+
run: |
59+
scripts\deploy\package-webapi.ps1 -Configuration Release -DotnetFramework net6.0 -TargetRuntime win-x64 -OutputDirectory ${{ github.workspace }}\scripts\deploy -Version ${{ steps.versiontag.outputs.versiontag }} -InformationalVersion "Built from commit ${{ steps.gitversion.outputs.ShortSha }} on $(Get-Date -Format "yyyy-MM-dd")"
60+
61+
- name: Check formatting of Copilot Chat WebAPI
62+
run: |
63+
cd webapi/
64+
dotnet format --verify-no-changes --verbosity diagnostic
65+
5466
- name: Upload package to artifacts
5567
uses: actions/upload-artifact@v3
5668
with:

‎.github/workflows/copilot-deploy-frontend.yml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
- uses: actions/checkout@v3
3939
with:
4040
clean: true
41+
fetch-depth: 0
4142

4243
- name: Install Azure CLI
4344
run: |
@@ -69,6 +70,24 @@ jobs:
6970
echo "::add-mask::$swaToken"
7071
echo "SWA_CLI_DEPLOYMENT_TOKEN=$swaToken" >> $GITHUB_ENV
7172
73+
- name: Install GitVersion
74+
uses: gittools/actions/gitversion/setup@v0
75+
with:
76+
versionSpec: '5.x'
77+
78+
- name: Determine version
79+
id: gitversion
80+
uses: gittools/actions/gitversion/execute@v0
81+
82+
- name: Set version tag
83+
id: versiontag
84+
run: |
85+
$VERSION_TAG = "${{ steps.gitversion.outputs.Major }}."
86+
$VERSION_TAG += "${{ steps.gitversion.outputs.Minor }}."
87+
$VERSION_TAG += "${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
88+
echo $VERSION_TAG
89+
Write-Output "versiontag=$VERSION_TAG" >> $env:GITHUB_OUTPUT
90+
7291
- name: Deploy SWA
7392
run: |
74-
scripts/deploy/deploy-webapp.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{inputs.DEPLOYMENT_NAME}} --application-id ${{vars.APPLICATION_CLIENT_ID}} --authority ${{secrets.APPLICATION_AUTHORITY}} --no-redirect
93+
scripts/deploy/deploy-webapp.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{inputs.DEPLOYMENT_NAME}} --application-id ${{vars.APPLICATION_CLIENT_ID}} --authority ${{secrets.APPLICATION_AUTHORITY}} --no-redirect -version ${{ steps.versiontag.outputs.versiontag }} -version-info "Built from commit ${{ steps.gitversion.outputs.ShortSha }} on $(Get-Date -Format "yyyy-MM-dd")"

‎.github/workflows/update-version.sh‎

Lines changed: 0 additions & 107 deletions
This file was deleted.

‎.gitignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,5 +485,8 @@ webapp/public/.well-known*
485485
# Auto-generated solution file from Visual Studio
486486
webapi/CopilotChatWebApi.sln
487487

488+
# Files created for deployments
489+
/deploy/
490+
488491
# Tesseract OCR language data files
489-
*.traineddata
492+
*.traineddata

‎scripts/deploy/deploy-webapp.ps1‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ param(
2727
[Parameter(Mandatory=$false)]
2828
[string]
2929
# Authority for client applications that are not configured as multi-tenant.
30-
$Authority="https://login.microsoftonline.com/common"
30+
$Authority="https://login.microsoftonline.com/common",
31+
32+
[string]
33+
# Version to display in UI.
34+
$Version = "",
35+
36+
[string]
37+
# Additional information given in version info. (Ex: commit SHA)
38+
$VersionInfo = ""
3139
)
3240

3341
Write-Host "Setting up Azure credentials..."
@@ -64,6 +72,8 @@ Write-Host "Writing environment variables to '$envFilePath'..."
6472
"REACT_APP_AAD_AUTHORITY=$Authority" | Out-File -FilePath $envFilePath -Append
6573
"REACT_APP_AAD_CLIENT_ID=$ApplicationClientId" | Out-File -FilePath $envFilePath -Append
6674
"REACT_APP_SK_API_KEY=$webapiApiKey" | Out-File -FilePath $envFilePath -Append
75+
"REACT_APP_SK_VERSION=$Version" | Out-File -FilePath $envFilePath -Append
76+
"REACT_APP_SK_BUILD_INFO=$VersionInfo" | Out-File -FilePath $envFilePath -Append
6777

6878
Write-Host "Generating SWA config..."
6979
$swaConfig = $(Get-Content "$PSScriptRoot/../../webapp/template.swa-cli.config.json" -Raw)

‎scripts/deploy/deploy-webapp.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ usage() {
1515
echo " -rg, --resource-group RESOURCE_GROUP Resource group name from a 'deploy-azure.sh' deployment (mandatory)"
1616
echo " -a, --application-id APPLICATION_ID Client application ID (mandatory)"
1717
echo " -au, --authority Authority to use for client applications that are not configured as multi-tenant. Defaults to (https://login.microsoftonline.com/common) if not specified."
18+
echo " -v --version VERSION Version to display in UI (default: 1.0.0)"
19+
echo " -i --version-info INFO Additional info to put in version details"
1820
echo " -nr, --no-redirect Do not attempt to register redirect URIs with the client application"
1921
}
2022

@@ -47,6 +49,16 @@ while [[ $# -gt 0 ]]; do
4749
shift
4850
shift
4951
;;
52+
-v|--version)
53+
VERSION="$2"
54+
shift
55+
shift
56+
;;
57+
-i|--version-nfo)
58+
VERSION_INFO="$2"
59+
shift
60+
shift
61+
;;
5062
-nr|--no-redirect)
5163
NO_REDIRECT=true
5264
shift
@@ -97,6 +109,8 @@ echo "REACT_APP_BACKEND_URI=https://$WEB_API_URL/" > $ENV_FILE_PATH
97109
echo "REACT_APP_AAD_AUTHORITY=$AUTHORITY" >> $ENV_FILE_PATH
98110
echo "REACT_APP_AAD_CLIENT_ID=$APPLICATION_ID" >> $ENV_FILE_PATH
99111
echo "REACT_APP_SK_API_KEY=$WEB_API_KEY" >> $ENV_FILE_PATH
112+
echo "REACT_APP_SK_VERSION=$VERSION" >> $ENV_FILE_PATH
113+
echo "REACT_APP_SK_BUILD_INFO=$VERSION_INFO" >> $ENV_FILE_PATH
100114

101115
echo "Writing swa-cli.config.json..."
102116
SWA_CONFIG_FILE_PATH="$SCRIPT_ROOT/../../webapp/swa-cli.config.json"

‎scripts/deploy/package-webapi.ps1‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ param(
1818

1919
[string]
2020
# Output directory for published assets.
21-
$OutputDirectory = "$PSScriptRoot"
21+
$OutputDirectory = "$PSScriptRoot",
22+
23+
[string]
24+
# Version to give to assemblies and files.
25+
$Version = "1.0.0",
26+
27+
[string]
28+
# Additional information given in version info.
29+
$InformationalVersion = ""
2230
)
2331

2432
Write-Host "BuildConfiguration: $BuildConfiguration"
@@ -37,7 +45,7 @@ if (!(Test-Path $publishOutputDirectory)) {
3745
}
3846

3947
Write-Host "Build configuration: $BuildConfiguration"
40-
dotnet publish "$PSScriptRoot/../../webapi/CopilotChatWebApi.csproj" --configuration $BuildConfiguration --framework $DotNetFramework --runtime $TargetRuntime --self-contained --output "$publishOutputDirectory"
48+
dotnet publish "$PSScriptRoot/../../webapi/CopilotChatWebApi.csproj" --configuration $BuildConfiguration --framework $DotNetFramework --runtime $TargetRuntime --self-contained --output "$publishOutputDirectory" /p:AssemblyVersion=$Version /p:FileVersion=$Version /p:InformationalVersion=$InformationalVersion
4149
if ($LASTEXITCODE -ne 0) {
4250
exit $LASTEXITCODE
4351
}

‎scripts/deploy/package-webapi.sh‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ usage() {
1414
echo " -c, --configuration CONFIGURATION Build configuration (default: Release)"
1515
echo " -d, --dotnet DOTNET_FRAMEWORK_VERSION Target dotnet framework (default: net6.0)"
1616
echo " -r, --runtime TARGET_RUNTIME Runtime identifier (default: linux-x64)"
17-
echo " -p, --output OUTPUT_DIRECTORY Output directory (default: $SCRIPT_ROOT)"
17+
echo " -o, --output OUTPUT_DIRECTORY Output directory (default: $SCRIPT_ROOT)"
18+
echo " -v --version VERSION Version to set files to (default: 1.0.0)"
19+
echo " -i --info INFO Additional info to put in version details"
1820
echo " -nz, --no-zip Do not zip package (default: false)"
1921
}
2022

@@ -42,6 +44,16 @@ while [[ $# -gt 0 ]]; do
4244
shift
4345
shift
4446
;;
47+
-v|--version)
48+
VERSION="$2"
49+
shift
50+
shift
51+
;;
52+
-i|--info)
53+
INFO="$2"
54+
shift
55+
shift
56+
;;
4557
-nz|--no-zip)
4658
NO_ZIP=true
4759
shift
@@ -58,6 +70,8 @@ done
5870
: "${CONFIGURATION:="Release"}"
5971
: "${DOTNET:="net6.0"}"
6072
: "${RUNTIME:="linux-x64"}"
73+
: "${VERSION:="1.0.0"}"
74+
: "${INFO:=""}"
6175
: "${OUTPUT_DIRECTORY:="$SCRIPT_ROOT"}"
6276

6377
PUBLISH_OUTPUT_DIRECTORY="$OUTPUT_DIRECTORY/publish"
@@ -72,7 +86,7 @@ if [[ ! -d "$PUBLISH_ZIP_DIRECTORY" ]]; then
7286
fi
7387

7488
echo "Build configuration: $CONFIGURATION"
75-
dotnet publish "$SCRIPT_ROOT/../../webapi/CopilotChatWebApi.csproj" --configuration $CONFIGURATION --framework $DOTNET --runtime $RUNTIME --self-contained --output "$PUBLISH_OUTPUT_DIRECTORY"
89+
dotnet publish "$SCRIPT_ROOT/../../webapi/CopilotChatWebApi.csproj" --configuration $CONFIGURATION --framework $DOTNET --runtime $RUNTIME --self-contained --output "$PUBLISH_OUTPUT_DIRECTORY" /p:AssemblyVersion=$VERSION /p:FileVersion=$VERSION /p:InformationalVersion=$INFO
7690
if [ $? -ne 0 ]; then
7791
exit 1
7892
fi

‎webapi/Controllers/ServiceOptionsController.cs‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using System;
4+
using System.Diagnostics;
5+
using System.Reflection;
46
using CopilotChat.WebApi.Models.Response;
57
using CopilotChat.WebApi.Options;
68
using Microsoft.AspNetCore.Authorization;
@@ -39,15 +41,24 @@ public ServiceOptionsController(
3941
[ProducesResponseType(StatusCodes.Status200OK)]
4042
public IActionResult GetServiceOptions()
4143
{
42-
return this.Ok(
43-
new ServiceOptionsResponse()
44+
var response = new ServiceOptionsResponse()
45+
{
46+
MemoryStore = new MemoryStoreOptionResponse()
4447
{
45-
MemoryStore = new MemoryStoreOptionResponse()
46-
{
47-
Types = Enum.GetNames(typeof(MemoryStoreOptions.MemoryStoreType)),
48-
SelectedType = this._memoryStoreOptions.Type.ToString()
49-
}
50-
}
51-
);
48+
Types = Enum.GetNames(typeof(MemoryStoreOptions.MemoryStoreType)),
49+
SelectedType = this._memoryStoreOptions.Type.ToString()
50+
},
51+
Version = GetAssemblyFileVersion()
52+
};
53+
54+
return this.Ok(response);
55+
}
56+
57+
private static string GetAssemblyFileVersion()
58+
{
59+
Assembly assembly = Assembly.GetExecutingAssembly();
60+
FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
61+
62+
return fileVersion.FileVersion ?? string.Empty;
5263
}
5364
}

‎webapi/Models/Response/ServiceOptionsResponse.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public class ServiceOptionsResponse
1313
/// </summary>
1414
[JsonPropertyName("memoryStore")]
1515
public MemoryStoreOptionResponse MemoryStore { get; set; } = new MemoryStoreOptionResponse();
16+
17+
/// <summary>
18+
/// Version of this application.
19+
/// </summary>
20+
[JsonPropertyName("version")]
21+
public string Version { get; set; } = string.Empty;
1622
}
1723

1824
/// <summary>

0 commit comments

Comments
 (0)