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

feature/sc-126217/implement-update-cli-command-in-js #729

Conversation

hugomontero
Copy link
Contributor

@hugomontero hugomontero commented Apr 18, 2024

Description

This PR will implement update-cli by using the new manifest and build structure.

How to Test

  1. Pull down the branch: git pull && git checkout feature/sc-126217/implement-update-cli-command-in-js
  2. Install dependencies: npm i
  3. Run update-cli command:
    • npm start -- update-cli
  4. Download the executable from CircleCI Artifacts
  5. Run these commands:
    • ./particle -- update-cli
    • ./particle -- update-cli --version 1.2.3
    • ./particle -- update-cli --version 3.23.0

Outcome

  • When Running cli with node you will see a message indicating to try npm i -g particle-cli in order to update it
  • When using the build from the link:
    • The cli will be updated with the latest uploaded version (check ~/.particle/profile.json)
    • Picking a non-existent version it will throw you an error indicating that the selected version doesn't exist
    • Picking an specific version will disable auto-update feature

Related Issues / Discussions

Story details: https://app.shortcut.com/particle/story/126217

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA
  • Problem and solution clearly stated
  • Tests have been provided
  • Docs have been updated
  • CI is passing

@hugomontero hugomontero marked this pull request as ready for review April 18, 2024 20:23
@hugomontero hugomontero changed the title Feature/sc 126217/implement update cli command in js feature/sc-126217/implement-update-cli-command-in-js Apr 18, 2024
Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good generally. Additional tweaks may be necessary before final release but you can merge this

if (skip) {
return;
}

const now = Date.now();
const lastCheck = settings.profile_json.last_version_check || 0;
const skipUpdates = !settings.profile_json.enableUpdates || settings.disableUpdateCheck;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone doesn't set enableUpdates it will skip updates. I think that's ok if we assume most people will install through the installer. npm install wouldn't set enableUpdates to true so that's fine. You may need to add a call to particle update-cli --enable-updates when installing from Workbench.

How about going back to the PRD and putting a little table of which installation methods enable updates, which ones don't and which ones have an option to enable/disable updates.

return;
}
return;
execa('particle', ['update-cli']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need some additional options for execa. Specifically, look at cleanup and detached to avoid the background process being killed when the current process exits.
https://www.npmjs.com/package/execa#cleanup
https://www.npmjs.com/package/execa#detached

}
if (!dirPath.includes('snapshot')) {
log.info(`Update the CLI by running ${chalk.bold('npm install -g particle-cli')}`);
log.info('To stay up to date with the latest features and improvements, please install the latest Particle Installer executable from our website: https://www.particle.io/cli');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good message!

log.info('Automatic update checks are now disabled');
return this.disableUpdates();
}
if (!dirPath.includes('snapshot')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try process.pkg to detect whether it's running under pkg?

const log = require('../lib/log');
const chalk = require('chalk');
const settings = require('../../settings');
const MANIFEST_HOST = process.env.PARTICLE_MANIFEST_HOST || 'binaries.particle.io';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would seem better in settings.js

resolve(filePath);
})
.on('error', (error) => {
log.error(`Error downloading CLI: ${error}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test what the error looks like when offline or version doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will show a 404 or econnrefused so I'll change it like I did in the manifest => put a log.debug for the actual error and return a more helpful error to the user.

@hugomontero hugomontero merged commit abbe4b0 into feature/cli-installer-v2 Apr 22, 2024
1 check passed
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.

None yet

2 participants