Skip to content

Commit ddb68b3

Browse files
authored
Merge pull request #545 from jpogran/GH-541-check-pdk-latest
(GH-541) Check for latest PDK Version
2 parents 17f3662 + 7c040c3 commit ddb68b3

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed

package-lock.json

Lines changed: 35 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@
433433
"none"
434434
]
435435
},
436+
"puppet.pdk.checkVersion": {
437+
"type": "boolean",
438+
"default": true,
439+
"description": "Enable/disable checking if installed PDK version is latest"
440+
},
436441
"puppet.titleBar.pdkNewModule.enable": {
437442
"type": "boolean",
438443
"default": true,
@@ -562,6 +567,7 @@
562567
"vscode-debugadapter": "^1.19.0",
563568
"vscode-debugprotocol": "^1.19.0",
564569
"vscode-extension-telemetry": "0.1.1",
565-
"vscode-languageclient": "^5.2.1"
570+
"vscode-languageclient": "^5.2.1",
571+
"axios": "0.19.0"
566572
}
567573
}

src/configuration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface IRubyConfiguration {
3535
readonly pdkRubyBinDir:string;
3636
readonly pdkGemVerDir:string;
3737
readonly pdkPuppetVersions: string[];
38+
readonly pdkVersion:string;
3839
}
3940

4041
/** The IConnectionConfiguration interface describes the connection used to
@@ -117,6 +118,7 @@ export class AggregateConfiguration implements IAggregateConfiguration {
117118
pdkRubyBinDir: pdkInstance.rubyBinDir,
118119
pdkGemVerDir: pdkInstance.gemVerDir,
119120
pdkPuppetVersions: puppetVersions,
121+
pdkVersion: this.getPdkVersionFromFile(puppetBaseDir),
120122
};
121123

122124
this.connection = {
@@ -227,6 +229,16 @@ export class AggregateConfiguration implements IAggregateConfiguration {
227229
}
228230
}
229231

232+
private getPdkVersionFromFile(puppetBaseDir:string){
233+
let basePath = path.join(puppetBaseDir, 'PDK_VERSION');
234+
if(fs.existsSync(basePath)){
235+
let contents = fs.readFileSync(basePath, 'utf8').toString();
236+
return contents.trim();
237+
}else{
238+
return '';
239+
}
240+
}
241+
230242
private findFirstDirectory(rootDir: string): string {
231243
if (!fs.existsSync(rootDir)) { return undefined; }
232244
var files = fs.readdirSync(rootDir);

src/extension.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import { ConnectionHandler } from './handler';
1616
import { DockerConnectionHandler } from './handlers/docker';
1717
import { StdioConnectionHandler } from './handlers/stdio';
1818
import { TcpConnectionHandler } from './handlers/tcp';
19-
import { ConnectionType, ProtocolType, PuppetInstallType } from './settings';
19+
import { ConnectionType, ProtocolType, PuppetInstallType, ISettings } from './settings';
2020
import { ILogger } from './logging';
2121
import { OutputChannelLogger } from './logging/outputchannel';
2222
import { legacySettings, SettingsFromWorkspace } from './settings';
2323
import { Reporter, reporter } from './telemetry/telemetry';
2424

25+
const axios = require('axios');
26+
2527
export const puppetLangID = 'puppet'; // don't change this
2628
export const puppetFileLangID = 'puppetfile'; // don't change this
2729
const debugType = 'Puppet'; // don't change this
@@ -36,6 +38,7 @@ export function activate(context: vscode.ExtensionContext) {
3638
extContext = context;
3739

3840
notifyOnNewExtensionVersion(extContext);
41+
3942
checkForLegacySettings();
4043

4144
context.subscriptions.push(new Reporter(extContext));
@@ -76,6 +79,12 @@ export function activate(context: vscode.ExtensionContext) {
7679
// This can be revisited to enable disabling language server portion
7780
return;
7881
}
82+
83+
// this happens after checkInstallDirectory so that we don't check pdk version
84+
// if it's not installed
85+
if(settings.pdk.checkVersion){
86+
notifyIfNewPDKVersion(extContext, configSettings);
87+
}
7988

8089
switch (configSettings.workspace.editorService.protocol) {
8190
case ProtocolType.STDIO:
@@ -232,3 +241,57 @@ async function notifyEditorServiceDisabled(context: vscode.ExtensionContext) {
232241
context.globalState.update(suppressEditorServicesDisabled, true);
233242
}
234243
}
244+
245+
async function notifyIfNewPDKVersion(context: vscode.ExtensionContext, settings:IAggregateConfiguration) {
246+
const suppressPDKUpdateCheck = 'suppressPDKUpdateCheck';
247+
const dontCheckAgainNotice = "Don't check again";
248+
const viewPDKDownloadPage = "More info";
249+
250+
if (context.globalState.get(suppressPDKUpdateCheck, false)) {
251+
return;
252+
}
253+
254+
let version = '';
255+
if(settings.ruby.pdkVersion){
256+
version = settings.ruby.pdkVersion;
257+
}else{
258+
// should we throw a warning here? technically this is only reached *if* a
259+
// PDK install is found, so the only way this is null is if the PDK_VERSION
260+
// file was removed.
261+
return;
262+
}
263+
264+
axios.get('https://s3.amazonaws.com/puppet-pdk/pdk/LATEST')
265+
.then(response => {
266+
return response.data;
267+
})
268+
.then(latest_version => {
269+
if(version !== latest_version){
270+
return vscode.window.showWarningMessage(
271+
`The installed PDK version is ${version}, the newest version is ${latest_version}. To find out how to update to the latest version click the more info button`,
272+
{ modal: false },
273+
{ title: dontCheckAgainNotice },
274+
{ title: viewPDKDownloadPage }
275+
);
276+
}
277+
})
278+
.then(result=>{
279+
if (result === undefined) {
280+
return;
281+
}
282+
283+
if (result.title === dontCheckAgainNotice) {
284+
context.globalState.update(suppressPDKUpdateCheck, true);
285+
}
286+
287+
if (result.title === viewPDKDownloadPage) {
288+
vscode.commands.executeCommand(
289+
'vscode.open',
290+
vscode.Uri.parse('https://puppet.com/download-puppet-development-kit')
291+
);
292+
}
293+
})
294+
.catch(error => {
295+
logger.error(error);
296+
});
297+
}

src/settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface ILintSettings {
6060
}
6161

6262
export interface IPDKSettings {
63-
// Future Use
63+
checkVersion?: boolean;
6464
}
6565

6666
export interface INotificationSettings {
@@ -173,6 +173,7 @@ export function DefaultWorkspaceSettings(): ISettings {
173173
puppetResource: "messagebox"
174174
},
175175
pdk: {
176+
checkVersion: true,
176177
}
177178
};
178179
}

0 commit comments

Comments
 (0)