Skip to content

Commit 8801680

Browse files
committed
Use GitCommitId to avoid pointless update checks
And remove an unused `IRunspaceDetails` interface.
1 parent caf7fd3 commit 8801680

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

.vsts-ci/templates/ci-general.yml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ steps:
7070
inputs:
7171
targetType: inline
7272
script: |
73+
Get-ChildItem env:
7374
Get-Module -ListAvailable Pester
7475
Install-Module InvokeBuild -Scope CurrentUser -Force
7576
Install-Module platyPS -Scope CurrentUser -Force

src/features/UpdatePowerShell.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class UpdatePowerShell {
5353
private sessionSettings: Settings,
5454
private logger: ILogger,
5555
versionDetails: IPowerShellVersionDetails) {
56-
this.localVersion = new SemVer(versionDetails.version);
56+
// We use the commit field as it's like
57+
// '7.3.0-preview.3-508-g07175ae0ff8eb7306fe0b0fc7d...' which translates
58+
// to SemVer. The version handler in PSES handles Windows PowerShell and
59+
// just returns the first three fields like '5.1.22621'.
60+
this.localVersion = new SemVer(versionDetails.commit);
5761
this.architecture = versionDetails.architecture.toLowerCase();
5862
}
5963

@@ -77,8 +81,27 @@ export class UpdatePowerShell {
7781
return false;
7882
}
7983

80-
// TODO: Check if PowerShell is self-built, i.e. PSVersionInfo.GitCommitId.Length > 40.
81-
// TODO: Check if preview is a daily build.
84+
if (this.localVersion.prerelease.length > 1) {
85+
// Daily builds look like '7.3.0-daily20221206.1' which split to
86+
// ['daily20221206', '1'] and development builds look like
87+
// '7.3.0-preview.3-508-g07175...' which splits to ['preview',
88+
// '3-508-g0717...']. The ellipsis is hiding a 40 char hash.
89+
const daily = this.localVersion.prerelease[0].toString();
90+
const commit = this.localVersion.prerelease[1].toString();
91+
92+
// Skip if PowerShell is self-built, that is, this contains a commit hash.
93+
if (commit.length >= 40) {
94+
this.logger.writeDiagnostic("Not offering to update development build.");
95+
return false;
96+
}
97+
98+
// Skip if preview is a daily build.
99+
if (daily.toLowerCase().startsWith("daily")) {
100+
this.logger.writeDiagnostic("Not offering to update daily build.");
101+
return false;
102+
}
103+
}
104+
82105
// TODO: Check if network is available?
83106
// TODO: Only check once a week.
84107
this.logger.writeDiagnostic("Should check for PowerShell update.");

src/session.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
OperatingSystem, PowerShellExeFinder
2525
} from "./platform";
2626
import { LanguageClientConsumer } from "./languageClientConsumer";
27+
import { SemVer } from "semver";
2728

