Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-update CLI in the background when a new version is available #4789

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

amcaplan
Copy link
Contributor

@amcaplan amcaplan commented Nov 3, 2024

WHY are these changes introduced?

Fixes #0000

WHAT is this pull request doing?

How to test your changes?

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Nov 3, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.3% (-0.19% 🔻)
8395/11611
🟡 Branches
68.72% (-0.12% 🔻)
4088/5949
🟡 Functions
71.76% (-0.14% 🔻)
2201/3067
🟡 Lines
72.61% (-0.22% 🔻)
7939/10934
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app.ts
87.07%
71.6% (-0.68% 🔻)
92% 88.37%
🟢
... / extension-instance.ts
84.85% (-1.08% 🔻)
74.29% (-3.81% 🔻)
90.91% (-0.4% 🔻)
86.29% (-1.11% 🔻)
🟢
... / file-watcher.ts
80% (-2.19% 🔻)
74.19% (+2.76% 🔼)
76.92% (+0.45% 🔼)
82.14% (-2.71% 🔻)
🔴
... / dev-session.ts
3.8% (-0.75% 🔻)
0%
9.09% (-2.02% 🔻)
4.23% (-0.86% 🔻)
🟡
... / bundle.ts
75.81% (-4.84% 🔻)
64.52% (-9.68% 🔻)
66.67%
76.67% (-5% 🔻)
🔴
... / system.ts
31.58% (-1.75% 🔻)
20% (-1.43% 🔻)
62.5%
33.33% (-0.95% 🔻)
🟡
... / local.ts
61.54% (-1.21% 🔻)
48.98% (-1.02% 🔻)
47.83% (-2.17% 🔻)
61.54% (-1.21% 🔻)

Test suite run success

1931 tests passing in 874 suites.

Report generated by 🧪jest coverage report action from dc80aa3

@amcaplan
Copy link
Contributor Author

amcaplan commented Nov 4, 2024

/snapit

Copy link
Contributor

github-actions bot commented Nov 4, 2024

🫰✨ Thanks @amcaplan! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/[email protected]

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@amcaplan
Copy link
Contributor Author

amcaplan commented Nov 4, 2024

/snapit

Copy link
Contributor

github-actions bot commented Nov 4, 2024

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/private/node/constants.d.ts
@@ -30,6 +30,7 @@ export declare const environmentVariables: {
     refreshToken: string;
     otelURL: string;
     themeKitAccessDomain: string;
+    disableAutoUpdate: string;
 };
 export declare const defaultThemeKitAccessDomain = "theme-kit-access.shopifyapps.com";
 export declare const systemEnvironmentVariables: {
packages/cli-kit/dist/public/node/node-package-manager.d.ts
@@ -140,6 +140,17 @@ export declare function checkForNewVersion(dependency: string, currentVersion: s
  * @returns A more recent version or undefined if there's no more recent version.
  */
 export declare function checkForCachedNewVersion(dependency: string, currentVersion: string): string | undefined;
+/**
+ * Given a current version and a new version, it returns true if it's safe to auto-upgrade the dependency.
+ * It's considered safe if the major version is the same.
+ * @param currentVersion - The current version.
+ * @param newVersion - The new version.
+ * @returns Boolean Whether it's safe to auto-upgrade the dependency.
+ * @example
+ * safeToAutoUpgrade('1.2.3', '1.3.0') // true
+ * safeToAutoUpgrade('1.2.3', '2.0.0') // false
+ */
+export declare function safeToAutoUpgrade(currentVersion: string, newVersion: string): boolean;
 /**
  * Utility function used to check whether a package version satisfies some requirements
  * @param version - The version to check
packages/cli-kit/dist/public/node/system.d.ts
@@ -12,6 +12,8 @@ export interface ExecOptions {
     stdio?: 'inherit';
     input?: string;
     signal?: AbortSignal;
+    detached?: boolean;
+    unref?: boolean;
     externalErrorHandler?: (error: unknown) => Promise<void>;
 }
 /**
packages/cli-kit/dist/public/node/upgrade.d.ts
@@ -5,6 +5,13 @@
  * @returns A string with the command to run.
  */
 export declare function cliInstallCommand(): string;
+/**
+ * Utility function for generating an install command for the user to run
+ * to install an updated version of Shopify CLI. Returns as an array of strings.
+ *
+ * @returns A string array with the command to run.
+ */
+export declare function cliInstallCommandAsArray(): [string, ...string[]];
 /**
  * Generates a message to remind the user to update the CLI.
  *
packages/cli-kit/dist/public/node/context/local.d.ts
@@ -170,4 +170,12 @@ export declare function macAddress(): Promise<string>;
  * @returns The domain to send OTEL metrics to.
  */
 export declare function opentelemetryDomain(env?: NodeJS.ProcessEnv): string | undefined;
-export type CIMetadata = Metadata;
\ No newline at end of file
+export type CIMetadata = Metadata;
+/**
+ * Returns whether auto-updates are enabled.
+ * It can be overridden via the SHOPIFY_CLI_DISABLE_AUTO_UPDATES environment variable.
+ *
+ * @param env - The environment variables from the environment of the current process.
+ * @returns Whether auto-updates are enabled.
+ */
+export declare function autoUpdatesEnabled(env?: NodeJS.ProcessEnv): boolean;
\ No newline at end of file
packages/cli-kit/dist/public/node/hooks/prerun.d.ts
@@ -13,4 +13,5 @@ export declare function parseCommandContent(cmdInfo: {
 /**
  * Warns the user if there is a new version of the CLI available
  */
-export declare function warnOnAvailableUpgrade(): Promise<void>;
\ No newline at end of file
+export declare function warnOnAvailableUpgrade(): Promise<void>;
+export declare function autoUpdateCli(currentVersion: string, newerVersion: string): Promise<void>;
\ No newline at end of file

Copy link
Contributor

github-actions bot commented Nov 4, 2024

🫰✨ Thanks @amcaplan! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/[email protected]

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant