Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
feat: check extensions version and add comment if not latest
Browse files Browse the repository at this point in the history
  • Loading branch information
daphne-sfdc committed May 17, 2024
1 parent 859a80d commit f546a7e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
7 changes: 3 additions & 4 deletions .github/actions/validate-issue/messages/old-cli.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Hello @THE_AUTHOR :wave: None of the versions of `USER_CLI` you shared match the latest release.
Hello @THE_AUTHOR :wave: None of the versions of the Salesforce Extension Pack you shared match the latest release.

Shared: `USER_VERSION`
Latest: `LATEST_VERSION`

Update to the latest version of Salesforce CLI ([docs](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_update_cli.htm)) and confirm that you're still seeing your issue.
You can also try the `rc` and `nightly` releases! ([docs](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli_rc.htm))
Update to the latest version of the Salesforce Extension Pack in the VSCode Extensions view and confirm that you're still seeing your issue.

After updating, share the full output of `USER_CLI version --verbose --json`
After updating, share your current extensions version.
Empty file.
58 changes: 47 additions & 11 deletions .github/actions/validate-issue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,54 @@ async function run() {
...authorComments.map((comment) => comment.body),
].filter((body): body is string => body !== undefined);

let valid = true;

// Checking Salesforce Extension Pack version
const extensionVersionRegex = /Salesforce Extension Version in VS Code:\s*\d{2}\.\d{1,2}\.\d$/g;
const extensionsVersionRegex = /Salesforce Extension Version in VS Code:\s*\d{2}\.\d{1,2}\.\d$/g;

// Search all bodies and get an array of all versions found (first capture group)
const extensionVersions = bodies
const extensionsVersions = bodies
.map((body) =>
[...body.matchAll(extensionVersionRegex)].map((match) => match[1])
[...body.matchAll(extensionsVersionRegex)].map((match) => match[1])
)
.flat();

console.log('extensionVersions', extensionVersions);
console.log('extensionsVersions', extensionsVersions);

if (extensionsVersions.length > 0) {
const extensionsLatest = getLatestExtensionsVersion();

const oneSatisfies = extensionsVersions.some((version) =>
semver.gte(version, extensionsLatest)
);

if (!oneSatisfies) {
const oldExtensions = getFile("../../messages/old-extensions.md", {
THE_AUTHOR: author,
USER_VERSION: extensionsVersions.join("`, `"),
LATEST_VERSION: extensionsLatest
});
postComment(oldExtensions);
}
valid = false;

if (extensionVersions.length > 0) {
// TODO: Check if the version the user supplied is the latest version
// Get the extension pack versions from `vsce show salesforce.salesforcedx-vscode --json`
// How do I choose the latest version from the array of versions?
if (valid) {
console.log("All information provided is valid!");
removeLabel("more information required");
// This label will prevent the action from running again after version info has been confirmed
// Otherwise, this action will continue to trigger after every weekly release as `latest` is bumped
addLabel("validated");
} else {
console.log("Information provided is NOT valid");
addLabel("more information required");
}
} else {
console.log("Full version information was not provided");
const message = getFile("../../messages/provide-version.md", {
THE_AUTHOR: issue.user.login,
});
postComment(message);
addLabel("more information required");
}

// Checking VSCode version
Expand Down Expand Up @@ -143,10 +175,9 @@ async function run() {
// FUTURE TODO:
// - Check for bundled plugins that are user installed (user) or linked (link)
// - Could do a check to see if the users has a prerelease version installed
let valid = true;

if (sfVersions.length > 0) {
const sfLatest = getLatestVersion("@salesforce/cli");
const sfLatest = getLatestCliVersion("@salesforce/cli");
const oneSatisfies = sfVersions.some((version) =>
semver.gte(version, sfLatest)
);
Expand Down Expand Up @@ -283,13 +314,18 @@ async function run() {
}
}

function getLatestVersion(plugin: string) {
function getLatestCliVersion(plugin: string) {
const distTags = execSync(
`npm view ${plugin} dist-tags --json`
).toString();
return JSON.parse(distTags).latest;
}

function getLatestExtensionsVersion() {
const result = execSync(`vsce show salesforce.salesforcedx-vscode --json`).toString();
return JSON.parse(result).versions[0].version;
}

function getFile(
filename: string,
replacements: { [key: string]: string } | undefined
Expand Down

0 comments on commit f546a7e

Please sign in to comment.