2829
export enum SessionStatus {
2930
NeverStarted,
@@ -54,17 +55,11 @@ export interface IEditorServicesSessionDetails {
5455

5556
export interface IPowerShellVersionDetails {
5657
version: string;
57-
displayVersion: string;
5858
edition: string;
59+
commit: string;
5960
architecture: string;
6061
}
6162

62-
export interface IRunspaceDetails {
63-
powerShellVersion: IPowerShellVersionDetails;
64-
runspaceType: RunspaceType;
65-
connectionString: string;
66-
}
67-
6863
export type IReadSessionFileCallback = (details: IEditorServicesSessionDetails) => void;
6964

7065
export const SendKeyPressNotificationType =
@@ -734,12 +729,9 @@ Type 'help' to get help.
734729
this.languageStatusItem.detail = "PowerShell";
735730

736731
if (this.versionDetails !== undefined) {
737-
const version = this.versionDetails.architecture.toLowerCase() !== "x64"
738-
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture.toLowerCase()})`
739-
: this.versionDetails.displayVersion;
740-
741-
this.languageStatusItem.text = "$(terminal-powershell) " + version;
742-
this.languageStatusItem.detail += " " + version;
732+
const semver = new SemVer(this.versionDetails.version);
733+
this.languageStatusItem.text = `$(terminal-powershell) ${semver.major}.${semver.minor}`;
734+
this.languageStatusItem.detail += ` ${this.versionDetails.commit} (${this.versionDetails.architecture.toLowerCase()})`;
743735
}
744736

745737
if (statusText) {
@@ -835,7 +827,7 @@ Type 'help' to get help.
835827
const powerShellSessionName =
836828
currentPowerShellExe ?
837829
currentPowerShellExe.displayName :
838-
`PowerShell ${this.versionDetails.displayVersion} ` +
830+
`PowerShell ${this.versionDetails.version} ` +
839831
`(${this.versionDetails.architecture.toLowerCase()}) ${this.versionDetails.edition} Edition ` +
840832
`[${this.versionDetails.version}]`;
841833

test/features/UpdatePowerShell.test.ts

+33-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe("UpdatePowerShell feature", function () {
2929
settings.promptToUpdatePowerShell = false;
3030
const version: IPowerShellVersionDetails = {
3131
"version": "7.3.0",
32-
"displayVersion": "7.3",
3332
"edition": "Core",
33+
"commit": "7.3.0",
3434
"architecture": "X64"
3535
};
3636
// @ts-expect-error testing doesn't require all arguments.
@@ -41,10 +41,9 @@ describe("UpdatePowerShell feature", function () {
4141

4242
it("Won't check for Windows PowerShell", function () {
4343
const version: IPowerShellVersionDetails = {
44-
// TODO: This should handle e.g. 5.1.22621.436
45-
"version": "5.1.0",
46-
"displayVersion": "5.1",
44+
"version": "5.1.22621",
4745
"edition": "Desktop",
46+
"commit": "5.1.22621",
4847
"architecture": "X64"
4948
};
5049
// @ts-expect-error testing doesn't require all arguments.
@@ -53,12 +52,38 @@ describe("UpdatePowerShell feature", function () {
5352
assert(!updater.shouldCheckForUpdate());
5453
});
5554

55+
it("Won't check for a development build of PowerShell", function () {
56+
const version: IPowerShellVersionDetails = {
57+
"version": "7.3.0-preview.3",
58+
"edition": "Core",
59+
"commit": "7.3.0-preview.3-508-g07175ae0ff8eb7306fe0b0fc7d19bdef4fbf2d67",
60+
"architecture": "Arm64"
61+
};
62+
// @ts-expect-error testing doesn't require all arguments.
63+
const updater = new UpdatePowerShell(undefined, settings, testLogger, version);
64+
// @ts-expect-error method is private.
65+
assert(!updater.shouldCheckForUpdate());
66+
});
67+
68+
it("Won't check for a daily build of PowerShell", function () {
69+
const version: IPowerShellVersionDetails = {
70+
"version": "7.3.0-daily20221206.1",
71+
"edition": "Core",
72+
"commit": "7.3.0-daily20221206.1",
73+
"architecture": "Arm64"
74+
};
75+
// @ts-expect-error testing doesn't require all arguments.
76+
const updater = new UpdatePowerShell(undefined, settings, testLogger, version);
77+
// @ts-expect-error method is private.
78+
assert(!updater.shouldCheckForUpdate());
79+
});
80+
5681
it("Won't check if POWERSHELL_UPDATECHECK is 'Off'", function () {
5782
process.env.POWERSHELL_UPDATECHECK = "Off";
5883
const version: IPowerShellVersionDetails = {
5984
"version": "7.3.0",
60-
"displayVersion": "7.3",
6185
"edition": "Core",
86+
"commit": "7.3.0",
6287
"architecture": "X64"
6388
};
6489
// @ts-expect-error testing doesn't require all arguments.
@@ -70,8 +95,8 @@ describe("UpdatePowerShell feature", function () {
7095
it ("Should otherwise check to update PowerShell", function () {
7196
const version: IPowerShellVersionDetails = {
7297
"version": "7.3.0",
73-
"displayVersion": "7.3",
7498
"edition": "Core",
99+
"commit": "7.3.0",
75100
"architecture": "X64"
76101
};
77102
// @ts-expect-error testing doesn't require all arguments.
@@ -86,8 +111,8 @@ describe("UpdatePowerShell feature", function () {
86111
process.env.POWERSHELL_UPDATECHECK = "LTS";
87112
const version: IPowerShellVersionDetails = {
88113
"version": "7.0.0",
89-
"displayVersion": "7.0",
90114
"edition": "Core",
115+
"commit": "7.0.0",
91116
"architecture": "X64"
92117
};
93118
// @ts-expect-error testing doesn't require all arguments.
@@ -101,8 +126,8 @@ describe("UpdatePowerShell feature", function () {
101126
it("Would update to stable", async function() {
102127
const version: IPowerShellVersionDetails = {
103128
"version": "7.0.0",
104-
"displayVersion": "7.0",
105129
"edition": "Core",
130+
"commit": "7.0.0",
106131
"architecture": "X64"
107132
};
108133
// @ts-expect-error testing doesn't require all arguments.

0 commit comments

Comments
 (0)