Skip to content

Commit 1e800f4

Browse files
committed
- adds a script to auto-update the package version
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 42ed5a6 commit 1e800f4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

.github/workflows/build_test_validate.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
uses: actions/setup-node@v3
2323
with:
2424
node-version: ${{ matrix.node-version }}
25+
- run: .\scripts\updateVersion.ps1
26+
shell: pwsh
27+
working-directory: ./
2528
- run: yarn install --frozen-lockfile --ignore-engines #spfx still not compatible with node 18
2629
- run: yarn global add mocha@10.X
2730
- run: yarn run build

packages/http/fetch/src/middlewares/options/userAgentHandlerOptions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import { RequestOption } from "@microsoft/kiota-abstractions";
99

10+
import { libraryVersion } from "./version";
11+
1012
export const UserAgentHandlerOptionsKey = "UserAgentHandlerOptionKey";
1113

1214
export class UserAgentHandlerOptions implements RequestOption {
@@ -21,5 +23,5 @@ export class UserAgentHandlerOptions implements RequestOption {
2123
* @param {string} [productName = "kiota-typescript"] - The product name to be added to the user agent header
2224
* @param {string} [productVersion = "1.0.0-preview.12"] - The product version to be added to the user agent header
2325
*/
24-
public constructor(public enable: boolean = true, public productName: string = "kiota-typescript", public productVersion: string = "1.0.0-preview.12") {}
26+
public constructor(public enable: boolean = true, public productName: string = "kiota-typescript", public productVersion: string = libraryVersion) {}
2527
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const libraryVersion = "1.0.0-preview.12";

scripts/updateVersion.ps1

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.Synopsis
6+
Reads the version from the http package definition and updates the constant in the version file.
7+
.Description
8+
Reads the version from the http package definition and updates the constant in the version file.
9+
#>
10+
11+
$httpPackageRelativePath = "packages/http/fetch"
12+
$packageDefinitionPath = Join-Path $PWD -ChildPath $httpPackageRelativePath -AdditionalChildPath "/package.json"
13+
$versionFilePath = Join-Path $PWD -ChildPath $httpPackageRelativePath -AdditionalChildPath "src/middlewares/options/version.ts"
14+
15+
if (-not (Test-Path $packageDefinitionPath)) {
16+
Write-Error "Could not find package definition at path: $packageDefinitionPath"
17+
Exit 1
18+
}
19+
20+
if (-not (Test-Path $versionFilePath)) {
21+
Write-Error "Could not find version file at path: $versionFilePath"
22+
Exit 1
23+
}
24+
25+
$packageDefinition = Get-Content $packageDefinitionPath | ConvertFrom-Json
26+
$version = $packageDefinition.version
27+
Set-Content $versionFilePath -Value "export const libraryVersion = ""$version"";" -Verbose

0 commit comments

Comments
 (0)